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;
117 return s.replace(/ /g, '
 ');
120 function wifirate(bss, rx) {
121 var p = rx ? 'rx_' : 'tx_',
122 s = '%
.1f <%:Mbit/s%
>, %d<%:MHz%
>'
123 .format(bss[p+'rate'] /
1000, bss[p+'mhz']),
124 ht = bss[p+'ht'], vht = bss[p+'vht'],
125 mhz = bss[p+'mhz'], nss = bss[p+'nss'],
126 mcs = bss[p+'mcs'], sgi = bss[p+'short_gi'];
129 if (vht) s += ', VHT-MCS %d'.format(mcs);
130 if (nss) s += ', VHT-NSS %d'.format(nss);
131 if (ht) s += ', MCS %s'.format(mcs);
132 if (sgi) s += ', <%:Short GI%
>';
138 function wifi_shutdown(id, toggle) {
139 var reconnect = (toggle.getAttribute('active') == 'false');
141 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'))%
>))
144 is_reconnecting = true;
146 var s = document.getElementById('iw-rc-status');
149 s.parentNode.style.display = 'block';
150 s.innerHTML = '<%:Waiting for changes to be applied...%
>';
153 for (var net in wifidevs)
155 var st = document.getElementById(net + '-iw-status');
157 st.innerHTML = '
<em><%:Wireless is restarting...%
></em>';
160 (new XHR()).post('<%=url('admin/network')%
>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, { token: '<%=token%
>' },
165 s.innerHTML = reconnect
166 ? '<%:Wireless restarted%
>'
167 : '<%:Wireless shut down%
>';
169 window.setTimeout(function() {
170 s.parentNode.style.display = 'none';
171 is_reconnecting = false;
178 function wifi_delete(id) {
179 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.'))%
>))
182 (new XHR()).post('<%=url('admin/network/wireless_delete')%
>/' + id, { token: '<%=token%
>' },
184 location.href = '<%=url('admin/network/wireless')%
>';
189 var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%
>;
191 XHR.poll(
5, '<%=url('admin/network/wireless_status', table.concat(netlist,
","))%
>', null,
196 var assoctable = document.getElementById('iw-assoclist');
198 while (assoctable.firstElementChild !== assoctable.lastElementChild)
199 assoctable.removeChild(assoctable.lastElementChild);
204 for( var i =
0; i < st.length; i++ )
207 var is_assoc = (iw.bssid && iw.bssid != '
00:
00:
00:
00:
00:
00' && iw.channel && iw.mode != 'Unknown' && !iw.disabled);
209 var q = is_assoc ? p : -
1;
213 icon =
"<%=resource%>/icons/signal-none.png";
215 icon =
"<%=resource%>/icons/signal-0.png";
217 icon =
"<%=resource%>/icons/signal-0-25.png";
219 icon =
"<%=resource%>/icons/signal-25-50.png";
221 icon =
"<%=resource%>/icons/signal-50-75.png";
223 icon =
"<%=resource%>/icons/signal-75-100.png";
225 if (!devup[wifidevs[iw.id]])
226 devup[wifidevs[iw.id]] = is_assoc;
228 var sig = document.getElementById(iw.id + '-iw-signal');
230 sig.innerHTML = String.format(
231 '
<span class=
"ifacebadge" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>"><img src=
"%s" /> %d%%
</span>',
232 iw.signal, iw.noise, icon, p
235 var toggle = document.getElementById(iw.id + '-iw-toggle');
240 toggle.className = 'cbi-button cbi-button-reset';
241 toggle.value = '<%:Disable%
>';
242 toggle.title = '<%:Shutdown this network%
>';
246 toggle.className = 'cbi-button cbi-button-reload';
247 toggle.value = '<%:Enable%
>';
248 toggle.title = '<%:Activate this network%
>';
251 toggle.setAttribute('active', !iw.disabled);
254 var info = document.getElementById(iw.id + '-iw-status');
258 info.innerHTML = String.format(
259 '
<strong><%:SSID%
>:
</strong> %h | ' +
260 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
261 '
<strong><%:BSSID%
>:
</strong> %s | ' +
262 '
<strong><%:Encryption%
>:
</strong> %s',
263 iw.ssid, iw.mode, iw.bssid,
264 iw.encryption ? iw.encryption : '<%:None%
>'
267 info.innerHTML = String.format(
268 '
<strong><%:SSID%
>:
</strong> %h | ' +
269 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
271 iw.ssid || '?', iw.mode,
273 ? '
<em><%:Wireless is restarting...%
></em>'
274 : '
<em><%:Wireless is disabled or not associated%
></em>'
278 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
282 dev.innerHTML = String.format(
283 '
<strong><%:Channel%
>:
</strong> %s (%s <%:GHz%
>) | ' +
284 '
<strong><%:Bitrate%
>:
</strong> %s <%:Mbit/s%
>',
285 iw.channel ? iw.channel : '?',
286 iw.frequency ? iw.frequency : '?',
287 iw.bitrate ? iw.bitrate : '?'
296 for (var bssid in iw.assoclist)
298 assoclist.push(iw.assoclist[bssid]);
299 assoclist[assoclist.length-
1].bssid = bssid;
302 assoclist.sort(function(a, b) { a.bssid < b.bssid });
304 for (var j =
0; j < assoclist.length; j++)
307 var q = (-
1 * (assoclist[j].noise - assoclist[j].signal)) /
5;
309 icon =
"<%=resource%>/icons/signal-0.png";
311 icon =
"<%=resource%>/icons/signal-0-25.png";
313 icon =
"<%=resource%>/icons/signal-25-50.png";
315 icon =
"<%=resource%>/icons/signal-50-75.png";
317 icon =
"<%=resource%>/icons/signal-75-100.png";
319 var host = hosts[assoclist[j].bssid],
320 name = host ? (host.name || host.ipv4 || host.ipv6) : null,
321 hint = (host && host.name && (host.ipv4 || host.ipv6)) ? (host.ipv4 || host.ipv6) : null;
323 assoctable.appendChild(E('
<div class=
"tr cbi-section-table-row cbi-rowstyle-%d">'.format(rowstyle), [
324 E('
<div class=
"td"><span class=
"ifacebadge" title=
"%q"><img src=
"<%=resource%>/icons/wifi.png" /> %h
</span></div>'
325 .format(iw.device.name, iw.ifname)),
326 E('
<div class=
"td" style=
"white-space:nowrap">%h
</div>'
327 .format(iw.ssid || '?')),
328 E('
<div class=
"td">%h
</div>'
329 .format(assoclist[j].bssid)),
330 E('
<div class=
"td">', hint ? '
<div style=
"max-width:200px;overflow:hidden;text-overflow:ellipsis">%h (%h)
</div>'
331 .format(name || '?', hint) : (name || '?')),
332 E('
<div class=
"td"><span class=
"ifacebadge" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%> / <%:SNR%>: %d"><img src=
"%s" /> %d / %d <%:dBm%
></span></div>'
333 .format(assoclist[j].signal, assoclist[j].noise, assoclist[j].signal - assoclist[j].noise, icon, assoclist[j].signal, assoclist[j].noise)),
334 E('
<div class=
"td">', [
335 E('
<span style=
"white-space:nowrap">', wifirate(assoclist[j], true)),
337 E('
<span style=
"white-space:nowrap">', wifirate(assoclist[j], false))
341 rowstyle = (rowstyle ==
1) ?
2 :
1;
346 if (assoctable && assoctable.firstElementChild === assoctable.lastElementChild)
347 assoctable.appendChild(E('
<div class=
"tr cbi-section-table-row"><div class=
"td"><em><br /><%:No information available%
></em></div></div>'));
349 for (var dev in devup)
351 var img = document.getElementById(dev + '-iw-upstate');
353 img.src = '<%=resource%
>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
360 <h2 name=
"content"><%:Wireless Overview%
></h2>
362 <fieldset class=
"cbi-section" style=
"display:none">
363 <legend><%:Reconnecting interface%
></legend>
364 <img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" />
365 <span id=
"iw-rc-status"><%:Waiting for changes to be applied...%
></span>
368 <div class=
"cbi-map">
370 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
371 <!-- device <%=dev:name()%> -->
372 <fieldset class=
"cbi-section">
373 <div class=
"table cbi-section-table" style=
"margin:10px; empty-cells:hide">
374 <!-- physical device -->
377 <img src=
"<%=resource%>/icons/wifi_big_disabled.png" id=
"<%=dev:name()%>-iw-upstate" />
379 <div class=
"td left">
380 <big><strong><%=guess_wifi_hw(dev)%
> (<%=dev:name()%
>)
</strong></big><br />
381 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
383 <div class=
"td right">
384 <form action=
"<%=url('admin/network/wireless_join')%>" method=
"post" class=
"inline">
385 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
386 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
387 <input type=
"submit" class=
"cbi-button cbi-button-find" style=
"width:100px" title=
"<%:Find and join network%>" value=
"<%:Scan%>" />
389 <form action=
"<%=url('admin/network/wireless_add')%>" method=
"post" class=
"inline">
390 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
391 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
392 <input type=
"submit" class=
"cbi-button cbi-button-add" style=
"width:100px" title=
"<%:Provide new network%>" value=
"<%:Add%>" />
396 <!-- /physical device -->
398 <!-- network list -->
399 <% if #nets
> 0 then %
>
400 <% for i, net in ipairs(nets) do %
>
401 <div class=
"tr cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
402 <div class=
"td" id=
"<%=net:id()%>-iw-signal">
403 <span class=
"ifacebadge" title=
"<%:Not associated%>"><img src=
"<%=resource%>/icons/signal-none.png" /> 0%
</span>
405 <div class=
"td left" id=
"<%=net:id()%>-iw-status">
406 <em><%:Collecting data...%
></em>
408 <div class=
"td right">
409 <input id=
"<%=net:id()%>-iw-toggle" type=
"button" class=
"cbi-button cbi-button-reload" style=
"width:100px" onclick=
"wifi_shutdown('<%=net:id()%>', this)" title=
"<%:Delete this network%>" value=
"<%:Enable%>" />
410 <input type=
"button" class=
"cbi-button cbi-button-edit" style=
"width:100px" onclick=
"location.href='<%=net:adminlink()%>'" title=
"<%:Edit this network%>" value=
"<%:Edit%>" />
411 <input type=
"button" class=
"cbi-button cbi-button-remove" style=
"width:100px" onclick=
"wifi_delete('<%=net:id()%>')" title=
"<%:Delete this network%>" value=
"<%:Remove%>" />
416 <div class=
"tr cbi-section-table-row cbi-rowstyle-2">
417 <div class=
"td left">
418 <em><%:No network configured on this device%
></em>
422 <!-- /network list -->
425 <!-- /device <%=dev:name()%> -->
429 <h2><%:Associated Stations%
></h2>
431 <fieldset class=
"cbi-section">
432 <div class=
"table cbi-section-table valign-middle" style=
"margin:10px" id=
"iw-assoclist">
433 <div class=
"tr cbi-section-table-titles">
434 <div class=
"th cbi-section-table-cell"></div>
435 <div class=
"th cbi-section-table-cell"><%:SSID%
></div>
436 <div class=
"th cbi-section-table-cell"><%:MAC-Address%
></div>
437 <div class=
"th cbi-section-table-cell"><%:Host%
></div>
438 <div class=
"th cbi-section-table-cell"><%:Signal%
> / <%:Noise%
></div>
439 <div class=
"th cbi-section-table-cell"><%:RX Rate%
> / <%:TX Rate%
></div>
441 <div class=
"tr cbi-section-table-row cbi-rowstyle-2">
443 <em><%:Collecting data...%
></em>