e05e3a47fd2a6000de6efa318b565cd8db3b1205
[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 translate("Obtain IPv6-Address"))
52
53 ipv6:value("auto", translate("Automatic"))
54 ipv6:value("0", translate("Disabled"))
55 ipv6:value("1", translate("Manual"))
56 ipv6.default = "auto"
57
58 end
59
60
61 maxwait = section:taboption("advanced", Value, "maxwait",
62 translate("Modem init timeout"),
63 translate("Maximum amount of seconds to wait for the modem to become ready"))
64
65 maxwait.placeholder = "20"
66 maxwait.datatype = "min(1)"
67
68
69 defaultroute = section:taboption("advanced", Flag, "defaultroute",
70 translate("Use default gateway"),
71 translate("If unchecked, no default route is configured"))
72
73 defaultroute.default = defaultroute.enabled
74
75
76 metric = section:taboption("advanced", Value, "metric",
77 translate("Use gateway metric"))
78
79 metric.placeholder = "0"
80 metric.datatype = "uinteger"
81 metric:depends("defaultroute", defaultroute.enabled)
82
83
84 peerdns = section:taboption("advanced", Flag, "peerdns",
85 translate("Use DNS servers advertised by peer"),
86 translate("If unchecked, the advertised DNS server addresses are ignored"))
87
88 peerdns.default = peerdns.enabled
89
90
91 dns = section:taboption("advanced", DynamicList, "dns",
92 translate("Use custom DNS servers"))
93
94 dns:depends("peerdns", "")
95 dns.datatype = "ipaddr"
96 dns.cast = "string"
97
98
99 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
100 translate("LCP echo failure threshold"),
101 translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
102
103 function keepalive_failure.cfgvalue(self, section)
104 local v = m:get(section, "keepalive")
105 if v and #v > 0 then
106 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
107 end
108 end
109
110 function keepalive_failure.write() end
111 function keepalive_failure.remove() end
112
113 keepalive_failure.placeholder = "0"
114 keepalive_failure.datatype = "uinteger"
115
116
117 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
118 translate("LCP echo interval"),
119 translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
120
121 function keepalive_interval.cfgvalue(self, section)
122 local v = m:get(section, "keepalive")
123 if v and #v > 0 then
124 return tonumber(v:match("^%d+[ ,]+(%d+)"))
125 end
126 end
127
128 function keepalive_interval.write(self, section, value)
129 local f = tonumber(keepalive_failure:formvalue(section)) or 0
130 local i = tonumber(value) or 5
131 if i < 1 then i = 1 end
132 if f > 0 then
133 m:set(section, "keepalive", "%d %d" %{ f, i })
134 else
135 m:del(section, "keepalive")
136 end
137 end
138
139 keepalive_interval.remove = keepalive_interval.write
140 keepalive_interval.placeholder = "5"
141 keepalive_interval.datatype = "min(1)"
142
143
144 demand = section:taboption("advanced", Value, "demand",
145 translate("Inactivity timeout"),
146 translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
147
148 demand.placeholder = "0"
149 demand.datatype = "uinteger"