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