2 LuCI - Lua Configuration Interface
3 Copyright 2008-2009 Steven Barth <steven@midlink.org>
4 Copyright 2008-2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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_state()
22 function guess_wifi_hw(ifname)
23 local name, idx = ifname:match("^([a-z]+)(%d+)")
28 local name = "Broadcom 802.11 Wireless Controller"
31 local fd = nixio.open("/proc/bus/pci/devices", "r")
34 for ln in fd:linesource() do
35 if ln:match("wl$") then
37 local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
39 "Broadcom BCM%04x 802.11 Wireless Controller",
55 elseif name == "ath" or name == "wifi" then
56 return "Atheros 802.11 Wireless Controller"
59 elseif name == "ra" then
60 return "RaLink 802.11 Wireless Controller"
63 elseif name == "eth" then
64 return "Prism 802.11 Wireless Controller"
68 return "Generic 802.11 Wireless Controller"
72 function guess_wifi_signal(info)
73 local snr = -1 * ((info.noise or 0) - (info.signal or 0))
74 local scale = math.floor(snr / 5)
77 if not info.bssid or info.bssid == "00:00:00:00:00:00" then
78 icon = resource .. "/icons/signal-none.png"
80 icon = resource .. "/icons/signal-0.png"
82 icon = resource .. "/icons/signal-0-25.png"
84 icon = resource .. "/icons/signal-25-50.png"
86 icon = resource .. "/icons/signal-50-75.png"
88 icon = resource .. "/icons/signal-75-100.png"
94 function percent_wifi_signal(info)
95 local qc = info.quality or 0
96 local qm = info.quality_max or 0
98 if info.bssid and qc > 0 and qm > 0 then
99 return math.floor((100 / qm) * qc)
105 function find_wifi_devices()
107 uci:foreach("wireless", "wifi-device",
109 local dev = s['.name']
111 devs[dev] = { active = 0, networks = { } }
113 uci:foreach("wireless", "wifi-iface",
115 if s.device == dev then
116 if s.up == "1" then act = act + 1 end
117 devs[dev].networks[#devs[dev].networks+1] = {
118 active = (s.up == "1"),
120 info = sys.wifi.getiwinfo(s.ifname or s.device)
125 devs[dev].hwname = guess_wifi_hw(dev)
126 devs[dev].active = (act > 0)
132 function find_wifi_frequency(state)
133 if state and state.active and state.networks[1] and state.networks[1].info then
134 return string.format("%d (%.03f GHz)",
135 state.networks[1].info.channel,
136 state.networks[1].info.frequency / 1000);
143 local devices = find_wifi_devices()
145 sys.net.arptable(function(e) arpcache[e["HW address"]] = e["IP address"] end)
150 <h2><a id="content" name="content"><%:a_s_iw_overview Wireless Overview%></a></h2>
152 <div class="cbi-map">
154 <% for dev, state in utl.kspairs(devices) do %>
155 <!-- device <%=dev%> -->
156 <fieldset class="cbi-section">
157 <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
158 <!-- physical device -->
160 <td style="width:34px"><img src="<%=resource%>/icons/wifi<%=state.active and "" or "_disabled"%>.png" style="float:left; margin-right:10px" /></td>
161 <td colspan="2" style="text-align:left">
162 <big><strong><%=state.hwname%> (<%=dev%>)</strong></big><br />
163 <% if state.networks[1] and state.networks[1].info then %>
164 <strong>Channel:</strong> <%=find_wifi_frequency(state)%> |
165 <strong>Bitrate:</strong> <%=state.networks[1].info.bitrate and (state.networks[1].info.bitrate / 1000) .. " Mb/s" or "n/a"%>
168 <td style="width:40px">
169 <a href="<%=luci.dispatcher.build_url("admin/network/wireless_join?device="..dev)%>"><img style="border:none" src="<%=resource%>/cbi/find.gif" alt="Find and join network" title="Find and join network" /></a>
170 <a href="#"><img style="border:none" src="<%=resource%>/cbi/add.gif" alt="Provide new network" title="Provide new network" /></a>
173 <!-- /physical device -->
175 <!-- network list -->
176 <% if #state.networks > 0 then %>
177 <% for i, net in ipairs(state.networks) do %>
178 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
180 <td class="cbi-value-field" style="width:16px; padding:3px">
181 <img src="<%=guess_wifi_signal(net.info)%>" title="Signal: <%=net.info.signal or 0%> dBm / Noise: <%=net.info.noise or 0%> dBm" /><br />
182 <small><%=percent_wifi_signal(net.info)%>%</small>
184 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
185 <strong>SSID:</strong> <%=utl.pcdata(net.info.ssid)%> |
186 <strong>Mode:</strong> <%=net.info.mode%><br />
187 <strong>BSSID:</strong> <%=net.info.bssid%> |
188 <strong>Encryption:</strong> <%=net.info.enctype or "None"%>
190 <td class="cbi-value-field" style="width:40px">
191 <a href="<%=REQUEST_URI%>/<%=dev%>"><img style="border:none" src="<%=resource%>/cbi/edit.gif" alt="Edit this network" title="Edit this network" /></a>
192 <a href="#"><img style="border:none" src="<%=resource%>/cbi/remove.gif" alt="Delete this network" title="Delete this network" /></a>
197 <tr class="cbi-section-table-row cbi-rowstyle-2">
199 <td colspan="3" class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px">
200 <em>(No network configured on this device)</em>
204 <!-- /network list -->
207 <!-- /device <%=dev%> -->
213 <h2><a id="content" name="content"><%:a_s_iw_overview2 Associated Stations%></a></h2>
215 <fieldset class="cbi-section">
216 <table class="cbi-section-table" style="margin:10px; width:50%">
217 <tr class="cbi-section-table-titles">
218 <th class="cbi-section-table-cell"></th>
219 <th class="cbi-section-table-cell">SSID</th>
220 <th class="cbi-section-table-cell">MAC</th>
221 <th class="cbi-section-table-cell">Address</th>
222 <th class="cbi-section-table-cell">Signal</th>
223 <th class="cbi-section-table-cell">Noise</th>
226 <% local count = -1 %>
227 <% for dev, state in utl.kspairs(devices) do %>
228 <% for _, net in ipairs(state.networks) do %>
229 <% for mac, info in utl.kspairs(net.info.assoclist) do info.bssid = mac; count = count + 1 %>
230 <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + (count % 2)%>">
231 <td class="cbi-value-field"><img src="<%=guess_wifi_signal(info)%>" title="Signal: <%=info.signal%> dBm / Noise: <%=info.noise%> dBm" /></td>
232 <td class="cbi-value-field"><%=net.info.ssid%></td>
233 <td class="cbi-value-field"><%=mac%></td>
234 <td class="cbi-value-field"><%=arpcache[mac] or "n/a"%></td>
235 <td class="cbi-value-field"><%=info.signal%> dBm</td>
236 <td class="cbi-value-field"><%=info.noise%> dBm</td>
241 <% if count <= 0 then %>
242 <tr class="cbi-section-table-row cbi-rowstyle-2">
243 <td class="cbi-value-field" colspan="6">
244 <em>No information available</em>