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 ==
"ath" or name ==
"wifi" then
71 return translatef(
"Atheros 802.11%s Wireless Controller", bands)
74 elseif name ==
"ra" then
75 return translatef(
"RaLink 802.11%s Wireless Controller", bands)
78 elseif name ==
"eth" then
79 return translate(
"Hermes 802.11b Wireless Controller")
82 elseif name ==
"wlan" and fs.stat(
"/proc/net/hostap/" .. ifname,
"type") ==
"dir" then
83 return translate(
"Prism2/2.5/3 802.11b Wireless Controller")
87 return translatef(
"Generic 802.11%s Wireless Controller", bands)
91 local devices = ntm:get_wifidevs()
96 for _, dev in ipairs(devices) do
98 for _, net in ipairs(dev:get_wifinets()) do
99 netlist[#netlist+
1] = net:id()
100 netdevs[net:id()] = dev:name()
107 <% if not has_iwinfo then %
>
108 <div class=
"errorbox">
109 <strong><%:Package libiwinfo required!%
></strong><br />
110 <%_The
<em>libiwinfo-lua
</em> package is not installed. You must install this component for working wireless configuration!%
>
114 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
115 <script type=
"text/javascript">//<![CDATA[
116 var wifidevs = <%=luci.http.write_json(netdevs)%
>;
118 var is_reconnecting = false;
121 return s.replace(/ /g, '
 ');
124 function wifirate(bss, rx) {
125 var p = rx ? 'rx_' : 'tx_',
126 s = '%
.1f <%:Mbit/s%
>, %d<%:MHz%
>'
127 .format(bss[p+'rate'] /
1000, bss[p+'mhz']),
128 ht = bss[p+'ht'], vht = bss[p+'vht'],
129 mhz = bss[p+'mhz'], nss = bss[p+'nss'],
130 mcs = bss[p+'mcs'], sgi = bss[p+'short_gi'];
133 if (vht) s += ', VHT-MCS %d'.format(mcs);
134 if (nss) s += ', VHT-NSS %d'.format(nss);
135 if (ht) s += ', MCS %s'.format(mcs);
136 if (sgi) s += ', <%:Short GI%
>';
142 function wifi_shutdown(id, toggle) {
143 var reconnect = (toggle.getAttribute('active') == 'false');
145 if (!reconnect && !confirm(String.format('<%:Really shut down network?\nYou might lose access to this device if you are connected via this interface.%
>')))
148 is_reconnecting = true;
150 var s = document.getElementById('iw-rc-status');
153 s.parentNode.style.display = 'block';
154 s.innerHTML = '<%:Waiting for changes to be applied...%
>';
157 for (var net in wifidevs)
159 var st = document.getElementById(net + '-iw-status');
161 st.innerHTML = '
<em><%:Wireless is restarting...%
></em>';
164 (new XHR()).post('<%=url('admin/network')%
>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, { token: '<%=token%
>' },
169 s.innerHTML = reconnect
170 ? '<%:Wireless restarted%
>'
171 : '<%:Wireless shut down%
>';
173 window.setTimeout(function() {
174 s.parentNode.style.display = 'none';
175 is_reconnecting = false;
182 function wifi_delete(id) {
183 if (!confirm('<%:Really delete this wireless network? The deletion cannot be undone!\nYou might lose access to this device if you are connected via this network.%
>'))
186 (new XHR()).post('<%=url('admin/network/wireless_delete')%
>/' + id, { token: '<%=token%
>' },
188 location.href = '<%=url('admin/network/wireless')%
>';
193 var hosts = <%=luci.http.write_json(luci.sys.net.host_hints())%
>;
195 XHR.poll(
5, '<%=url('admin/network/wireless_status', table.concat(netlist,
","))%
>', null,
200 var assoctable = document.getElementById('iw-assoclist');
202 while (assoctable.rows.length
> 1)
203 assoctable.rows[
1].parentNode.removeChild(assoctable.rows[
1]);
208 for( var i =
0; i < st.length; i++ )
211 var is_assoc = (iw.bssid && iw.bssid != '
00:
00:
00:
00:
00:
00' && iw.channel && iw.mode != 'Unknown' && !iw.disabled);
213 var q = is_assoc ? p : -
1;
217 icon =
"<%=resource%>/icons/signal-none.png";
219 icon =
"<%=resource%>/icons/signal-0.png";
221 icon =
"<%=resource%>/icons/signal-0-25.png";
223 icon =
"<%=resource%>/icons/signal-25-50.png";
225 icon =
"<%=resource%>/icons/signal-50-75.png";
227 icon =
"<%=resource%>/icons/signal-75-100.png";
229 if (!devup[wifidevs[iw.id]])
230 devup[wifidevs[iw.id]] = is_assoc;
232 var sig = document.getElementById(iw.id + '-iw-signal');
234 sig.innerHTML = String.format(
235 '
<span class=
"ifacebadge" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>"><img src=
"%s" /> %d%%
</span>',
236 iw.signal, iw.noise, icon, p
239 var toggle = document.getElementById(iw.id + '-iw-toggle');
244 toggle.className = 'cbi-button cbi-button-reset';
245 toggle.value = '<%:Disable%
>';
246 toggle.title = '<%:Shutdown this network%
>';
250 toggle.className = 'cbi-button cbi-button-reload';
251 toggle.value = '<%:Enable%
>';
252 toggle.title = '<%:Activate this network%
>';
255 toggle.setAttribute('active', !iw.disabled);
258 var info = document.getElementById(iw.id + '-iw-status');
262 info.innerHTML = String.format(
263 '
<strong><%:SSID%
>:
</strong> %h | ' +
264 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
265 '
<strong><%:BSSID%
>:
</strong> %s | ' +
266 '
<strong><%:Encryption%
>:
</strong> %s',
267 iw.ssid, iw.mode, iw.bssid,
268 iw.encryption ? iw.encryption : '<%:None%
>'
271 info.innerHTML = String.format(
272 '
<strong><%:SSID%
>:
</strong> %h | ' +
273 '
<strong><%:Mode%
>:
</strong> %s
<br />' +
275 iw.ssid || '?', iw.mode,
277 ? '
<em><%:Wireless is restarting...%
></em>'
278 : '
<em><%:Wireless is disabled or not associated%
></em>'
282 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
286 dev.innerHTML = String.format(
287 '
<strong><%:Channel%
>:
</strong> %s (%s <%:GHz%
>) | ' +
288 '
<strong><%:Bitrate%
>:
</strong> %s <%:Mbit/s%
>',
289 iw.channel ? iw.channel : '?',
290 iw.frequency ? iw.frequency : '?',
291 iw.bitrate ? iw.bitrate : '?'
300 for( var bssid in iw.assoclist )
302 assoclist.push(iw.assoclist[bssid]);
303 assoclist[assoclist.length-
1].bssid = bssid;
306 assoclist.sort(function(a, b) { a.bssid < b.bssid });
308 for( var j =
0; j < assoclist.length; j++ )
310 var tr = assoctable.insertRow(-
1);
311 tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle;
314 var q = (-
1 * (assoclist[j].noise - assoclist[j].signal)) /
5;
316 icon =
"<%=resource%>/icons/signal-0.png";
318 icon =
"<%=resource%>/icons/signal-0-25.png";
320 icon =
"<%=resource%>/icons/signal-25-50.png";
322 icon =
"<%=resource%>/icons/signal-50-75.png";
324 icon =
"<%=resource%>/icons/signal-75-100.png";
326 tr.insertCell(-
1).innerHTML = String.format(
327 '
<span class=
"ifacebadge" title=
"%q"><img src=
"<%=resource%>/icons/wifi.png" /> %h
</span>',
328 iw.device.name, iw.ifname
331 tr.insertCell(-
1).innerHTML = nowrap(String.format('%h', iw.ssid ? iw.ssid : '?'));
332 tr.insertCell(-
1).innerHTML = assoclist[j].bssid;
334 var host = hosts[assoclist[j].bssid];
336 tr.insertCell(-
1).innerHTML = String.format(
337 '
<div style=
"max-width:200px;overflow:hidden;text-overflow:ellipsis">%s
</div>',
338 ((host.name && (host.ipv4 || host.ipv6))
339 ? '%h (%s)'.format(host.name, host.ipv4 || host.ipv6)
340 : '%h'.format(host.name || host.ipv4 || host.ipv6)).nobr()
343 tr.insertCell(-
1).innerHTML = '?';
345 tr.insertCell(-
1).innerHTML = String.format(
346 '
<span class=
"ifacebadge" title=
"<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%> / <%:SNR%>: %d"><img src=
"%s" /> %d / %d <%:dBm%
></span>',
347 assoclist[j].signal, assoclist[j].noise, assoclist[j].signal - assoclist[j].noise,
349 assoclist[j].signal, assoclist[j].noise
352 tr.insertCell(-
1).innerHTML = nowrap(wifirate(assoclist[j], true)) + '
<br />' + nowrap(wifirate(assoclist[j], false));
354 rowstyle = (rowstyle ==
1) ?
2 :
1;
359 if (assoctable && assoctable.rows.length ==
1)
361 var tr = assoctable.insertRow(-
1);
362 tr.className = 'cbi-section-table-row';
364 var td = tr.insertCell(-
1);
366 td.innerHTML = '
<br /><em><%:No information available%
></em>';
369 for (var dev in devup)
371 var img = document.getElementById(dev + '-iw-upstate');
373 img.src = '<%=resource%
>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
380 <h2 name=
"content"><%:Wireless Overview%
></h2>
382 <fieldset class=
"cbi-section" style=
"display:none">
383 <legend><%:Reconnecting interface%
></legend>
384 <img src=
"<%=resource%>/icons/loading.gif" alt=
"<%:Loading%>" style=
"vertical-align:middle" />
385 <span id=
"iw-rc-status"><%:Waiting for changes to be applied...%
></span>
388 <div class=
"cbi-map">
390 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %
>
391 <!-- device <%=dev:name()%> -->
392 <fieldset class=
"cbi-section">
393 <table class=
"cbi-section-table" style=
"margin:10px; empty-cells:hide">
394 <!-- physical device -->
396 <td style=
"width:34px"><img src=
"<%=resource%>/icons/wifi_big_disabled.png" style=
"float:left; margin-right:10px" id=
"<%=dev:name()%>-iw-upstate" /></td>
397 <td colspan=
"2" style=
"text-align:left">
398 <big><strong><%=guess_wifi_hw(dev)%
> (<%=dev:name()%
>)
</strong></big><br />
399 <span id=
"<%=dev:name()%>-iw-devinfo"></span>
401 <td style=
"width:310px;text-align:right">
402 <form action=
"<%=url('admin/network/wireless_join')%>" method=
"post" class=
"inline">
403 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
404 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
405 <input type=
"submit" class=
"cbi-button cbi-button-find" style=
"width:100px" title=
"<%:Find and join network%>" value=
"<%:Scan%>" />
407 <form action=
"<%=url('admin/network/wireless_add')%>" method=
"post" class=
"inline">
408 <input type=
"hidden" name=
"device" value=
"<%=dev:name()%>" />
409 <input type=
"hidden" name=
"token" value=
"<%=token%>" />
410 <input type=
"submit" class=
"cbi-button cbi-button-add" style=
"width:100px" title=
"<%:Provide new network%>" value=
"<%:Add%>" />
414 <!-- /physical device -->
416 <!-- network list -->
417 <% if #nets
> 0 then %
>
418 <% for i, net in ipairs(nets) do %
>
419 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
421 <td class=
"cbi-value-field" style=
"vertical-align:middle; padding:3px" id=
"<%=net:id()%>-iw-signal">
422 <span class=
"ifacebadge" title=
"<%:Not associated%>"><img src=
"<%=resource%>/icons/signal-none.png" /> 0%
</span>
424 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px" id=
"<%=net:id()%>-iw-status">
425 <em><%:Collecting data...%
></em>
427 <td class=
"cbi-value-field" style=
"width:310px;text-align:right">
428 <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%>" />
429 <input type=
"button" class=
"cbi-button cbi-button-edit" style=
"width:100px" onclick=
"location.href='<%=net:adminlink()%>'" title=
"<%:Edit this network%>" value=
"<%:Edit%>" />
430 <input type=
"button" class=
"cbi-button cbi-button-remove" style=
"width:100px" onclick=
"wifi_delete('<%=net:id()%>')" title=
"<%:Delete this network%>" value=
"<%:Remove%>" />
435 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
437 <td colspan=
"3" class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
438 <em><%:No network configured on this device%
></em>
442 <!-- /network list -->
445 <!-- /device <%=dev:name()%> -->
449 <h2><%:Associated Stations%
></h2>
451 <fieldset class=
"cbi-section">
452 <table class=
"cbi-section-table valign-middle" style=
"margin:10px" id=
"iw-assoclist">
453 <tr class=
"cbi-section-table-titles">
454 <th class=
"cbi-section-table-cell"></th>
455 <th class=
"cbi-section-table-cell"><%:SSID%
></th>
456 <th class=
"cbi-section-table-cell"><%:MAC-Address%
></th>
457 <th class=
"cbi-section-table-cell"><%:Host%
></th>
458 <th class=
"cbi-section-table-cell"><%:Signal%
> / <%:Noise%
></th>
459 <th class=
"cbi-section-table-cell"><%:RX Rate%
> / <%:TX Rate%
></th>
461 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
462 <td class=
"cbi-value-field" colspan=
"6">
463 <em><%:Collecting data...%
></em>