2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2010 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
18 local sys = require "luci.sys"
19 local utl = require "luci.util"
20 local uci = require "luci.model.uci".cursor()
21 local ntm = require "luci.model.network"
23 local has_iwinfo = pcall(require, "iwinfo")
27 function guess_wifi_hw(ifname)
29 local name, idx = ifname:match("^([a-z]+)(%d+)")
33 local iw = luci.sys.wifi.getiwinfo(ifname)
34 local bl = iw.hwmodelist
35 if bl and next(bl) then
36 if bl.a then bands = bands .. "a" end
37 if bl.b then bands = bands .. "b" end
38 if bl.g then bands = bands .. "g" end
39 if bl.n then bands = bands .. "n" end
45 local name = "Broadcom 802.11%s Wireless Controller" % bands
48 local fd = nixio.open("/proc/bus/pci/devices", "r")
51 for ln in fd:linesource() do
52 if ln:match("wl$") then
54 local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
56 "Broadcom BCM%04x 802.11 Wireless Controller",
72 elseif name == "ath" or name == "wifi" then
73 return "Atheros 802.11%s Wireless Controller" % bands
76 elseif name == "ra" then
77 return "RaLink 802.11%s Wireless Controller" % bands
80 elseif name == "eth" then
81 return "Prism 802.11%s Wireless Controller" % bands
85 return "Generic 802.11%s Wireless Controller" % bands
89 local devices = ntm:get_wifidevs()
91 sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end)
97 for _, dev in ipairs(devices) do
99 for _, net in ipairs(dev:get_wifinets()) do
100 netlist[#netlist+1] = net:ifname()
101 netdevs[net:ifname()] = dev:name()
108 <% if not has_iwinfo then %>
109 <div class="errorbox">
110 <strong><%:Package libiwinfo required!%></strong><br />
111 <%_The <em>libiwinfo</em> package is not installed. You must install this component for working wireless configuration!%>
115 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
116 <script type="text/javascript">//<![CDATA[
117 var iwxhr = new XHR();
118 var wifidevs = <%=luci.http.write_json(netdevs)%>;
119 var arptable = <%=luci.http.write_json(arpcache)%>;
121 var update_status = function() {
122 iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null,
127 var assoctable = document.getElementById('iw-assoclist');
129 while (assoctable.rows.length > 1)
130 assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]);
134 for( var i = 0; i < st.length; i++ )
137 var is_assoc = (iw.bssid && iw.channel);
138 var p = (100 / iw.quality_max * iw.quality);
139 var q = is_assoc ? p : -1;
143 icon = "<%=resource%>/icons/signal-none.png";
145 icon = "<%=resource%>/icons/signal-0.png";
147 icon = "<%=resource%>/icons/signal-0-25.png";
149 icon = "<%=resource%>/icons/signal-25-50.png";
151 icon = "<%=resource%>/icons/signal-50-75.png";
153 icon = "<%=resource%>/icons/signal-75-100.png";
155 if (!devup[wifidevs[iw.id]])
156 devup[wifidevs[iw.id]] = is_assoc;
158 var sig = document.getElementById(iw.id + '-iw-signal');
160 sig.innerHTML = String.format(
161 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' +
162 '<small>%d%%</small>', icon, iw.signal, iw.noise, p
165 var info = document.getElementById(iw.id + '-iw-status');
169 info.innerHTML = String.format(
170 '<strong><%:SSID%>:</strong> %h | ' +
171 '<strong><%:Mode%>:</strong> %s<br />' +
172 '<strong><%:BSSID%>:</strong> %s | ' +
173 '<strong><%:Encryption%>:</strong> %s',
174 iw.ssid, iw.mode, iw.bssid,
175 iw.encryption ? iw.encryption.description : '<%:None%>'
178 info.innerHTML = String.format(
179 '<strong><%:SSID%>:</strong> %h | ' +
180 '<strong><%:Mode%>:</strong> %s<br />' +
181 '<em><%:Wireless is disabled or not associated%></em>',
182 iw.ssid || '?', iw.mode
186 var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
190 dev.innerHTML = String.format(
191 '<strong><%:Channel%>:</strong> %s (%s GHz) | ' +
192 '<strong><%:Bitrate%>:</strong> %s Mb/s',
193 iw.channel ? iw.channel : '?',
194 iw.frequency ? iw.frequency / 1000 : '?',
195 iw.bitrate ? iw.bitrate / 1000 : '?'
204 for( var bssid in iw.assoclist )
206 assoclist.push(iw.assoclist[bssid]);
207 assoclist[assoclist.length-1].bssid = bssid;
210 assoclist.sort(function(a, b) { a.bssid < b.bssid });
212 for( var j = 0; j < assoclist.length; j++ )
214 var tr = document.createElement('tr');
215 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((j % 2) + (i % 2));
218 var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5;
220 icon = "<%=resource%>/icons/signal-0.png";
222 icon = "<%=resource%>/icons/signal-0-25.png";
224 icon = "<%=resource%>/icons/signal-25-50.png";
226 icon = "<%=resource%>/icons/signal-50-75.png";
228 icon = "<%=resource%>/icons/signal-75-100.png";
230 tr.innerHTML = String.format(
231 '<td class="cbi-value-field">' +
232 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' +
234 '<td class="cbi-value-field">%s</td>' +
235 '<td class="cbi-value-field">%s</td>' +
236 '<td class="cbi-value-field">%s</td>' +
237 '<td class="cbi-value-field">%d dBm</td>' +
238 '<td class="cbi-value-field">%d dBm</td>',
240 assoclist[j].signal, assoclist[j].noise,
241 iw.ssid ? iw.ssid : '?',
243 arptable[assoclist[j].bssid]
244 ? arptable[assoclist[j].bssid] : '?',
245 assoclist[j].signal, assoclist[j].noise
248 assoctable.rows[0].parentNode.appendChild(tr);
253 if (assoctable && assoctable.rows.length == 1)
255 var tr = document.createElement('tr');
256 tr.className = 'cbi-section-table-row';
258 tr.innerHTML = '<td class="cbi-value-field" colspan="6"><br /><em><%:No information available%></em></td>';
260 assoctable.rows[0].parentNode.appendChild(tr);
263 for (var dev in devup)
265 var img = document.getElementById(dev + '-iw-upstate');
267 img.src = '<%=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png';
271 window.setTimeout(update_status, 5000);
279 <h2><a id="content" name="content"><%:Wireless Overview%></a></h2>
281 <div class="cbi-map">
283 <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %>
284 <!-- device <%=dev:name()%> -->
285 <fieldset class="cbi-section">
286 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
287 <!-- physical device -->
289 <td style="width:34px"><img src="<%=resource%>/icons/wifi_big_disabled.png" style="float:left; margin-right:10px" id="<%=dev:name()%>-iw-upstate" /></td>
290 <td colspan="2" style="text-align:left">
291 <big><strong><%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)</strong></big><br />
292 <span id="<%=dev:name()%>-iw-devinfo"></span>
294 <td style="width:40px">
295 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_join")%>?device=<%=dev:name()%>"><img style="border:none" src="<%=resource%>/cbi/find.gif" alt="<%:Find and join network%>" title="<%:Find and join network%>" /></a>
296 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_add")%>?device=<%=dev:name()%>"><img style="border:none" src="<%=resource%>/cbi/add.gif" alt="<%:Provide new network%>" title="<%:Provide new network%>" /></a>
299 <!-- /physical device -->
301 <!-- network list -->
302 <% if #nets > 0 then %>
303 <% for i, net in ipairs(nets) do %>
304 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
306 <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=net:ifname()%>-iw-signal">
307 <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br />
310 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net:ifname()%>-iw-status">
311 <em><%:Collecting data...%></em>
313 <td class="cbi-value-field" style="width:40px">
314 <a href="<%=net:adminlink()%>"><img style="border:none" src="<%=resource%>/cbi/edit.gif" alt="<%:Edit this network%>" title="<%:Edit this network%>" /></a>
315 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_delete", net:ifname())%>" onclick="return confirm('<%:Really delete this wireless network? The deletion cannot be undone!\nYou might loose access to this router if you are connected via this network.%>')"><img style="border:none" src="<%=resource%>/cbi/remove.gif" alt="<%:Delete this network%>" title="<%:Delete this network%>" /></a>
320 <tr class="cbi-section-table-row cbi-rowstyle-2">
322 <td colspan="3" class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
323 <em><%:No network configured on this device%></em>
327 <!-- /network list -->
330 <!-- /device <%=dev:name()%> -->
334 <h2><a id="content" name="content"><%:Associated Stations%></a></h2>
336 <fieldset class="cbi-section">
337 <table class="cbi-section-table" style="margin:10px; width:50%" id="iw-assoclist">
338 <tr class="cbi-section-table-titles">
339 <th class="cbi-section-table-cell"></th>
340 <th class="cbi-section-table-cell"><%:SSID%></th>
341 <th class="cbi-section-table-cell"><%:MAC%></th>
342 <th class="cbi-section-table-cell"><%:Address%></th>
343 <th class="cbi-section-table-cell"><%:Signal%></th>
344 <th class="cbi-section-table-cell"><%:Noise%></th>
346 <tr class="cbi-section-table-row cbi-rowstyle-2">
347 <td class="cbi-value-field" colspan="6">
348 <em><%:Collecting data...%></em>