2 Copyright
2008-
2009 Steven Barth
<steven@midlink.org
>
3 Copyright
2008-
2015 Jo-Philipp Wich
<jow@openwrt.org
>
4 Licensed to the public under the Apache License
2.0.
9 local ip = require
"luci.ip"
10 local fs = require
"nixio.fs"
11 local utl = require
"luci.util"
12 local uci = require
"luci.model.uci".cursor()
13 local ntm = require
"luci.model.network"
15 local has_iwinfo = pcall(require,
"iwinfo")
19 function guess_wifi_hw(dev)
21 local ifname = dev:name()
22 local name, idx = ifname:match(
"^([a-z]+)(%d+)")
26 local bl = dev.iwinfo.hwmodelist
27 if bl and next(bl) then
28 if bl.a then bands = bands ..
"a" end
29 if bl.b then bands = bands ..
"b" end
30 if bl.g then bands = bands ..
"g" end
31 if bl.n then bands = bands ..
"n" end
32 if bl.ac then bands = bands ..
"ac" end
35 local hw = dev.iwinfo.hardware_name
37 return
"%s 802.11%s" %{ hw, bands }
43 local name = translatef(
"Broadcom 802.11%s Wireless Controller", bands)
46 local fd = nixio.open(
"/proc/bus/pci/devices",
"r")
49 for ln in fd:linesource() do
50 if ln:match(
"wl$") then
52 local version = ln:match(
"^%S+%s+%S%S%S%S([0-9a-f]+)")
54 "Broadcom BCM%04x 802.11 Wireless Controller",
70 elseif name ==
"ra" then
71 return translatef(
"RaLink 802.11%s Wireless Controller", bands)
74 elseif name ==
"eth" then
75 return translate(
"Hermes 802.11b Wireless Controller")
78 elseif name ==
"wlan" and fs.stat(
"/proc/net/hostap/" .. ifname,
"type") ==
"dir" then
79 return translate(
"Prism2/2.5/3 802.11b Wireless Controller")
83 return translatef(
"Generic 802.11%s Wireless Controller", bands)
87 local devices = ntm:get_wifidevs()
92 for _, dev in ipairs(devices) do
94 for _, net in ipairs(dev:get_wifinets()) do
95 netlist[#netlist+
1] = net:id()
96 netdevs[net:id()] = dev:name()
103 <% if not has_iwinfo then %
>
104 <div class=
"alert-message warning">
105 <h4><%:Package libiwinfo required!%
></h4>
106 <p><%_The
<em>libiwinfo-lua
</em> package is not installed. You must install this component for working wireless configuration!%
></p>
110 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
111 <script type=
"text/javascript">//<![CDATA[
112 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
114 var is_reconnecting = false;
116 function wifi_shutdown(id, toggle) {
117 var reconnect = (toggle.getAttribute('active') == 'false');
119 if (!reconnect && !confirm(<%=luci.http.write_json(translate('Really shut down network? You might lose access to this device if you are connected via this interface'))%
>))
122 is_reconnecting = true;
124 var s = document.getElementById('iw-rc-status');
127 s.parentNode.style.display = 'block';
128 s.innerHTML = '<%:Waiting for changes to be applied...%
>';
131 for (var net in wifidevs)
133 var st = document.getElementById(net + '-iw-status');
135 st.innerHTML = '
<em><%:Wireless is restarting...%
></em>';
138 (new XHR()).post('<%=url('admin/network')%
>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, { token: '<%=token%
>' },
143 s.innerHTML = reconnect
144 ? '<%:Wireless restarted%
>'
145 : '<%:Wireless shut down%
>';
147 window.setTimeout(function() {
148 s.parentNode.style.display = 'none';
149 is_reconnecting = false;
156 function wifi_delete(id) {
157 if (!confirm(<%=luci.http.write_json(translate('Really delete this wireless network? The deletion cannot be undone! You might lose access to this device if you are connected via this network.'))%
>))
160 (new XHR()).post('<%=url('admin/network/wireless_delete')%
>/' + id, { token: '<%=token%
>' },
162 location.href = '<%=url('admin/network/wireless')%
>';
167 var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%
>;
169 XHR.poll(
5, '<%=url('admin/network/wireless_status', table.concat(netlist,
","))%
>', null,
175 var radiostate = { };
177 st.forEach(function(s) {
178 var r = radiostate[wifidevs[s.id]] || (radiostate[wifidevs[s.id]] = {});
180 s.is_assoc = (s.bssid && s.bssid != '
00:
00:
00:
00:
00:
00' && s.channel && s.mode != 'Unknown' && !s.disabled);
182 r.up = r.up || s.is_assoc;
183 r.channel = r.channel || s.channel;
184 r.bitrate = r.bitrate || s.bitrate;
185 r.frequency = r.frequency || s.frequency;
188 for( var i =
0; i < st.length; i++ )
192 var q = iw.is_assoc ? p : -
1;
196 icon =
"<%=resource%>/icons/signal-none.png";
198 icon =
"<%=resource%>/icons/signal-0.png";
200 icon =
"<%=resource%>/icons/signal-0-25.png";
202 icon =
"<%=resource%>/icons/signal-25-50.png";
204 icon =
"<%=resource%>/icons/signal-50-75.png";
206 icon =
"<%=resource%>/icons/signal-75-100.png";
208 var sig = document.getElementById(iw.id + '-iw-signal');
210 sig.innerHTML = String.format(
211 '
<span class=
"ifacebadge" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>"><img src=
"%s" /> %d%%
</span>',
212 iw.signal, iw.noise, icon, p
215 var toggle = document.getElementById(iw.id + '-iw-toggle');
220 toggle.className = 'cbi-button cbi-button-neutral';
221 toggle.value = '<%:Disable%
>';
222 toggle.title = '<%:Shutdown this network%
>';
226 toggle.className = 'cbi-button cbi-button-neutral';
227 toggle.value = '<%:Enable%
>';
228 toggle.title = '<%:Activate this network%
>';
231 toggle.setAttribute('active', !iw.disabled);
234 var info = document.getElementById(iw.id + '-iw-status');
238 info.innerHTML = String.format(
239 '
<strong><%:SSID%
>:
</strong> %h | ' +
240 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
241 '
<strong><%:BSSID%
>:
</strong> %s | ' +
242 '
<strong><%:Encryption%
>:
</strong> %s',
243 iw.ssid, iw.mode, iw.bssid,
244 iw.encryption ? iw.encryption : '<%:None%
>'
247 info.innerHTML = String.format(
248 '
<strong><%:SSID%
>:
</strong> %h | ' +
249 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
251 iw.ssid || '?', iw.mode,
253 ? '
<em><%:Wireless is restarting...%
></em>'
254 : '
<em><%:Wireless is disabled or not associated%
></em>'
259 for (var dev in radiostate)
261 var img = document.getElementById(dev + '-iw-upstate');
263 img.src = '<%=resource%
>/icons/wifi' + (radiostate[dev].up ? '' : '_disabled') + '.png';
265 var stat = document.getElementById(dev + '-iw-devinfo');
267 stat.innerHTML = String.format(
268 '
<strong><%:Channel%
>:
</strong> %s (%s <%:GHz%
>) | ' +
269 '
<strong><%:Bitrate%
>:
</strong> %s <%:Mbit/s%
>',
270 radiostate[dev].channel ? radiostate[dev].channel : '?',
271 radiostate[dev].frequency ? radiostate[dev].frequency : '?',
272 radiostate[dev].bitrate ? radiostate[dev].bitrate : '?'
280 <h2 name=
"content"><%:Wireless Overview%
></h2>
282 <div class=
"cbi-section" style=
"display:none">
283 <legend><%:Reconnecting interface%
></legend>
284 <img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" />
285 <span id=
"iw-rc-status"><%:Waiting for changes to be applied...%
></span>
288 <div id=
"cbi-wireless-overview" class=
"cbi-map">
290 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
291 <!-- device <%=dev:name()%> -->
292 <div class=
"cbi-section-node">
294 <!-- physical device -->
296 <div class=
"td col-2 center">
297 <span class=
"ifacebadge"><img src=
"<%=resource%>/icons/wifi_disabled.png" id=
"<%=dev:name()%>-iw-upstate" /> <%=dev:name()%
></span>
299 <div class=
"td col-7 left">
300 <big><strong><%=guess_wifi_hw(dev)%
></strong></big><br />
301 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
303 <div class=
"td cbi-section-actions">
304 <form action=
"<%=url('admin/network/wireless_join')%>" method=
"post" class=
"inline">
305 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
306 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
307 <input type=
"submit" class=
"cbi-button cbi-button-action" title=
"<%:Find and join network%>" value=
"<%:Scan%>" />
309 <form action=
"<%=url('admin/network/wireless_add')%>" method=
"post" class=
"inline">
310 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
311 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
312 <input type=
"submit" class=
"cbi-button cbi-button-add" title=
"<%:Provide new network%>" value=
"<%:Add%>" />
316 <!-- /physical device -->
318 <!-- network list -->
319 <% if #nets
> 0 then %
>
320 <% for i, net in ipairs(nets) do %
>
321 <div class=
"tr cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
322 <div class=
"td col-2 center" id=
"<%=net:id()%>-iw-signal">
323 <span class=
"ifacebadge" title=
"<%:Not associated%>"><img src=
"<%=resource%>/icons/signal-none.png" /> 0%
</span>
325 <div class=
"td col-7 left" id=
"<%=net:id()%>-iw-status">
326 <em><%:Collecting data...%
></em>
328 <div class=
"td cbi-section-actions">
329 <input id=
"<%=net:id()%>-iw-toggle" type=
"button" class=
"cbi-button cbi-button-neutral" onclick=
"wifi_shutdown('<%=net:id()%>', this)" title=
"<%:Enable this network%>" value=
"<%:Enable%>" />
330 <input type=
"button" class=
"cbi-button cbi-button-action important" onclick=
"location.href='<%=net:adminlink()%>'" title=
"<%:Edit this network%>" value=
"<%:Edit%>" />
331 <input type=
"button" class=
"cbi-button cbi-button-negative" onclick=
"wifi_delete('<%=net:id()%>')" title=
"<%:Delete this network%>" value=
"<%:Remove%>" />
336 <div class=
"tr cbi-rowstyle-2">
337 <div class=
"td left">
338 <em><%:No network configured on this device%
></em>
342 <!-- /network list -->
345 <!-- /device <%=dev:name()%> -->
349 <h2><%:Associated Stations%
></h2>
351 <%+admin_network/wifi_assoclist%
>