Merge pull request #1980 from hanipouspilot/ncm-addpdp
[oweals/luci.git] / protocols / luci-proto-ncm / luasrc / model / cbi / admin_network / proto_ncm.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2015 Cezary Jackiewicz <cezary.jackiewicz@gmail.com>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11 ]]--
12
13 local map, section, net = ...
14
15 local device, apn, service, pincode, username, password, dialnumber
16 local ipv6, maxwait, defaultroute, metric, peerdns, dns,
17       keepalive_failure, keepalive_interval, demand
18
19
20 device = section:taboption("general", Value, "device", translate("Modem device"))
21 device.rmempty = false
22
23 local device_suggestions = nixio.fs.glob("/dev/cdc-wdm*")
24         or nixio.fs.glob("/dev/ttyUSB*")
25
26 if device_suggestions then
27         local node
28         for node in device_suggestions do
29                 device:value(node)
30         end
31 end
32
33
34 mode = section:taboption("general", Value, "mode", translate("Service Type"))
35 mode:value("", translate("Modem default"))
36 mode:value("preferlte", translate("Prefer LTE"))
37 mode:value("preferumts", translate("Prefer UMTS"))
38 mode:value("lte", "LTE")
39 mode:value("umts", "UMTS/GPRS")
40 mode:value("gsm", translate("GPRS only"))
41 mode:value("auto", translate("auto"))
42
43
44 mode = section:taboption("general", Value, "pdptype", translate("IP Protocol"))
45 mode.default = "IP"
46 mode:value("IP", translate("IPv4"))
47 mode:value("IPV4V6", translate("IPv4+IPv6"))
48 mode:value("IPV6", translate("IPv6"))
49
50
51 apn = section:taboption("general", Value, "apn", translate("APN"))
52
53
54 pincode = section:taboption("general", Value, "pincode", translate("PIN"))
55
56
57 username = section:taboption("general", Value, "username", translate("PAP/CHAP username"))
58
59
60 password = section:taboption("general", Value, "password", translate("PAP/CHAP password"))
61 password.password = true
62
63 dialnumber = section:taboption("general", Value, "dialnumber", translate("Dial number"))
64 dialnumber.placeholder = "*99***1#"
65
66 if luci.model.network:has_ipv6() then
67
68         ipv6 = section:taboption("advanced", ListValue, "ipv6")
69         ipv6:value("auto", translate("Automatic"))
70         ipv6:value("0", translate("Disabled"))
71         ipv6:value("1", translate("Manual"))
72         ipv6.default = "auto"
73
74 end
75
76
77 maxwait = section:taboption("advanced", Value, "maxwait",
78         translate("Modem init timeout"),
79         translate("Maximum amount of seconds to wait for the modem to become ready"))
80
81 maxwait.placeholder = "20"
82 maxwait.datatype    = "min(1)"
83
84
85 defaultroute = section:taboption("advanced", Flag, "defaultroute",
86         translate("Use default gateway"),
87         translate("If unchecked, no default route is configured"))
88
89 defaultroute.default = defaultroute.enabled
90
91 metric = section:taboption("advanced", Value, "metric",
92         translate("Use gateway metric"))
93
94 metric.placeholder = "0"
95 metric.datatype    = "uinteger"
96 metric:depends("defaultroute", defaultroute.enabled)
97
98
99 peerdns = section:taboption("advanced", Flag, "peerdns",
100         translate("Use DNS servers advertised by peer"),
101         translate("If unchecked, the advertised DNS server addresses are ignored"))
102
103 peerdns.default = peerdns.enabled
104
105
106 dns = section:taboption("advanced", DynamicList, "dns",
107         translate("Use custom DNS servers"))
108
109 dns:depends("peerdns", "")
110 dns.datatype = "ipaddr"
111 dns.cast     = "string"
112
113
114 keepalive_failure = section:taboption("advanced", Value, "_keepalive_failure",
115         translate("LCP echo failure threshold"),
116         translate("Presume peer to be dead after given amount of LCP echo failures, use 0 to ignore failures"))
117
118 function keepalive_failure.cfgvalue(self, section)
119         local v = m:get(section, "keepalive")
120         if v and #v > 0 then
121                 return tonumber(v:match("^(%d+)[ ,]+%d+") or v)
122         end
123 end
124
125 function keepalive_failure.write() end
126 function keepalive_failure.remove() end
127
128 keepalive_failure.placeholder = "0"
129 keepalive_failure.datatype    = "uinteger"
130
131
132 keepalive_interval = section:taboption("advanced", Value, "_keepalive_interval",
133         translate("LCP echo interval"),
134         translate("Send LCP echo requests at the given interval in seconds, only effective in conjunction with failure threshold"))
135
136 function keepalive_interval.cfgvalue(self, section)
137         local v = m:get(section, "keepalive")
138         if v and #v > 0 then
139                 return tonumber(v:match("^%d+[ ,]+(%d+)"))
140         end
141 end
142
143 function keepalive_interval.write(self, section, value)
144         local f = tonumber(keepalive_failure:formvalue(section)) or 0
145         local i = tonumber(value) or 5
146         if i < 1 then i = 1 end
147         if f > 0 then
148                 m:set(section, "keepalive", "%d %d" %{ f, i })
149         else
150                 m:del(section, "keepalive")
151         end
152 end
153
154 keepalive_interval.remove      = keepalive_interval.write
155 keepalive_interval.placeholder = "5"
156 keepalive_interval.datatype    = "min(1)"
157
158
159 demand = section:taboption("advanced", Value, "demand",
160         translate("Inactivity timeout"),
161         translate("Close inactive connection after the given amount of seconds, use 0 to persist connection"))
162
163 demand.placeholder = "0"
164 demand.datatype    = "uinteger"