proto_3g.lua 4.2 KB

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