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
20 local fs = require "nixio.fs"
21 local sys = require "luci.sys"
22 local cursor = require "luci.model.uci".inst
23 local state = require "luci.model.uci".inst_state
24 cursor:unload("wireless")
26 local device = cursor:get("wireless", iface, "device")
27 local hwtype = cursor:get("wireless", device, "type")
29 local nsantenna = cursor:get("wireless", device, "antenna")
33 local chan = sys.wifi.channels()
35 state:foreach("wireless", "wifi-iface",
37 if s.device == device and not iw then
38 iw = sys.wifi.getiwinfo(s.ifname or s.device)
39 chan = sys.wifi.channels(s.ifname or s.device)
40 tx_powers = iw.txpwrlist or { }
48 m = Map("wireless", translate("Configure Access Point"))
51 --- Device Settings ---
52 s = m:section(NamedSection, device, "wifi-device", "Device Configuration")
55 s:tab("general", translate("General Settings"))
57 ch = s:taboption("general", Value, "channel", translate("Channel"))
58 ch:value("auto", translate("automatic"))
59 for _, f in ipairs(chan) do
60 ch:value(f.channel, "%i (%.3f GHz)" %{ f.channel, f.mhz / 1000 })
65 s:tab("expert", translate("Expert Settings"))
66 if hwtype == "mac80211" then
67 local macaddr = cursor:get("wireless", device, "macaddr") or "!"
68 local hwmode = cursor:get("wireless", device, "hwmode")
72 for entry in fs.glob("/sys/class/ieee80211/*") do
73 if (fs.readfile(entry .. "/macaddress") or ""):find(macaddr) == 1 then
78 local iwp = io.popen("iw phy " .. phy .. " info")
79 local iwin = iwp:read("*a")
83 local htcap = iwin:match("HT capabilities:%s*0x([0-9a-fA-F]+)")
84 allowed.n = (htcap and tonumber(htcap, 16) or 0) > 0
85 allowed.g = iwin:find("2412 MHz")
86 allowed.a = iwin:find("5180 MHz")
91 mode = s:taboption("expert", ListValue, "hwmode", translate("Communication Protocol"))
92 if allowed.n and allowed.g then
93 mode:value("11ng", "802.11n (2.4 GHz)")
95 if allowed.n and allowed.a then
96 mode:value("11na", "802.11n (5 GHz)")
99 mode:value("11a", "802.11a (5 GHz)")
102 mode:value("11g", "802.11g (2.4 GHz)")
103 mode:value("11bg", "802.11b+g (2.4 GHz)")
104 mode:value("11b", "802.11b (2.4 GHz)")
108 tp = s:taboption("expert",
109 (tx_powers and #tx_powers > 0) and ListValue or Value,
110 "txpower", translate("Transmission Power"), "dBm")
113 tp:value("", translate("automatic"))
114 for _, p in ipairs(iw and iw.txpwrlist or {}) do
115 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
117 elseif hwtype == "atheros" then
118 tp = s:taboption("expert",
119 (#tx_powers > 0) and ListValue or Value,
120 "txpower", translate("Transmission Power"), "dBm")
123 tp:value("", translate("automatic"))
124 for _, p in ipairs(iw.txpwrlist) do
125 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
128 mode = s:taboption("expert", ListValue, "hwmode", translate("Communication Protocol"))
129 mode:value("", translate("automatic"))
130 mode:value("11g", "802.11g")
131 mode:value("11b", "802.11b")
132 mode:value("11bg", "802.11b+g")
133 mode:value("11a", "802.11a")
134 mode:value("11gst", "802.11g + Turbo")
135 mode:value("11ast", "802.11a + Turbo")
137 if nsantenna then -- NanoFoo
138 local ant = s:taboption("expert", ListValue, "antenna", translate("Transmitter Antenna"))
140 ant:value("vertical")
141 ant:value("horizontal")
142 ant:value("external")
145 elseif hwtype == "broadcom" then
146 tp = s:taboption("expert",
147 (#tx_powers > 0) and ListValue or Value,
148 "txpower", translate("Transmit Power"), "dBm")
151 tp:value("", translate("automatic"))
152 for _, p in ipairs(iw.txpwrlist) do
153 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
156 mp = s:taboption("expert", ListValue, "macfilter", translate("MAC-Address Filter"))
157 mp:value("", translate("disable"))
158 mp:value("allow", translate("Allow listed only"))
159 mp:value("deny", translate("Allow all except listed"))
160 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
161 ml:depends({macfilter="allow"})
162 ml:depends({macfilter="deny"})
164 s:taboption("expert", Flag, "frameburst", translate("Allow Burst Transmissions"))
165 elseif hwtype == "prism2" then
166 s:taboption("expert", Value, "txpower", translate("Transmission Power"), "att units").rmempty = true
172 s = m:section(NamedSection, iface, "wifi-iface", translate("Interface Details"))
175 s:tab("general", translate("General Settings"))
176 s:tab("expert", translate("Expert Settings"))
178 s:taboption("general", Value, "ssid", translate("Network Name (<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>)"))
180 mode = s:taboption("expert", ListValue, "mode", translate("Operating Mode"))
181 mode.override_values = true
182 mode:value("ap", translate("Access Point"))
184 encr = s:taboption("expert", ListValue, "encryption", translate("Encryption"))
187 if hwtype == "mac80211" then
188 s:taboption("expert", Flag, "wds", "Allow Bridging and Repeating (WDS)")
189 s:taboption("expert", Flag, "powersave", "Enable Powersaving")
190 elseif hwtype == "atheros" then
191 -- mode:value("wds", translate("Static WDS"))
193 mp = s:taboption("expert", ListValue, "macpolicy", translate("MAC-Address Filter"))
194 mp:value("", translate("disable"))
195 mp:value("deny", translate("Allow listed only"))
196 mp:value("allow", translate("Allow all except listed"))
197 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
198 ml:depends({macpolicy="allow"})
199 ml:depends({macpolicy="deny"})
201 s:taboption("expert", Flag, "wds", "Allow Bridging and Repeating (WDS)")
204 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
205 hidden:depends({mode="ap"})
206 hidden:depends({mode="ap-wds"})
208 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
209 isolate:depends({mode="ap"})
212 s:taboption("expert", Flag, "bursting", translate("Allow Burst Transmissions"))
213 elseif hwtype == "broadcom" then
215 mode:value("wds", translate("WDS"))
217 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
218 hidden:depends({mode="ap"})
219 hidden:depends({mode="wds"})
221 isolate = s:taboption("expert", Flag, "isolate", translate("Prevent communication between clients"))
222 isolate:depends({mode="ap"})
224 elseif hwtype == "prism2" then
226 mode:value("wds", translate("WDS"))
229 mp = s:taboption("expert", ListValue, "macpolicy", translate("MAC-Address Filter"))
230 mp:value("", translate("disable"))
231 mp:value("deny", translate("Allow listed only"))
232 mp:value("allow", translate("Allow all except listed"))
234 ml = s:taboption("expert", DynamicList, "maclist", translate("MAC-List"))
235 ml:depends({macpolicy="allow"})
236 ml:depends({macpolicy="deny"})
239 hidden = s:taboption("expert", Flag, "hidden", translate("Hide Access Point"))
240 hidden:depends({mode="ap"})
241 hidden:depends({mode="wds"})
247 encr.default = "wep" -- Early default
248 encr.override_values = true
249 encr.override_depends = true
250 encr:value("none", "No Encryption")
251 encr:value("wep", "WEP", {mode="ap"})
253 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
254 local hostapd = fs.access("/usr/sbin/hostapd") or os.getenv("LUCI_SYSROOT")
257 --s:taboption("expert", Flag, "_alloweap", "Allow EAP / 802.11i authentication")
259 encr:value("psk", "WPA", {mode="ap"})
260 encr:value("wpa", "WPA-EAP", {mode="ap"})
261 encr:value("psk-mixed", "WPA + WPA2", {mode="ap"})
262 encr:value("psk2", "WPA2", {mode="ap"})
263 encr:value("wpa2", "WPA2-EAP (802.11i)", {mode="ap"})
264 encr.default = "psk-mixed"
266 elseif hwtype == "broadcom" then
267 encr:value("psk", "WPA")
268 encr:value("psk+psk2", "WPA + WPA2")
269 encr:value("psk2", "WPA2")
270 encr.default = "psk+psk2"
273 server = s:taboption("general", Value, "server", translate("Radius-Server"))
274 server:depends({mode="ap", encryption="wpa"})
275 server:depends({mode="ap", encryption="wpa2"})
276 server.rmempty = true
278 port = s:taboption("general", Value, "port", translate("Radius-Port"))
279 port:depends({mode="ap", encryption="wpa"})
280 port:depends({mode="ap", encryption="wpa2"})
283 key = s:taboption("general", Value, "key", translate("Password"))
284 key:depends("encryption", "wep")
285 key:depends("encryption", "psk")
286 key:depends("encryption", "psk2")
287 key:depends("encryption", "psk+psk2")
288 key:depends("encryption", "psk-mixed")
289 key:depends({mode="ap", encryption="wpa"})
290 key:depends({mode="ap", encryption="wpa2"})
294 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
295 nasid = s:taboption("general", Value, "nasid", translate("NAS ID"))
296 nasid:depends({mode="ap", encryption="wpa"})
297 nasid:depends({mode="ap", encryption="wpa2"})