NIU:
[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 = {}
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 local macaddr = cursor:get("wireless", device, "macaddr") or "!"
62 local hwmode = cursor:get("wireless", device, "hwmode")
63 local modes = {}
64 local phy
65 local allowed = {}
66 for entry in fs.glob("/sys/class/ieee80211/*") do
67 if (fs.readfile(entry .. "/macaddress") or ""):find(macaddr) == 1 then
68 phy = entry:sub(22)
69 end
70 end
71 if phy then
72 local iwp = io.popen("iw phy " .. phy .. " info")
73 local iwin = iwp:read("*a")
74
75 if iwp then
76 iwp:close()
77 local htcap = iwin:match("HT capabilities:%s*0x([0-9a-fA-F]+)")
78 allowed.n = (htcap and tonumber(htcap, 16) or 0) > 0
79 allowed.g = iwin:find("2412 MHz")
80 allowed.a = iwin:find("5180 MHz")
81 end
82 end
83
84 if next(allowed) then
85 mode = s:taboption("expert", ListValue, "hwmode", translate("Communication Protocol"))
86 if allowed.n and allowed.g then
87 mode:value("11ng", "802.11n (2.4 GHz)")
88 end
89 if allowed.n and allowed.a then
90 mode:value("11na", "802.11n (5 GHz)")
91 end
92 if allowed.a then
93 mode:value("11a", "802.11a (5 GHz)")
94 end
95 if allowed.g then
96 mode:value("11g", "802.11g (2.4 GHz)")
97 mode:value("11bg", "802.11b+g (2.4 GHz)")
98 mode:value("11b", "802.11b (2.4 GHz)")
99 end
100 end
101
102 tp = s:taboption("expert",
103 (tx_powers and #tx_powers > 0) and ListValue or Value,
104 "txpower", translate("Transmission Power"), "dBm")
105
106 tp.rmempty = true
107 tp:value("", translate("automatic"))
108 for _, p in ipairs(iw and iw.txpwrlist or {}) do
109 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
110 end
111 elseif hwtype == "atheros" then
112 tp = s:taboption("expert",
113 (#tx_powers > 0) and ListValue or Value,
114 "txpower", translate("Transmission Power"), "dBm")
115
116 tp.rmempty = true
117 tp:value("", translate("automatic"))
118 for _, p in ipairs(iw.txpwrlist) do
119 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
120 end
121
122 mode = s:taboption("expert", ListValue, "hwmode", translate("Communication Protocol"))
123 mode:value("", translate("automatic"))
124 mode:value("11g", "802.11g")
125 mode:value("11b", "802.11b")
126 mode:value("11bg", "802.11b+g")
127 mode:value("11a", "802.11a")
128 mode:value("11gst", "802.11g + Turbo")
129 mode:value("11ast", "802.11a + Turbo")
130
131 if nsantenna then -- NanoFoo
132 local ant = s:taboption("expert", ListValue, "antenna", translate("Transmitter Antenna"))
133 ant:value("auto")
134 ant:value("vertical")
135 ant:value("horizontal")
136 ant:value("external")
137 ant.default = "auto"
138 end
139 elseif hwtype == "broadcom" then
140 tp = s:taboption("expert",
141 (#tx_powers > 0) and ListValue or Value,
142 "txpower", translate("Transmit Power"), "dBm")
143
144 tp.rmempty = true
145 tp:value("", translate("automatic"))
146 for _, p in ipairs(iw.txpwrlist) do
147 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
148 end
149
150 mp = s:taboption("expert", ListValue, "macfilter", translate("MAC-Address Filter"))
151 mp:value("", translate("disable"))
152 mp:value("allow", translate("Allow listed only"))
153 mp:value("deny", translate("Allow all except listed"))
154 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
155 ml:depends({macfilter="allow"})
156 ml:depends({macfilter="deny"})
157
158 s:taboption("expert", Flag, "frameburst", translate("Allow Burst Transmissions"))
159 elseif hwtype == "prism2" then
160 s:taboption("expert", Value, "txpower", translate("Transmission Power"), "att units").rmempty = true
161 end
162
163
164
165
166 s = m:section(NamedSection, "ap", "wifi-iface", "Access Point Details")
167 s.addremove = false
168
169 s:tab("general", translate("General Settings"))
170 s:tab("expert", translate("Expert Settings"))
171
172 s:taboption("general", Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
173
174 mode = s:taboption("expert", ListValue, "mode", translate("Operating Mode"))
175 mode.override_values = true
176 mode:value("ap", translate("Access Point"))
177
178 encr = s:taboption("expert", ListValue, "encryption", translate("Encryption"))
179
180
181 if hwtype == "mac80211" then
182 s:taboption("expert", Flag, "wds", "Allow Bridging and Repeating (WDS)")
183 s:taboption("expert", Flag, "powersave", "Enable Powersaving")
184 elseif hwtype == "atheros" then
185 -- mode:value("wds", translate("Static WDS"))
186
187 mp = s:taboption("expert", ListValue, "macpolicy", translate("MAC-Address Filter"))
188 mp:value("", translate("disable"))
189 mp:value("deny", translate("Allow listed only"))
190 mp:value("allow", translate("Allow all except listed"))
191 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
192 ml:depends({macpolicy="allow"})
193 ml:depends({macpolicy="deny"})
194
195 s:taboption("expert", Flag, "wds", "Allow Bridging and Repeating (WDS)")
196
197 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
198 hidden:depends({mode="ap"})
199 hidden:depends({mode="ap-wds"})
200
201 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
202 isolate:depends({mode="ap"})
203
204 s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
205 elseif hwtype == "broadcom" then
206 mode:value("wds", translate("WDS"))
207
208 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
209 hidden:depends({mode="ap"})
210 hidden:depends({mode="wds"})
211
212 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
213 isolate:depends({mode="ap"})
214 elseif hwtype == "prism2" then
215 mode:value("wds", translate("WDS"))
216
217 mp = s:taboption("expert", ListValue, "macpolicy", translate("MAC-Address Filter"))
218 mp:value("", translate("disable"))
219 mp:value("deny", translate("Allow listed only"))
220 mp:value("allow", translate("Allow all except listed"))
221
222 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
223 ml:depends({macpolicy="allow"})
224 ml:depends({macpolicy="deny"})
225
226 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
227 hidden:depends({mode="ap"})
228 hidden:depends({mode="wds"})
229 end
230
231 -- Encryption --
232
233 encr.default = "wep" -- Early default
234 encr.override_values = true
235 encr.override_depends = true
236 encr:value("none", "No Encryption")
237 encr:value("wep", "WEP", {mode="ap"})
238
239 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
240 local hostapd = fs.access("/usr/sbin/hostapd") or os.getenv("LUCI_SYSROOT")
241
242 if hostapd then
243 --s:taboption("expert", Flag, "_alloweap", "Allow EAP / 802.11i authentication")
244
245 encr:value("psk", "WPA", {mode="ap"})
246 encr:value("wpa", "WPA-EAP", {mode="ap"})
247 encr:value("psk-mixed", "WPA + WPA2", {mode="ap"})
248 encr:value("psk2", "WPA2", {mode="ap"})
249 encr:value("wpa2", "WPA2-EAP (802.11i)", {mode="ap"})
250 encr.default = "psk-mixed"
251 end
252 elseif hwtype == "broadcom" then
253 encr:value("psk", "WPA")
254 encr:value("psk+psk2", "WPA + WPA2")
255 encr:value("psk2", "WPA2")
256 encr.default = "psk+psk2"
257 end
258
259 server = s:taboption("general", Value, "server", translate("Radius-Server"))
260 server:depends({mode="ap", encryption="wpa"})
261 server:depends({mode="ap", encryption="wpa2"})
262 server.rmempty = true
263
264 port = s:taboption("general", Value, "port", translate("Radius-Port"))
265 port:depends({mode="ap", encryption="wpa"})
266 port:depends({mode="ap", encryption="wpa2"})
267 port.rmempty = true
268
269 key = s:taboption("general", Value, "key", translate("Password"))
270 key:depends("encryption", "wep")
271 key:depends("encryption", "psk")
272 key:depends("encryption", "psk2")
273 key:depends("encryption", "psk+psk2")
274 key:depends("encryption", "psk-mixed")
275 key:depends({mode="ap", encryption="wpa"})
276 key:depends({mode="ap", encryption="wpa2"})
277 key.rmempty = true
278 key.password = true
279
280 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
281 nasid = s:taboption("general", Value, "nasid", translate("NAS ID"))
282 nasid:depends({mode="ap", encryption="wpa"})
283 nasid:depends({mode="ap", encryption="wpa2"})
284 nasid.rmempty = true
285 end
286 return m