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
"Unkown 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 <strong>Channel:
</strong> <%=find_wifi_frequency(state)%
> |
164 <strong>Bitrate:
</strong> <%=(state and state.networks[
1]) and (state.networks[
1].info.bitrate /
1000) ..
" Mb/s" or
"n/a"%
>
166 <td style=
"width:40px">
167 <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>
168 <a href=
"#"><img style=
"border:none" src=
"<%=resource%>/cbi/add.gif" alt=
"Provide new network" title=
"Provide new network" /></a>
171 <!-- /physical device -->
173 <!-- network list -->
174 <% if #state.networks
> 0 then %
>
175 <% for i, net in ipairs(state.networks) do %
>
176 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>">
178 <td class=
"cbi-value-field" style=
"width:16px; padding:3px">
179 <img src=
"<%=guess_wifi_signal(net.info)%>" title=
"Signal: <%=net.info.signal%> dBm / Noise: <%=net.info.noise%> dBm" /><br />
180 <small><%=percent_wifi_signal(net.info)%
>%
</small>
182 <td class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
183 <strong>SSID:
</strong> <%=utl.pcdata(net.info.ssid)%
> |
184 <strong>Mode:
</strong> <%=net.info.mode%
><br />
185 <strong>BSSID:
</strong> <%=net.info.bssid%
> |
186 <strong>Encryption:
</strong> <%=net.info.enctype%
>
188 <td class=
"cbi-value-field" style=
"width:40px">
189 <a href=
"<%=REQUEST_URI%>/<%=dev%>"><img style=
"border:none" src=
"<%=resource%>/cbi/edit.gif" alt=
"Edit this network" title=
"Edit this network" /></a>
190 <a href=
"#"><img style=
"border:none" src=
"<%=resource%>/cbi/remove.gif" alt=
"Delete this network" title=
"Delete this network" /></a>
195 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
197 <td colspan=
"3" class=
"cbi-value-field" style=
"vertical-align:middle; text-align:left; padding:3px">
198 <em>(No network configured on this device)
</em>
202 <!-- /network list -->
205 <!-- /device <%=dev%> -->
211 <h2><a id=
"content" name=
"content"><%:a_s_iw_overview2 Associated Stations%
></a></h2>
213 <fieldset class=
"cbi-section">
214 <table class=
"cbi-section-table" style=
"margin:10px; width:50%">
215 <tr class=
"cbi-section-table-titles">
216 <th class=
"cbi-section-table-cell"></th>
217 <th class=
"cbi-section-table-cell">SSID
</th>
218 <th class=
"cbi-section-table-cell">MAC
</th>
219 <th class=
"cbi-section-table-cell">Address
</th>
220 <th class=
"cbi-section-table-cell">Signal
</th>
221 <th class=
"cbi-section-table-cell">Noise
</th>
224 <% local count = -
1 %
>
225 <% for dev, state in utl.kspairs(devices) do %
>
226 <% for _, net in ipairs(state.networks) do %
>
227 <% for mac, info in utl.kspairs(net.info.assoclist) do info.bssid = mac; count = count +
1 %
>
228 <tr class=
"cbi-section-table-row cbi-rowstyle-<%=1 + (count % 2)%>">
229 <td class=
"cbi-value-field"><img src=
"<%=guess_wifi_signal(info)%>" title=
"Signal: <%=info.signal%> dBm / Noise: <%=info.noise%> dBm" /></td>
230 <td class=
"cbi-value-field"><%=net.info.ssid%
></td>
231 <td class=
"cbi-value-field"><%=mac%
></td>
232 <td class=
"cbi-value-field"><%=arpcache[mac] or
"n/a"%
></td>
233 <td class=
"cbi-value-field"><%=info.signal%
> dBm
</td>
234 <td class=
"cbi-value-field"><%=info.noise%
> dBm
</td>
239 <% if count <=
0 then %
>
240 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
241 <td class=
"cbi-value-field" colspan=
"6">
242 <em>No information available
</em>