IPv6 updates
[project/luci.git] / protocols / luci-proto-3g / luasrc / model / cbi / admin_network / proto_3g.lua
1 -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local map, section, net = ...
5
6 local device, apn, service, pincode, username, password, dialnumber
7 local ipv6, maxwait, defaultroute, metric, peerdns, dns,
8       keepalive_failure, keepalive_interval, demand
9
10
11 device = section:taboption("general", Value, "device", translate("Modem device"))
12 device.rmempty = false
13
14 local device_suggestions = nixio.fs.glob("/dev/tty[A-Z]*")
15         or nixio.fs.glob("/dev/tts/*")
16
17 if device_suggestions then
18         local node
19         for node in device_suggestions do
20                 device:value(node)
21         end
22 end
23
24
25 service = section:taboption("general", Value, "service", translate("Service Type"))
26 service:value("", translate("-- Please choose --"))
27 service:value("umts", "UMTS/GPRS")
28 service:value("umts_only", translate("UMTS only"))
29 service:value("gprs_only", translate("GPRS only"))
30 service:value("evdo", "CDMA/EV-DO")
31
32
33 apn = section:taboption("general", Value, "apn", translate("APN"))
34
35
36 pincode = section:taboption("general", Value, "pincode", translate("PIN"))
37
38
39 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
40
41
42 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
43 password.password = true
44
45 dialnumber = section:taboption("general", Value, "dialnumber", translate("Dial number"))
46 dialnumber.placeholder = "*99***1#"
47
48 if luci.model.network:has_ipv6() then
49
50         ipv6 = section:taboption("advanced", ListValue, "ipv6")
51         ipv6:value("auto", translate("Automatic"))
52         ipv6:value("0", translate("Disabled"))
53         ipv6:value("1", translate("Manual"))
54         ipv6.default = "auto"
55
56 end
57
58
59 maxwait = section:taboption("advanced", Value, "maxwait",
60         translate("Modem init timeout"),
61         translate("Maximum amount of seconds to wait for the modem to become ready"))
62
63 maxwait.placeholder = "20"
64 maxwait.datatype    = "min(1)"
65
66
67 defaultroute = section:taboption("advanced", Flag, "defaultroute",
68         translate("Use default gateway"),
69         translate("If unchecked, no default route is configured"))
70
71 defaultroute.default = defaultroute.enabled
72
73
74 metric = section:taboption("advanced", Value, "metric",
75         translate("Use gateway metric"))
76
77 metric.placeholder = "0"
78 metric.datatype    = "uinteger"
79 metric:depends("defaultroute", defaultroute.enabled)
80
81
82 peerdns = section:taboption("advanced", Flag, "peerdns",
83         translate("Use DNS servers advertised by peer"),
84         translate("If unchecked, the advertised DNS server addresses are ignored"))
85
86 peerdns.default = peerdns.enabled
87
88
89 dns = section:taboption("advanced", DynamicList, "dns",
90         translate("Use custom DNS servers"))
91
92 dns:depends("peerdns", "")
93 dns.datatype = "ipaddr"
94 dns.cast     = "string"
95
96
97 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
98         translate("LCP echo failure threshold"),
99         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
100
101 function keepalive_failure.cfgvalue(self, section)
102         local v = m:get(section, "keepalive")
103         if v and #v > 0 then
104                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
105         end
106 end
107
108 function keepalive_failure.write() end
109 function keepalive_failure.remove() end
110
111 keepalive_failure.placeholder = "0"
112 keepalive_failure.datatype    = "uinteger"
113
114
115 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
116         translate("LCP echo interval"),
117         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
118
119 function keepalive_interval.cfgvalue(self, section)
120         local v = m:get(section, "keepalive")
121         if v and #v > 0 then
122                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
123         end
124 end
125
126 function keepalive_interval.write(self, section, value)
127         local f = tonumber(keepalive_failure:formvalue(section)) or 0
128         local i = tonumber(value) or 5
129         if i < 1 then i = 1 end
130         if f > 0 then
131                 m:set(section, "keepalive", "%d %d" %{ f, i })
132         else
133                 m:del(section, "keepalive")
134         end
135 end
136
137 keepalive_interval.remove      = keepalive_interval.write
138 keepalive_interval.placeholder = "5"
139 keepalive_interval.datatype    = "min(1)"
140
141
142 demand = section:taboption("advanced", Value, "demand",
143         translate("Inactivity timeout"),
144         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
145
146 demand.placeholder = "0"
147 demand.datatype    = "uinteger"