2
0

qmi.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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(/^cdc-wdm/))
  14. rv.push(params.path + list[i].name);
  15. return rv.sort();
  16. }
  17. });
  18. network.registerPatternVirtual(/^qmi-.+$/);
  19. network.registerErrorCode('CALL_FAILED', _('Call failed'));
  20. network.registerErrorCode('NO_CID', _('Unable to obtain client ID'));
  21. network.registerErrorCode('PLMN_FAILED', _('Setting PLMN failed'));
  22. return network.registerProtocol('qmi', {
  23. getI18n: function() {
  24. return _('QMI Cellular');
  25. },
  26. getIfname: function() {
  27. return this._ubus('l3_device') || 'qmi-%s'.format(this.sid);
  28. },
  29. getOpkgPackage: function() {
  30. return 'uqmi';
  31. },
  32. isFloating: function() {
  33. return true;
  34. },
  35. isVirtual: function() {
  36. return true;
  37. },
  38. getDevices: function() {
  39. return null;
  40. },
  41. containsDevice: function(ifname) {
  42. return (network.getIfnameOf(ifname) == this.getIfname());
  43. },
  44. renderFormOptions: function(s) {
  45. var dev = this.getL3Device() || this.getDevice(), o;
  46. o = s.taboption('general', form.Value, '_modem_device', _('Modem device'));
  47. o.ucioption = 'device';
  48. o.rmempty = false;
  49. o.load = function(section_id) {
  50. return callFileList('/dev/').then(L.bind(function(devices) {
  51. for (var i = 0; i < devices.length; i++)
  52. this.value(devices[i]);
  53. return form.Value.prototype.load.apply(this, [section_id]);
  54. }, this));
  55. };
  56. var validate_apn = function(section_id, value) {
  57. if (value == null || value == '')
  58. return true;
  59. if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
  60. return _('Invalid APN provided');
  61. return true;
  62. };
  63. o = s.taboption('general', form.Value, 'apn', _('APN'));
  64. o.validate = validate_apn;
  65. if (L.hasSystemFeature('ipv6')) {
  66. o = s.taboption('general', form.Value, 'v6apn', _('IPv6 APN'));
  67. o.validate = validate_apn;
  68. o.depends('pdptype', 'ipv4v6')
  69. };
  70. o = s.taboption('general', form.Value, 'pincode', _('PIN'));
  71. o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
  72. o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
  73. o.value('both', 'PAP/CHAP');
  74. o.value('pap', 'PAP');
  75. o.value('chap', 'CHAP');
  76. o.value('none', 'NONE');
  77. o.default = 'none';
  78. o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
  79. o.depends('auth', 'pap');
  80. o.depends('auth', 'chap');
  81. o.depends('auth', 'both');
  82. o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
  83. o.depends('auth', 'pap');
  84. o.depends('auth', 'chap');
  85. o.depends('auth', 'both');
  86. o.password = true;
  87. if (L.hasSystemFeature('ipv6')) {
  88. o = s.taboption('advanced', form.Flag, 'ppp_ipv6', _('Enable IPv6 negotiation'));
  89. o.ucioption = 'ipv6';
  90. o.default = o.disabled;
  91. }
  92. o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Maximum amount of seconds to wait for the modem to become ready'));
  93. o.placeholder = '10';
  94. o.datatype = 'min(1)';
  95. o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
  96. o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
  97. o.datatype = 'max(9200)';
  98. o = s.taboption('general', form.ListValue, 'pdptype', _('PDP Type'));
  99. o.value('ipv4v6', 'IPv4/IPv6');
  100. o.value('ipv4', 'IPv4');
  101. o.value('ipv6', 'IPv6');
  102. o.default = 'ipv4v6';
  103. o = s.taboption('advanced', form.Flag, 'defaultroute',
  104. _('Use default gateway'),
  105. _('If unchecked, no default route is configured'));
  106. o.default = o.enabled;
  107. o = s.taboption('advanced', form.Value, 'metric',
  108. _('Use gateway metric'));
  109. o.placeholder = '0';
  110. o.datatype = 'uinteger';
  111. o.depends('defaultroute', '1');
  112. o = s.taboption('advanced', form.Flag, 'peerdns',
  113. _('Use DNS servers advertised by peer'),
  114. _('If unchecked, the advertised DNS server addresses are ignored'));
  115. o.default = o.enabled;
  116. o = s.taboption('advanced', form.Value, 'profile',
  117. _('APN profile index'));
  118. o.placeholder = '1';
  119. o.datatype = 'uinteger';
  120. if (L.hasSystemFeature('ipv6')) {
  121. o = s.taboption('advanced', form.Value, 'v6profile',
  122. _('IPv6 APN profile index'));
  123. o.placeholder = '1';
  124. o.datatype = 'uinteger';
  125. o.depends('pdptype', 'ipv4v6');
  126. };
  127. }
  128. });