2 LuCI - Network model - Wireless extension
4 Copyright 2009 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
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
20 local pairs, i18n, uci = pairs, luci.i18n, luci.model.uci
22 local iwi = require "iwinfo"
23 local utl = require "luci.util"
24 local uct = require "luci.model.uci.bind"
26 module "luci.model.network.wireless"
28 local ub = uct.bind("wireless")
31 function init(self, cursor)
32 cursor:unload("wireless")
33 cursor:load("wireless")
36 st = uci.cursor_state()
41 ub.uci:foreach("wireless", "wifi-iface",
45 local device = s.device or "wlan0"
46 local state = st:get_all("wireless", s['.name'])
47 local name = device .. ".network" .. count
52 rawname = state and state.ifname or name,
66 local function _mode(m)
67 if m == "ap" then m = "AP"
68 elseif m == "sta" then m = "Client"
69 elseif m == "adhoc" then m = "Ad-Hoc"
70 elseif m == "mesh" then m = "Mesh"
71 elseif m == "monitor" then m = "Monitor"
72 elseif m == "wds" then m = "WDS"
78 function shortname(self, iface)
79 if iface.dev and iface.dev.wifi then
81 i18n.translate(_mode(iface.dev.wifi.mode)),
82 iface.dev.wifi.ssid or iface.dev.wifi.bssid
83 or i18n.translate("(hidden)")
90 function get_i18n(self, iface)
91 if iface.dev and iface.dev.wifi then
93 i18n.translate("Wireless Network"),
94 i18n.translate(_mode(iface.dev.wifi.mode)),
95 iface.dev.wifi.ssid or iface.dev.wifi.bssid
96 or i18n.translate("(hidden)")
99 return "%s: %q" %{ i18n.translate("Wireless Network"), iface:name() }
103 function rename_network(self, old, new)
105 for i, _ in pairs(ifs) do
106 if ifs[i].network == old then
111 ub.uci:foreach("wireless", "wifi-iface",
113 if s.network == old then
115 ub.uci:set("wireless", s['.name'], "network", new)
117 ub.uci:delete("wireless", s['.name'], "network")
123 function del_network(self, old)
124 return self:rename_network(old, nil)
127 function find_interfaces(self, iflist, brlist)
129 for iface, _ in pairs(ifs) do
130 iflist[iface] = ifs[iface]
134 function ignore_interface(self, iface)
135 if ifs and ifs[iface] then
138 return iwi.type(iface) and true or false
142 function add_interface(self, net, iface)
143 if ifs and ifs[iface] and ifs[iface].sid then
144 ub.uci:set("wireless", ifs[iface].sid, "network", net:name())
145 ifs[iface].network = net:name()
152 function del_interface(self, net, iface)
153 if ifs and ifs[iface] and ifs[iface].sid then
154 ub.uci:delete("wireless", ifs[iface].sid, "network")