modemmanager.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. 'use strict';
  2. 'require fs';
  3. 'require form';
  4. 'require network';
  5. 'require modemmanager_helper as helper';
  6. network.registerPatternVirtual(/^mobiledata-.+$/);
  7. network.registerErrorCode('MM_CONNECT_FAILED', _('Connection attempt failed.'));
  8. network.registerErrorCode('MM_CONNECT_IN_PROGRESS', _('Modem connection in progress. Please wait. This process will timeout after 2 minutes.'));
  9. network.registerErrorCode('DEVICE_NOT_MANAGED', _('Device not managed by ModemManager.'));
  10. network.registerErrorCode('INVALID_BEARER_LIST', _('Invalid bearer list. Possibly too many bearers created. This protocol supports one and only one bearer.'));
  11. network.registerErrorCode('UNKNOWN_METHOD', _('Unknown and unsupported connection method.'));
  12. network.registerErrorCode('DISCONNECT_FAILED', _('Disconnection attempt failed.'));
  13. network.registerErrorCode('MM_INVALID_ALLOWED_MODES_LIST', _('Unable to set allowed mode list.'));
  14. network.registerErrorCode('MM_NO_PREFERRED_MODE_CONFIGURED', _('No preferred mode configuration found.'));
  15. network.registerErrorCode('MM_NO_ALLOWED_MODE_CONFIGURED', _('No allowed mode configuration found.'));
  16. network.registerErrorCode('MM_FAILED_SETTING_PREFERRED_MODE', _('Unable to set preferred mode.'));
  17. return network.registerProtocol('modemmanager', {
  18. getI18n: function() {
  19. return _('ModemManager');
  20. },
  21. getIfname: function() {
  22. return this._ubus('l3_device') || 'modemmanager-%s'.format(this.sid);
  23. },
  24. getOpkgPackage: function() {
  25. return 'modemmanager';
  26. },
  27. isFloating: function() {
  28. return true;
  29. },
  30. isVirtual: function() {
  31. return true;
  32. },
  33. getDevices: function() {
  34. return null;
  35. },
  36. containsDevice: function(ifname) {
  37. return (network.getIfnameOf(ifname) == this.getIfname());
  38. },
  39. renderFormOptions: function(s) {
  40. var dev = this.getL3Device() || this.getDevice(), o;
  41. o = s.taboption('general', form.ListValue, '_modem_device', _('Modem device'));
  42. o.ucioption = 'device';
  43. o.rmempty = false;
  44. o.load = function(section_id) {
  45. return helper.getModems().then(L.bind(function(devices) {
  46. for (var i = 0; i < devices.length; i++) {
  47. var generic = devices[i].modem.generic;
  48. this.value(generic.device,
  49. '%s - %s'.format(generic.manufacturer, generic.model));
  50. }
  51. return form.Value.prototype.load.apply(this, [section_id]);
  52. }, this));
  53. };
  54. o = s.taboption('general', form.Value, 'apn', _('APN'));
  55. o.validate = function(section_id, value) {
  56. if (value == null || value == '')
  57. return true;
  58. if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
  59. return _('Invalid APN provided');
  60. return true;
  61. };
  62. o = s.taboption('general', form.Value, 'pincode', _('PIN'));
  63. o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
  64. o = s.taboption('general', form.DynamicList, 'allowedauth', _('Authentication Type'));
  65. o.value('pap', 'PAP');
  66. o.value('chap', 'CHAP');
  67. o.value('mschap', 'MSCHAP');
  68. o.value('mschapv2', 'MSCHAPv2');
  69. o.value('eap', 'EAP');
  70. o.value('', _('None'));
  71. o.default = 'none';
  72. o = s.taboption('general', form.ListValue, 'allowedmode', _('Allowed network technology'),
  73. _('Setting the allowed network technology.'));
  74. o.value('2g');
  75. o.value('3g');
  76. o.value('3g|2g');
  77. o.value('4g');
  78. o.value('4g|2g');
  79. o.value('4g|3g');
  80. o.value('4g|3g|2g');
  81. o.value('5g');
  82. o.value('5g|2g');
  83. o.value('5g|3g');
  84. o.value('5g|3g|2g');
  85. o.value('5g|4g');
  86. o.value('5g|4g|2g');
  87. o.value('5g|4g|3g');
  88. o.value('5g|4g|3g|2g');
  89. o.value('',_('any'));
  90. o.default = '';
  91. o = s.taboption('general', form.ListValue, 'preferredmode', _('Preferred network technology'),
  92. _('Setting the preferred network technology.'));
  93. o.value('2g');
  94. o.value('3g');
  95. o.value('4g');
  96. o.value('5g');
  97. o.value('none', _('None'));
  98. o.depends('allowedmode','3g|2g');
  99. o.depends('allowedmode','4g|2g');
  100. o.depends('allowedmode','4g|3g');
  101. o.depends('allowedmode','4g|3g|2g');
  102. o.depends('allowedmode','5g|2g');
  103. o.depends('allowedmode','5g|3g');
  104. o.depends('allowedmode','5g|3g|2g');
  105. o.depends('allowedmode','5g|4g');
  106. o.depends('allowedmode','5g|4g|2g');
  107. o.depends('allowedmode','5g|4g|3g');
  108. o.depends('allowedmode','5g|4g|3g|2g');
  109. o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
  110. o.depends('auth', 'pap');
  111. o.depends('auth', 'chap');
  112. o.depends('auth', 'both');
  113. o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
  114. o.depends('auth', 'pap');
  115. o.depends('auth', 'chap');
  116. o.depends('auth', 'both');
  117. o.password = true;
  118. o = s.taboption('general', form.ListValue, 'iptype', _('IP Type'));
  119. o.value('ipv4v6', _('IPv4/IPv6 (both - defaults to IPv4)'))
  120. o.value('ipv4', _('IPv4 only'));
  121. o.value('ipv6', _('IPv6 only'));
  122. o.default = 'ipv4v6';
  123. o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
  124. o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
  125. o.datatype = 'max(9200)';
  126. o = s.taboption('general', form.Value, 'signalrate', _('Signal Refresh Rate'), _("In seconds"));
  127. o.datatype = 'uinteger';
  128. s.taboption('general', form.Value, 'metric', _('Gateway metric'));
  129. s.taboption('advanced', form.Flag, 'debugmode', _('Enable Debugmode'));
  130. o = s.taboption('advanced', form.ListValue, 'loglevel', _('Log output level'));
  131. o.value('ERR', _('Error'))
  132. o.value('WARN', _('Warning'));
  133. o.value('INFO', _('Info'));
  134. o.value('DEBUG', _('Debug'));
  135. o.default = 'ERR';
  136. o = s.taboption('general', form.ListValue, 'init_epsbearer', _('Initial EPS Bearer'),
  137. _('none: Do not set an initial EPS bearer (default behaviour)') + '<br/>' +
  138. _('default: Use the configuration options above (APN, IP Type, ...).') + '<br/>' +
  139. _('custom: Use different options when establishing a connection (these options are prefixed with %s).').format('<code>init_</code>'));
  140. o.value('', _('none'));
  141. o.value('default', 'default');
  142. o.value('custom', 'custom');
  143. o.default = '';
  144. o = s.taboption('general', form.Value, 'init_apn', _('Initial EPS Bearer APN'));
  145. o.depends('init_epsbearer', 'custom');
  146. o.default = '';
  147. o = s.taboption('general', form.ListValue, 'init_allowedauth', _('Initial EPS Bearer Authentication Type'));
  148. o.depends('init_epsbearer', 'custom');
  149. o.value('pap', 'PAP');
  150. o.value('chap', 'CHAP');
  151. o.value('mschap', 'MSCHAP');
  152. o.value('mschapv2', 'MSCHAPv2');
  153. o.value('eap', 'EAP');
  154. o.value('', _('None'));
  155. o.default = '';
  156. o = s.taboption('general', form.Value, 'init_username', _('Initial EPS Bearer Username'));
  157. o.depends('init_allowedauth', 'pap');
  158. o.depends('init_allowedauth', 'chap');
  159. o.depends('init_allowedauth', 'mschap');
  160. o.depends('init_allowedauth', 'mschapv2');
  161. o.depends('init_allowedauth', 'eap');
  162. o.default = '';
  163. o = s.taboption('general', form.Value, 'init_password', _('Initial EPS Bearer Password'));
  164. o.depends('init_allowedauth', 'pap');
  165. o.depends('init_allowedauth', 'chap');
  166. o.depends('init_allowedauth', 'mschap');
  167. o.depends('init_allowedauth', 'mschapv2');
  168. o.depends('init_allowedauth', 'eap');
  169. o.default = '';
  170. o.password = true;
  171. o = s.taboption('general', form.ListValue, 'init_iptype', _('Initial EPS Bearer IP Type'));
  172. o.depends('init_epsbearer', 'custom');
  173. o.value('ipv4v6', _('IPv4/IPv6 (both - defaults to IPv4)'))
  174. o.value('ipv4', _('IPv4 only'));
  175. o.value('ipv6', _('IPv6 only'));
  176. o.default = 'ipv4v6';
  177. }
  178. });