1 -- Copyright 2018 Jo-Philipp Wich <jo@mein.io>
2 -- Licensed to the public under the Apache License 2.0.
4 local fs = require "nixio.fs"
5 local utl = require "luci.util"
6 local tpl = require "luci.template"
7 local ntm = require "luci.model.network"
9 local has_iwinfo = pcall(require, "iwinfo")
11 function guess_wifi_hw(dev)
13 local ifname = dev:name()
14 local name, idx = ifname:match("^([a-z]+)(%d+)")
18 local bl = dev.iwinfo.hwmodelist
19 if bl and next(bl) then
20 if bl.a then bands = bands .. "a" end
21 if bl.b then bands = bands .. "b" end
22 if bl.g then bands = bands .. "g" end
23 if bl.n then bands = bands .. "n" end
24 if bl.ac then bands = bands .. "ac" end
27 local hw = dev.iwinfo.hardware_name
29 return "%s 802.11%s" %{ hw, bands }
35 local name = translatef("Broadcom 802.11%s Wireless Controller", bands)
38 local fd = nixio.open("/proc/bus/pci/devices", "r")
41 for ln in fd:linesource() do
42 if ln:match("wl$") then
44 local version = ln:match("^%S+%s+%S%S%S%S([0-9a-f]+)")
46 "Broadcom BCM%04x 802.11 Wireless Controller",
63 return translatef("Generic 802.11%s Wireless Controller", bands)
68 m = Map("wireless", translate("Wireless Overview"))
72 if not has_iwinfo then
73 s = m:section(NamedSection, "__warning__")
75 function s.render(self)
77 <div class="alert-message warning">
78 <h4><%:Package libiwinfo required!%></h4>
79 <p><%_The <em>libiwinfo-lua</em> package is not installed. You must install this component for working wireless configuration!%></p>
86 for _, dev in ipairs(ntm:get_wifidevs()) do
87 s = m:section(TypedSection)
88 s.template = "admin_network/wifi_overview"
89 s.wnets = dev:get_wifinets()
91 s.hw = guess_wifi_hw(dev)
93 function s.cfgsections(self)
94 local _, net, sl = nil, nil, { }
95 for _, net in ipairs(self.wnets) do
96 sl[#sl+1] = net:name()
97 self.wnets[net:name()] = net
102 o = s:option(Value, "__disable__")
104 function o.cfgvalue(self, sid)
105 local wnet = self.section.wnets[sid]
106 local wdev = wnet:get_device()
108 return ((wnet and wnet:get("disabled") == "1") or
109 (wdev and wdev:get("disabled") == "1")) and "1" or "0"
112 function o.write(self, sid, value)
113 local wnet = self.section.wnets[sid]
114 local wdev = wnet:get_device()
117 wnet:set("disabled", nil)
118 wdev:set("disabled", nil)
120 wnet:set("disabled", "1")
127 o = s:option(Value, "__delete__")
129 function o.write(self, sid, value)
130 local wnet = self.section.wnets[sid]
131 local nets = wnet:get_networks()
133 ntm:del_wifinet(wnet:id())
136 for _, net in ipairs(nets) do
137 if net:is_empty() then
138 ntm:del_network(net:name())
144 s = m:section(NamedSection, "__assoclist__")
146 function s.render(self, sid)
148 <h2><%:Associated Stations%></h2>