ncm.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. 'require rpc';
  3. 'require form';
  4. 'require network';
  5. var callFileList = rpc.declare({
  6. object: 'file',
  7. method: 'list',
  8. params: [ 'path' ],
  9. expect: { entries: [] },
  10. filter: function(list, params) {
  11. var rv = [];
  12. for (var i = 0; i < list.length; i++)
  13. if (list[i].name.match(/^ttyUSB/) || list[i].name.match(/^cdc-wdm/))
  14. rv.push(params.path + list[i].name);
  15. return rv.sort();
  16. }
  17. });
  18. network.registerPatternVirtual(/^ncm-.+$/);
  19. network.registerErrorCode('CONFIGURE_FAILED', _('Failed to configure modem'));
  20. network.registerErrorCode('CONNECT_FAILED', _('Failed to connect'));
  21. network.registerErrorCode('DISCONNECT_FAILED', _('Failed to disconnect'));
  22. network.registerErrorCode('FINALIZE_FAILED', _('Finalizing failed'));
  23. network.registerErrorCode('GETINFO_FAILED', _('Failed to get modem information'));
  24. network.registerErrorCode('INITIALIZE_FAILED', _('Failed to initialize modem'));
  25. network.registerErrorCode('NO_DEVICE', _('No control device specified'));
  26. network.registerErrorCode('NO_IFACE', _('The interface could not be found'));
  27. network.registerErrorCode('PIN_FAILED', _('Unable to verify PIN'));
  28. network.registerErrorCode('SETMODE_FAILED', _('Failed to set operating mode'));
  29. network.registerErrorCode('UNSUPPORTED_MODEM', _('Unsupported modem'));
  30. return network.registerProtocol('ncm', {
  31. getI18n: function() {
  32. return _('NCM');
  33. },
  34. getIfname: function() {
  35. return this._ubus('l3_device') || 'wan';
  36. },
  37. getOpkgPackage: function() {
  38. return 'comgt-ncm';
  39. },
  40. isFloating: function() {
  41. return true;
  42. },
  43. isVirtual: function() {
  44. return true;
  45. },
  46. getDevices: function() {
  47. return null;
  48. },
  49. containsDevice: function(ifname) {
  50. return (network.getIfnameOf(ifname) == this.getIfname());
  51. },
  52. renderFormOptions: function(s) {
  53. var o;
  54. o = s.taboption('general', form.Value, '_modem_device', _('Modem device'));
  55. o.ucioption = 'device';
  56. o.rmempty = false;
  57. o.load = function(section_id) {
  58. return callFileList('/dev/').then(L.bind(function(devices) {
  59. for (var i = 0; i < devices.length; i++)
  60. this.value(devices[i]);
  61. return form.Value.prototype.load.apply(this, [section_id]);
  62. }, this));
  63. };
  64. o = s.taboption('general', form.Value, 'mode', _('Network Mode'));
  65. o.value('', _('Modem default'));
  66. o.value('preferlte', _('Prefer LTE'));
  67. o.value('preferumts', _('Prefer UMTS'));
  68. o.value('lte', 'LTE');
  69. o.value('umts', 'UMTS/GPRS');
  70. o.value('gsm', _('GPRS only'));
  71. o.value('auto', _('auto'));
  72. o = s.taboption('general', form.ListValue, 'pdptype', _('IP Protocol'));
  73. o.default = 'IP';
  74. o.value('IP', _('IPv4'));
  75. o.value('IPV4V6', _('IPv4+IPv6'));
  76. o.value('IPV6', _('IPv6'));
  77. o = s.taboption('general', form.Value, 'apn', _('APN'));
  78. o.validate = function(section_id, value) {
  79. if (value == null || value == '')
  80. return true;
  81. if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
  82. return _('Invalid APN provided');
  83. return true;
  84. };
  85. o = s.taboption('general', form.Value, 'pincode', _('PIN'));
  86. o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
  87. s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
  88. o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
  89. o.password = true;
  90. if (L.hasSystemFeature('ipv6')) {
  91. o = s.taboption('advanced', form.ListValue, 'ppp_ipv6', _('Obtain IPv6 address'));
  92. o.ucioption = 'ipv6';
  93. o.value('auto', _('Automatic'));
  94. o.value('0', _('Disabled'));
  95. o.value('1', _('Manual'));
  96. o.default = 'auto';
  97. }
  98. o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Amount of seconds to wait for the modem to become ready'));
  99. o.placeholder = '0';
  100. o.datatype = 'min(0)';
  101. }
  102. });