2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2013 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
16 local sys = require "luci.sys"
17 local fs = require "luci.fs"
18 local utl = require "luci.util"
19 local uci = require "luci.model.uci".cursor()
20 local ntm = require "luci.model.network"
22 local has_iwinfo = pcall(require, "iwinfo")
26 function guess_wifi_hw(dev)
28 local ifname = dev:name()
29 local name, idx = ifname:match("^([a-z]+)(%d+)")
33 local bl = dev.iwinfo.hwmodelist
34 if bl and next(bl) then
35 if bl.a then bands = bands .. "a" end
36 if bl.b then bands = bands .. "b" end
37 if bl.g then bands = bands .. "g" end
38 if bl.n then bands = bands .. "n" end
39 if bl.ac then bands = bands .. "ac" end
42 local hw = dev.iwinfo.hardware_name
44 return "%s 802.11%s" %{ hw, bands }
50 local name = translatef("Broadcom 802.11%s Wireless Controller", bands)
53 local fd = nixio.open("/proc/bus/pci/devices", "r")
56 for ln in fd:linesource() do
57 if ln:match("wl$") then
59 local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
61 "Broadcom BCM%04x 802.11 Wireless Controller",
77 elseif name == "ath" or name == "wifi" then
78 return translatef("Atheros 802.11%s Wireless Controller", bands)
81 elseif name == "ra" then
82 return translatef("RaLink 802.11%s Wireless Controller", bands)
85 elseif name == "eth" then
86 return translate("Hermes 802.11b Wireless Controller")
89 elseif name == "wlan" and fs.isdirectory("/proc/net/hostap/" .. ifname) then
90 return translate("Prism2/2.5/3 802.11b Wireless Controller")
94 return translatef("Generic 802.11%s Wireless Controller", bands)
98 local devices = ntm:get_wifidevs()
100 sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end)
106 for _, dev in ipairs(devices) do
108 for _, net in ipairs(dev:get_wifinets()) do
109 netlist[#netlist+1] = net:id()
110 netdevs[net:id()] = dev:name()
117 <% if not has_iwinfo then %>
118 <div class="errorbox">
119 <strong><%:Package libiwinfo required!%></strong><br />
120 <%_The <em>libiwinfo-lua</em> package is not installed. You must install this component for working wireless configuration!%>
124 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
125 <script type="text/javascript">//<![CDATA[
126 var wifidevs = <%=luci.http.write_json(netdevs)%>;
127 var arptable = <%=luci.http.write_json(arpcache)%>;
129 var is_reconnecting = false;
132 return s.replace(/ /g, ' ');
135 function wifi_shutdown(id, toggle) {
136 var reconnect = (toggle.getAttribute('active') == 'false');
138 if (!reconnect && !confirm(String.format('<%:Really shut down network?\nYou might lose access to this device if you are connected via this interface.%>')))
141 is_reconnecting = true;
143 var s = document.getElementById('iw-rc-status');
146 s.parentNode.style.display = 'block';
147 s.innerHTML = '<%:Waiting for changes to be applied...%>';
150 for (var net in wifidevs)
152 var st = document.getElementById(net + '-iw-status');
154 st.innerHTML = '<em><%:Wireless is restarting...%></em>';
157 XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
162 s.innerHTML = reconnect
163 ? '<%:Wireless restarted%>'
164 : '<%:Wireless shut down%>';
166 window.setTimeout(function() {
167 s.parentNode.style.display = 'none';
168 is_reconnecting = false;
175 XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null,
180 var assoctable = document.getElementById('iw-assoclist');
182 while (assoctable.rows.length > 1)
183 assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]);
188 for( var i = 0; i < st.length; i++ )
191 var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel && iw.mode != 'Unknown');
193 var q = is_assoc ? p : -1;
197 icon = "<%=resource%>/icons/signal-none.png";
199 icon = "<%=resource%>/icons/signal-0.png";
201 icon = "<%=resource%>/icons/signal-0-25.png";
203 icon = "<%=resource%>/icons/signal-25-50.png";
205 icon = "<%=resource%>/icons/signal-50-75.png";
207 icon = "<%=resource%>/icons/signal-75-100.png";
209 if (!devup[wifidevs[iw.id]])
210 devup[wifidevs[iw.id]] = is_assoc;
212 var sig = document.getElementById(iw.id + '-iw-signal');
214 sig.innerHTML = String.format(
215 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" /><br />' +
216 '<small>%d%%</small>', icon, iw.signal, iw.noise, p
219 var toggle = document.getElementById(iw.id + '-iw-toggle');
224 toggle.className = 'cbi-button cbi-button-reset';
225 toggle.value = '<%:Disable%>';
226 toggle.title = '<%:Shutdown this network%>';
230 toggle.className = 'cbi-button cbi-button-reload';
231 toggle.value = '<%:Enable%>';
232 toggle.title = '<%:Activate this network%>';
235 toggle.setAttribute('active', !iw.disabled);
238 var info = document.getElementById(iw.id + '-iw-status');
242 info.innerHTML = String.format(
243 '<strong><%:SSID%>:</strong> %h | ' +
244 '<strong><%:Mode%>:</strong> %s<br />' +
245 '<strong><%:BSSID%>:</strong> %s | ' +
246 '<strong><%:Encryption%>:</strong> %s',
247 iw.ssid, iw.mode, iw.bssid,
248 iw.encryption ? iw.encryption : '<%:None%>'
251 info.innerHTML = String.format(
252 '<strong><%:SSID%>:</strong> %h | ' +
253 '<strong><%:Mode%>:</strong> %s<br />' +
255 iw.ssid || '?', iw.mode,
257 ? '<em><%:Wireless is restarting...%></em>'
258 : '<em><%:Wireless is disabled or not associated%></em>'
262 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
266 dev.innerHTML = String.format(
267 '<strong><%:Channel%>:</strong> %s (%s <%:GHz%>) | ' +
268 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%>',
269 iw.channel ? iw.channel : '?',
270 iw.frequency ? iw.frequency : '?',
271 iw.bitrate ? iw.bitrate : '?'
280 for( var bssid in iw.assoclist )
282 assoclist.push(iw.assoclist[bssid]);
283 assoclist[assoclist.length-1].bssid = bssid;
286 assoclist.sort(function(a, b) { a.bssid < b.bssid });
288 for( var j = 0; j < assoclist.length; j++ )
290 var tr = assoctable.insertRow(-1);
291 tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle;
294 var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5;
296 icon = "<%=resource%>/icons/signal-0.png";
298 icon = "<%=resource%>/icons/signal-0-25.png";
300 icon = "<%=resource%>/icons/signal-25-50.png";
302 icon = "<%=resource%>/icons/signal-50-75.png";
304 icon = "<%=resource%>/icons/signal-75-100.png";
306 tr.insertCell(-1).innerHTML = String.format(
307 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
308 icon, assoclist[j].signal, assoclist[j].noise
311 tr.insertCell(-1).innerHTML = nowrap(String.format('%h', iw.ssid ? iw.ssid : '?'));
312 tr.insertCell(-1).innerHTML = assoclist[j].bssid;
314 tr.insertCell(-1).innerHTML = arptable[assoclist[j].bssid]
315 ? arptable[assoclist[j].bssid] : '?';
317 tr.insertCell(-1).innerHTML = nowrap(String.format('%d <%:dBm%>', assoclist[j].signal));
318 tr.insertCell(-1).innerHTML = nowrap(String.format('%d <%:dBm%>', assoclist[j].noise));
320 tr.insertCell(-1).innerHTML = nowrap((assoclist[j].rx_mcs > -1)
321 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[j].rx_rate / 1000, assoclist[j].rx_mcs, assoclist[j].rx_40mhz ? 40 : 20)
322 : String.format('%.1f <%:Mbit/s%>', assoclist[j].rx_rate / 1000)
325 tr.insertCell(-1).innerHTML = nowrap((assoclist[j].tx_mcs > -1)
326 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[j].tx_rate / 1000, assoclist[j].tx_mcs, assoclist[j].tx_40mhz ? 40 : 20)
327 : String.format('%.1f <%:Mbit/s%>', assoclist[j].tx_rate / 1000)
330 rowstyle = (rowstyle == 1) ? 2 : 1;
335 if (assoctable && assoctable.rows.length == 1)
337 var tr = assoctable.insertRow(-1);
338 tr.className = 'cbi-section-table-row';
340 var td = tr.insertCell(-1);
342 td.innerHTML = '<br /><em><%:No information available%></em>';
345 for (var dev in devup)
347 var img = document.getElementById(dev + '-iw-upstate');
349 img.src = '<%=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
356 <h2><a id="content" name="content"><%:Wireless Overview%></a></h2>
358 <fieldset class="cbi-section" style="display:none">
359 <legend><%:Reconnecting interface%></legend>
360 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
361 <span id="iw-rc-status"><%:Waiting for changes to be applied...%></span>
364 <div class="cbi-map">
366 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %>
367 <!-- device <%=dev:name()%> -->
368 <fieldset class="cbi-section">
369 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
370 <!-- physical device -->
372 <td style="width:34px"><img src="<%=resource%>/icons/wifi_big_disabled.png" style="float:left; margin-right:10px" id="<%=dev:name()%>-iw-upstate" /></td>
373 <td colspan="2" style="text-align:left">
374 <big><strong><%=guess_wifi_hw(dev)%> (<%=dev:name()%>)</strong></big><br />
375 <span id="<%=dev:name()%>-iw-devinfo"></span>
377 <td style="width:310px;text-align:right">
378 <input type="button" class="cbi-button cbi-button-find" style="width:100px" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/wireless_join")%>?device=<%=dev:name()%>'" title="<%:Find and join network%>" value="<%:Scan%>" />
379 <input type="button" class="cbi-button cbi-button-add" style="width:100px" onclick="location.href='<%=luci.dispatcher.build_url("admin/network/wireless_add")%>?device=<%=dev:name()%>'" title="<%:Provide new network%>" value="<%:Add%>" />
382 <!-- /physical device -->
384 <!-- network list -->
385 <% if #nets > 0 then %>
386 <% for i, net in ipairs(nets) do %>
387 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
389 <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=net:id()%>-iw-signal">
390 <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br />
393 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net:id()%>-iw-status">
394 <em><%:Collecting data...%></em>
396 <td class="cbi-value-field" style="width:310px;text-align:right">
397 <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%>" />
398 <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=net:adminlink()%>'" title="<%:Edit this network%>" value="<%:Edit%>" />
399 <input type="button" class="cbi-button cbi-button-remove" style="width:100px" onclick="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.%>')) location.href='<%=luci.dispatcher.build_url("admin/network/wireless_delete", net:ifname())%>'" title="<%:Delete this network%>" value="<%:Remove%>" />
404 <tr class="cbi-section-table-row cbi-rowstyle-2">
406 <td colspan="3" class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
407 <em><%:No network configured on this device%></em>
411 <!-- /network list -->
414 <!-- /device <%=dev:name()%> -->
418 <h2><a id="content" name="content"><%:Associated Stations%></a></h2>
420 <fieldset class="cbi-section">
421 <table class="cbi-section-table" style="margin:10px" id="iw-assoclist">
422 <tr class="cbi-section-table-titles">
423 <th class="cbi-section-table-cell"></th>
424 <th class="cbi-section-table-cell"><%:SSID%></th>
425 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
426 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
427 <th class="cbi-section-table-cell"><%:Signal%></th>
428 <th class="cbi-section-table-cell"><%:Noise%></th>
429 <th class="cbi-section-table-cell"><%:RX Rate%></th>
430 <th class="cbi-section-table-cell"><%:TX Rate%></th>
432 <tr class="cbi-section-table-row cbi-rowstyle-2">
433 <td class="cbi-value-field" colspan="8">
434 <em><%:Collecting data...%></em>