2 LuCI - Lua Configuration Interface
4 Copyright 2009 Steven Barth <steven@midlink.org>
5 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
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
11 http://www.apache.org/licenses/LICENSE-2.0
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")
22 local device = cursor:get("wireless", "ap", "device")
23 local hwtype = cursor:get("wireless", device, "type")
25 local nsantenna = cursor:get("wireless", device, "antenna")
29 local chan = sys.wifi.channels()
31 state:foreach("wireless", "wifi-iface",
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 { }
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.")
45 --- Device Settings ---
46 s = m:section(NamedSection, device, "wifi-device", "Device Configuration")
49 s:tab("general", translate("General Settings"))
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 })
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")
66 for entry in fs.glob("/sys/class/ieee80211/*") do
67 if (fs.readfile(entry .. "/macaddress") or ""):find(macaddr) == 1 then
72 local iwp = io.popen("iw phy " .. phy .. " info")
73 local iwin = iwp:read("*a")
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")
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)")
89 if allowed.n and allowed.a then
90 mode:value("11na", "802.11n (5 GHz)")
93 mode:value("11a", "802.11a (5 GHz)")
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)")
102 tp = s:taboption("expert",
103 (tx_powers and #tx_powers > 0) and ListValue or Value,
104 "txpower", translate("Transmission Power"), "dBm")
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 })
111 elseif hwtype == "atheros" then
112 tp = s:taboption("expert",
113 (#tx_powers > 0) and ListValue or Value,
114 "txpower", translate("Transmission Power"), "dBm")
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 })
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")
131 if nsantenna then -- NanoFoo
132 local ant = s:taboption("expert", ListValue, "antenna", translate("Transmitter Antenna"))
134 ant:value("vertical")
135 ant:value("horizontal")
136 ant:value("external")
139 elseif hwtype == "broadcom" then
140 tp = s:taboption("expert",
141 (#tx_powers > 0) and ListValue or Value,
142 "txpower", translate("Transmit Power"), "dBm")
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 })
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"})
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
166 s = m:section(NamedSection, "ap", "wifi-iface", "Access Point Details")
169 s:tab("general", translate("General Settings"))
170 s:tab("expert", translate("Expert Settings"))
172 s:taboption("general", Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
174 mode = s:taboption("expert", ListValue, "mode", translate("Operating Mode"))
175 mode.override_values = true
176 mode:value("ap", translate("Access Point"))
178 encr = s:taboption("expert", ListValue, "encryption", translate("Encryption"))
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"))
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"})
195 s:taboption("expert", Flag, "wds", "Allow Bridging and Repeating (WDS)")
197 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
198 hidden:depends({mode="ap"})
199 hidden:depends({mode="ap-wds"})
201 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
202 isolate:depends({mode="ap"})
204 s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
205 elseif hwtype == "broadcom" then
206 mode:value("wds", translate("WDS"))
208 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
209 hidden:depends({mode="ap"})
210 hidden:depends({mode="wds"})
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"))
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"))
222 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
223 ml:depends({macpolicy="allow"})
224 ml:depends({macpolicy="deny"})
226 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
227 hidden:depends({mode="ap"})
228 hidden:depends({mode="wds"})
234 encr.override_values = true
235 encr.override_depends = true
236 encr:value("none", "No Encryption")
237 encr:value("wep", "WEP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"})
239 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
240 local hostapd = fs.access("/usr/sbin/hostapd") or os.getenv("LUCI_SYSROOT")
243 --s:taboption("expert", Flag, "_alloweap", "Allow EAP / 802.11i authentication")
245 encr:value("psk", "WPA", {mode="ap"}, {mode="ap-wds"})
246 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
247 encr:value("psk-mixed", "WPA + WPA2", {mode="ap"}, {mode="ap-wds"})
248 encr:value("psk2", "WPA2", {mode="ap"}, {mode="ap-wds"})
249 encr:value("wpa2", "WPA2-EAP (802.11i)", {mode="ap"}, {mode="ap-wds"})
250 encr.default = "psk-mixed"
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"
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
264 port = s:taboption("general", Value, "port", translate("Radius-Port"))
265 port:depends({mode="ap", encryption="wpa"})
266 port:depends({mode="ap", encryption="wpa2"})
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"})
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"})