2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2011 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(ifname)
28 local name, idx = ifname:match("^([a-z]+)(%d+)")
32 local iw = luci.sys.wifi.getiwinfo(ifname)
33 local bl = iw.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
44 local name = translatef("Broadcom 802.11%s Wireless Controller", bands)
47 local fd = nixio.open("/proc/bus/pci/devices", "r")
50 for ln in fd:linesource() do
51 if ln:match("wl$") then
53 local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
55 "Broadcom BCM%04x 802.11 Wireless Controller",
71 elseif name == "ath" or name == "wifi" then
72 return translatef("Atheros 802.11%s Wireless Controller", bands)
75 elseif name == "ra" then
76 return translatef("RaLink 802.11%s Wireless Controller", bands)
79 elseif name == "eth" then
80 return translate("Hermes 802.11b Wireless Controller")
83 elseif name == "wlan" and fs.isdirectory("/proc/net/hostap/" .. ifname) then
84 return translate("Prism2/2.5/3 802.11b Wireless Controller")
88 return translatef("Generic 802.11%s Wireless Controller", bands)
92 local devices = ntm:get_wifidevs()
94 sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end)
100 for _, dev in ipairs(devices) do
102 for _, net in ipairs(dev:get_wifinets()) do
103 netlist[#netlist+1] = net:id()
104 netdevs[net:id()] = dev:name()
111 <% if not has_iwinfo then %>
112 <div class="errorbox">
113 <strong><%:Package libiwinfo required!%></strong><br />
114 <%_The <em>libiwinfo-lua</em> package is not installed. You must install this component for working wireless configuration!%>
118 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
119 <script type="text/javascript">//<![CDATA[
120 var wifidevs = <%=luci.http.write_json(netdevs)%>;
121 var arptable = <%=luci.http.write_json(arpcache)%>;
123 var is_reconnecting = false;
126 return s.replace(/ /g, ' ');
129 function wifi_shutdown(id, toggle) {
130 var reconnect = (toggle.getAttribute('active') == 'false');
132 if (!reconnect && !confirm(String.format('<%:Really shutdown network ?\nYou might lose access to this device if you are connected via this interface.%>')))
135 is_reconnecting = true;
137 var s = document.getElementById('iw-rc-status');
140 s.parentNode.style.display = 'block';
141 s.innerHTML = '<%:Waiting for changes to be applied...%>';
144 for (var net in wifidevs)
146 var st = document.getElementById(net + '-iw-status');
148 st.innerHTML = '<em><%:Wireless is restarting...%></em>';
151 XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
156 s.innerHTML = reconnect
157 ? '<%:Wireless restarted%>'
158 : '<%:Wireless shut down%>';
160 window.setTimeout(function() {
161 s.parentNode.style.display = 'none';
162 is_reconnecting = false;
169 XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null,
174 var assoctable = document.getElementById('iw-assoclist');
176 while (assoctable.rows.length > 1)
177 assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]);
182 for( var i = 0; i < st.length; i++ )
185 var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel);
187 var q = is_assoc ? p : -1;
191 icon = "<%=resource%>/icons/signal-none.png";
193 icon = "<%=resource%>/icons/signal-0.png";
195 icon = "<%=resource%>/icons/signal-0-25.png";
197 icon = "<%=resource%>/icons/signal-25-50.png";
199 icon = "<%=resource%>/icons/signal-50-75.png";
201 icon = "<%=resource%>/icons/signal-75-100.png";
203 if (!devup[wifidevs[iw.id]])
204 devup[wifidevs[iw.id]] = is_assoc;
206 var sig = document.getElementById(iw.id + '-iw-signal');
208 sig.innerHTML = String.format(
209 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" /><br />' +
210 '<small>%d%%</small>', icon, iw.signal, iw.noise, p
213 var toggle = document.getElementById(iw.id + '-iw-toggle');
218 toggle.className = 'cbi-button cbi-button-reset';
219 toggle.value = '<%:Disable%>';
220 toggle.title = '<%:Shutdown this network%>';
224 toggle.className = 'cbi-button cbi-button-reload';
225 toggle.value = '<%:Enable%>';
226 toggle.title = '<%:Activate this network%>';
229 toggle.setAttribute('active', is_assoc);
232 var info = document.getElementById(iw.id + '-iw-status');
236 info.innerHTML = String.format(
237 '<strong><%:SSID%>:</strong> %h | ' +
238 '<strong><%:Mode%>:</strong> %s<br />' +
239 '<strong><%:BSSID%>:</strong> %s | ' +
240 '<strong><%:Encryption%>:</strong> %s',
241 iw.ssid, iw.mode, iw.bssid,
242 iw.encryption ? iw.encryption : '<%:None%>'
245 info.innerHTML = String.format(
246 '<strong><%:SSID%>:</strong> %h | ' +
247 '<strong><%:Mode%>:</strong> %s<br />' +
249 iw.ssid || '?', iw.mode,
251 ? '<em><%:Wireless is restarting...%></em>'
252 : '<em><%:Wireless is disabled or not associated%></em>'
256 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
260 dev.innerHTML = String.format(
261 '<strong><%:Channel%>:</strong> %s (%s <%:GHz%>) | ' +
262 '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%>',
263 iw.channel ? iw.channel : '?',
264 iw.frequency ? iw.frequency : '?',
265 iw.bitrate ? iw.bitrate : '?'
274 for( var bssid in iw.assoclist )
276 assoclist.push(iw.assoclist[bssid]);
277 assoclist[assoclist.length-1].bssid = bssid;
280 assoclist.sort(function(a, b) { a.bssid < b.bssid });
282 for( var j = 0; j < assoclist.length; j++ )
284 var tr = assoctable.insertRow(-1);
285 tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle;
288 var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5;
290 icon = "<%=resource%>/icons/signal-0.png";
292 icon = "<%=resource%>/icons/signal-0-25.png";
294 icon = "<%=resource%>/icons/signal-25-50.png";
296 icon = "<%=resource%>/icons/signal-50-75.png";
298 icon = "<%=resource%>/icons/signal-75-100.png";
300 tr.insertCell(-1).innerHTML = String.format(
301 '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />',
302 icon, assoclist[j].signal, assoclist[j].noise
305 tr.insertCell(-1).innerHTML = nowrap(String.format('%h', iw.ssid ? iw.ssid : '?'));
306 tr.insertCell(-1).innerHTML = assoclist[j].bssid;
308 tr.insertCell(-1).innerHTML = arptable[assoclist[j].bssid]
309 ? arptable[assoclist[j].bssid] : '?';
311 tr.insertCell(-1).innerHTML = nowrap(String.format('%d <%:dBm%>', assoclist[j].signal));
312 tr.insertCell(-1).innerHTML = nowrap(String.format('%d <%:dBm%>', assoclist[j].noise));
314 tr.insertCell(-1).innerHTML = nowrap((assoclist[j].rx_mcs > -1)
315 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[j].rx_rate / 1000, assoclist[j].rx_mcs, assoclist[j].rx_40mhz ? 40 : 20)
316 : String.format('%.1f <%:Mbit/s%>', assoclist[j].rx_rate / 1000)
319 tr.insertCell(-1).innerHTML = nowrap((assoclist[j].tx_mcs > -1)
320 ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[j].tx_rate / 1000, assoclist[j].tx_mcs, assoclist[j].tx_40mhz ? 40 : 20)
321 : String.format('%.1f <%:Mbit/s%>', assoclist[j].tx_rate / 1000)
324 rowstyle = (rowstyle == 1) ? 2 : 1;
329 if (assoctable && assoctable.rows.length == 1)
331 var tr = assoctable.insertRow(-1);
332 tr.className = 'cbi-section-table-row';
334 var td = tr.insertCell(-1);
336 td.innerHTML = '<br /><em><%:No information available%></em>';
339 for (var dev in devup)
341 var img = document.getElementById(dev + '-iw-upstate');
343 img.src = '<%=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
350 <h2><a id="content" name="content"><%:Wireless Overview%></a></h2>
352 <fieldset class="cbi-section" style="display:none">
353 <legend><%:Reconnecting interface%></legend>
354 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
355 <span id="iw-rc-status"><%:Waiting for changes to be applied...%></span>
358 <div class="cbi-map">
360 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %>
361 <!-- device <%=dev:name()%> -->
362 <fieldset class="cbi-section">
363 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
364 <!-- physical device -->
366 <td style="width:34px"><img src="<%=resource%>/icons/wifi_big_disabled.png" style="float:left; margin-right:10px" id="<%=dev:name()%>-iw-upstate" /></td>
367 <td colspan="2" style="text-align:left">
368 <big><strong><%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)</strong></big><br />
369 <span id="<%=dev:name()%>-iw-devinfo"></span>
371 <td style="width:310px;text-align:right">
372 <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%>" />
373 <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%>" />
376 <!-- /physical device -->
378 <!-- network list -->
379 <% if #nets > 0 then %>
380 <% for i, net in ipairs(nets) do %>
381 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
383 <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=net:id()%>-iw-signal">
384 <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br />
387 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net:id()%>-iw-status">
388 <em><%:Collecting data...%></em>
390 <td class="cbi-value-field" style="width:310px;text-align:right">
391 <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%>" />
392 <input type="button" class="cbi-button cbi-button-edit" style="width:100px" onclick="location.href='<%=net:adminlink()%>'" title="<%:Edit this network%>" value="<%:Edit%>" />
393 <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%>" />
398 <tr class="cbi-section-table-row cbi-rowstyle-2">
400 <td colspan="3" class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
401 <em><%:No network configured on this device%></em>
405 <!-- /network list -->
408 <!-- /device <%=dev:name()%> -->
412 <h2><a id="content" name="content"><%:Associated Stations%></a></h2>
414 <fieldset class="cbi-section">
415 <table class="cbi-section-table" style="margin:10px" id="iw-assoclist">
416 <tr class="cbi-section-table-titles">
417 <th class="cbi-section-table-cell"></th>
418 <th class="cbi-section-table-cell"><%:SSID%></th>
419 <th class="cbi-section-table-cell"><%:MAC-Address%></th>
420 <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
421 <th class="cbi-section-table-cell"><%:Signal%></th>
422 <th class="cbi-section-table-cell"><%:Noise%></th>
423 <th class="cbi-section-table-cell"><%:RX Rate%></th>
424 <th class="cbi-section-table-cell"><%:TX Rate%></th>
426 <tr class="cbi-section-table-row cbi-rowstyle-2">
427 <td class="cbi-value-field" colspan="8">
428 <em><%:Collecting data...%></em>