root/luci/trunk/libs/core/luasrc/model/network/wireless.lua @ 5513

Revision 5513, 3.5 KB (checked in by jow, 4 years ago)

libs/core: i18n fixes for wds mode

  • Property svn:keywords set to Id
Line 
1--[[
2LuCI - Network model - Wireless extension
3
4Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations under the License.
17
18]]--
19
20local pairs, i18n, uci = pairs, luci.i18n, luci.model.uci
21
22local iwi = require "iwinfo"
23local utl = require "luci.util"
24local uct = require "luci.model.uci.bind"
25
26module "luci.model.network.wireless"
27
28local ub = uct.bind("wireless")
29local st, ifs
30
31function init(self, cursor)
32    cursor:unload("wireless")
33    cursor:load("wireless")
34    ub:init(cursor)
35
36    st = uci.cursor_state()
37    ifs = { }
38
39    local count = 0
40       
41    ub.uci:foreach("wireless", "wifi-iface",
42        function(s)
43            count = count + 1
44
45            local device = s.device or "wlan0"
46            local state = st:get_all("wireless", s['.name'])
47            local name = device .. ".network" .. count
48           
49            ifs[name] = {
50                idx      = count,
51                name     = name,
52                rawname  = state and state.ifname or name,
53                flags    = { },
54                ipaddrs  = { },
55                ip6addrs = { },
56
57                type     = "wifi",
58                network  = s.network,
59                handler  = self,
60                wifi     = state or s,
61                sid      = s['.name']
62            }
63        end)
64end
65
66local 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"
73    end
74
75    return m or "Client"
76end
77
78function shortname(self, iface)
79    if iface.dev and iface.dev.wifi then
80        return "%s %q" %{
81            i18n.translate(_mode(iface.dev.wifi.mode)),
82            iface.dev.wifi.ssid or iface.dev.wifi.bssid
83                or i18n.translate("(hidden)")
84        }
85    else
86        return iface:name()
87    end
88end
89
90function get_i18n(self, iface)
91    if iface.dev and iface.dev.wifi then
92        return "%s: %s %q" %{
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)")
97        }
98    else
99        return "%s: %q" %{ i18n.translate("Wireless Network"), iface:name() }
100    end
101end
102
103function rename_network(self, old, new)
104    local i
105    for i, _ in pairs(ifs) do
106        if ifs[i].network == old then
107            ifs[i].network = new
108        end
109    end
110
111    ub.uci:foreach("wireless", "wifi-iface",
112        function(s)
113            if s.network == old then
114                if new then 
115                    ub.uci:set("wireless", s['.name'], "network", new)
116                else
117                    ub.uci:delete("wireless", s['.name'], "network")
118                end
119            end
120        end)
121end
122
123function del_network(self, old)
124    return self:rename_network(old, nil)
125end
126
127function find_interfaces(self, iflist, brlist)
128    local iface
129    for iface, _ in pairs(ifs) do
130        iflist[iface] = ifs[iface]
131    end
132end
133
134function ignore_interface(self, iface)
135    if ifs and ifs[iface] then
136        return false
137    else
138        return iwi.type(iface) and true or false
139    end
140end
141
142function 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()
146        return true
147    end
148
149    return false
150end
151
152function 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")
155        --return true
156    end
157
158    return false
159end
160
161return _M
162
Note: See TracBrowser for help on using the browser.