luci-mod-admin-full: restrict DSL xfer_mode and line_mode options to VDSL modems
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / network.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
3 -- Licensed to the public under the Apache License 2.0.
4
5 local fs = require "nixio.fs"
6 local json = require "luci.jsonc"
7
8 m = Map("network", translate("Interfaces"))
9 m.pageaction = false
10 m:section(SimpleSection).template = "admin_network/iface_overview"
11
12 if fs.access("/etc/init.d/dsl_control") then
13         local ok, boarddata = pcall(json.parse, fs.readfile("/etc/board.json"))
14         local modemtype = (ok == true)
15                 and (type(boarddata) == "table")
16                 and (type(boarddata.dsl) == "table")
17                 and (type(boarddata.dsl.modem) == "table")
18                 and boarddata.dsl.modem.type
19
20         dsl = m:section(TypedSection, "dsl", translate("DSL"))
21         dsl.anonymous = true
22
23         annex = dsl:option(ListValue, "annex", translate("Annex"))
24         annex:value("a", translate("Annex A + L + M (all)"))
25         annex:value("b", translate("Annex B (all)"))
26         annex:value("j", translate("Annex J (all)"))
27         annex:value("m", translate("Annex M (all)"))
28         annex:value("bdmt", translate("Annex B G.992.1"))
29         annex:value("b2", translate("Annex B G.992.3"))
30         annex:value("b2p", translate("Annex B G.992.5"))
31         annex:value("at1", translate("ANSI T1.413"))
32         annex:value("admt", translate("Annex A G.992.1"))
33         annex:value("alite", translate("Annex A G.992.2"))
34         annex:value("a2", translate("Annex A G.992.3"))
35         annex:value("a2p", translate("Annex A G.992.5"))
36         annex:value("l", translate("Annex L G.992.3 POTS 1"))
37         annex:value("m2", translate("Annex M G.992.3"))
38         annex:value("m2p", translate("Annex M G.992.5"))
39
40         tone = dsl:option(ListValue, "tone", translate("Tone"))
41         tone:value("", translate("auto"))
42         tone:value("a", translate("A43C + J43 + A43"))
43         tone:value("av", translate("A43C + J43 + A43 + V43"))
44         tone:value("b", translate("B43 + B43C"))
45         tone:value("bv", translate("B43 + B43C + V43"))
46
47         if modemtype == "vdsl" then
48                 xfer_mode = dsl:option(ListValue, "xfer_mode", translate("Encapsulation mode"))
49                 xfer_mode:value("", translate("auto"))
50                 xfer_mode:value("atm", translate("ATM (Asynchronous Transfer Mode)"))
51                 xfer_mode:value("ptm", translate("PTM/EFM (Packet Transfer Mode)"))
52
53                 line_mode = dsl:option(ListValue, "line_mode", translate("DSL line mode"))
54                 line_mode:value("", translate("auto"))
55                 line_mode:value("adsl", translate("ADSL"))
56                 line_mode:value("vdsl", translate("VDSL"))
57         end
58
59         firmware = dsl:option(Value, "firmware", translate("Firmware File"))
60
61         m.pageaction = true
62 end
63
64 -- Show ATM bridge section if we have the capabilities
65 if fs.access("/usr/sbin/br2684ctl") then
66         atm = m:section(TypedSection, "atm-bridge", translate("ATM Bridges"),
67                 translate("ATM bridges expose encapsulated ethernet in AAL5 " ..
68                         "connections as virtual Linux network interfaces which can " ..
69                         "be used in conjunction with DHCP or PPP to dial into the " ..
70                         "provider network."))
71
72         atm.addremove = true
73         atm.anonymous = true
74
75         atm.create = function(self, section)
76                 local sid = TypedSection.create(self, section)
77                 local max_unit = -1
78
79                 m.uci:foreach("network", "atm-bridge",
80                         function(s)
81                                 local u = tonumber(s.unit)
82                                 if u ~= nil and u > max_unit then
83                                         max_unit = u
84                                 end
85                         end)
86
87                 m.uci:set("network", sid, "unit", max_unit + 1)
88                 m.uci:set("network", sid, "atmdev", 0)
89                 m.uci:set("network", sid, "encaps", "llc")
90                 m.uci:set("network", sid, "payload", "bridged")
91                 m.uci:set("network", sid, "vci", 35)
92                 m.uci:set("network", sid, "vpi", 8)
93
94                 return sid
95         end
96
97         atm:tab("general", translate("General Setup"))
98         atm:tab("advanced", translate("Advanced Settings"))
99
100         vci    = atm:taboption("general", Value, "vci", translate("ATM Virtual Channel Identifier (VCI)"))
101         vpi    = atm:taboption("general", Value, "vpi", translate("ATM Virtual Path Identifier (VPI)"))
102         encaps = atm:taboption("general", ListValue, "encaps", translate("Encapsulation mode"))
103         encaps:value("llc", translate("LLC"))
104         encaps:value("vc", translate("VC-Mux"))
105
106         atmdev  = atm:taboption("advanced", Value, "atmdev", translate("ATM device number"))
107         unit    = atm:taboption("advanced", Value, "unit", translate("Bridge unit number"))
108         payload = atm:taboption("advanced", ListValue, "payload", translate("Forwarding mode"))
109         payload:value("bridged", translate("bridged"))
110         payload:value("routed", translate("routed"))
111         m.pageaction = true
112 end
113
114 local network = require "luci.model.network"
115 if network:has_ipv6() then
116         local s = m:section(NamedSection, "globals", "globals", translate("Global network options"))
117         local o = s:option(Value, "ula_prefix", translate("IPv6 ULA-Prefix"))
118         o.datatype = "ip6addr"
119         o.rmempty = true
120         m.pageaction = true
121 end
122
123
124 return m