2019-08-20 15:31:35 +02:00
|
|
|
'use strict';
|
|
|
|
'require rpc';
|
|
|
|
'require form';
|
|
|
|
'require network';
|
|
|
|
|
2019-09-08 16:12:25 +02:00
|
|
|
var callFileList = rpc.declare({
|
|
|
|
object: 'file',
|
|
|
|
method: 'list',
|
|
|
|
params: [ 'path' ],
|
|
|
|
expect: { entries: [] },
|
|
|
|
filter: function(list, params) {
|
|
|
|
var rv = [];
|
|
|
|
for (var i = 0; i < list.length; i++)
|
|
|
|
if (list[i].name.match(/^ttyUSB/) || list[i].name.match(/^cdc-wdm/))
|
|
|
|
rv.push(params.path + list[i].name);
|
|
|
|
return rv.sort();
|
|
|
|
}
|
2019-08-20 15:31:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
network.registerPatternVirtual(/^ncm-.+$/);
|
2022-07-28 19:23:21 +03:00
|
|
|
network.registerErrorCode('CONFIGURE_FAILED', _('Failed to configure modem'));
|
|
|
|
network.registerErrorCode('CONNECT_FAILED', _('Failed to connect'));
|
|
|
|
network.registerErrorCode('DISCONNECT_FAILED', _('Failed to disconnect'));
|
|
|
|
network.registerErrorCode('FINALIZE_FAILED', _('Finalizing failed'));
|
|
|
|
network.registerErrorCode('GETINFO_FAILED', _('Failed to get modem information'));
|
|
|
|
network.registerErrorCode('INITIALIZE_FAILED', _('Failed to initialize modem'));
|
|
|
|
network.registerErrorCode('NO_DEVICE', _('No control device specified'));
|
|
|
|
network.registerErrorCode('NO_IFACE', _('The interface could not be found'));
|
|
|
|
network.registerErrorCode('PIN_FAILED', _('Unable to verify PIN'));
|
|
|
|
network.registerErrorCode('SETMODE_FAILED', _('Failed to set operating mode'));
|
2019-08-20 15:31:35 +02:00
|
|
|
network.registerErrorCode('UNSUPPORTED_MODEM', _('Unsupported modem'));
|
|
|
|
|
|
|
|
return network.registerProtocol('ncm', {
|
|
|
|
getI18n: function() {
|
|
|
|
return _('NCM');
|
|
|
|
},
|
|
|
|
|
|
|
|
getIfname: function() {
|
|
|
|
return this._ubus('l3_device') || 'wan';
|
|
|
|
},
|
|
|
|
|
2024-12-15 20:11:23 +01:00
|
|
|
getPackageName: function() {
|
2019-08-20 15:31:35 +02:00
|
|
|
return 'comgt-ncm';
|
|
|
|
},
|
|
|
|
|
|
|
|
isFloating: function() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
isVirtual: function() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
getDevices: function() {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
containsDevice: function(ifname) {
|
|
|
|
return (network.getIfnameOf(ifname) == this.getIfname());
|
|
|
|
},
|
|
|
|
|
|
|
|
renderFormOptions: function(s) {
|
|
|
|
var o;
|
|
|
|
|
2021-06-01 15:31:44 +02:00
|
|
|
o = s.taboption('general', form.Value, '_modem_device', _('Modem device'));
|
|
|
|
o.ucioption = 'device';
|
2019-08-20 15:31:35 +02:00
|
|
|
o.rmempty = false;
|
|
|
|
o.load = function(section_id) {
|
2019-09-08 16:12:25 +02:00
|
|
|
return callFileList('/dev/').then(L.bind(function(devices) {
|
|
|
|
for (var i = 0; i < devices.length; i++)
|
|
|
|
this.value(devices[i]);
|
2019-08-20 15:31:35 +02:00
|
|
|
return form.Value.prototype.load.apply(this, [section_id]);
|
|
|
|
}, this));
|
|
|
|
};
|
|
|
|
|
2022-07-11 11:23:57 +02:00
|
|
|
o = s.taboption('general', form.Value, 'mode', _('Network Mode'));
|
2019-08-20 15:31:35 +02:00
|
|
|
o.value('', _('Modem default'));
|
|
|
|
o.value('preferlte', _('Prefer LTE'));
|
|
|
|
o.value('preferumts', _('Prefer UMTS'));
|
|
|
|
o.value('lte', 'LTE');
|
|
|
|
o.value('umts', 'UMTS/GPRS');
|
|
|
|
o.value('gsm', _('GPRS only'));
|
|
|
|
o.value('auto', _('auto'));
|
|
|
|
|
|
|
|
o = s.taboption('general', form.ListValue, 'pdptype', _('IP Protocol'));
|
|
|
|
o.default = 'IP';
|
|
|
|
o.value('IP', _('IPv4'));
|
|
|
|
o.value('IPV4V6', _('IPv4+IPv6'));
|
|
|
|
o.value('IPV6', _('IPv6'));
|
|
|
|
|
2021-06-27 15:43:13 +10:00
|
|
|
o = s.taboption('general', form.Value, 'apn', _('APN'));
|
|
|
|
o.validate = function(section_id, value) {
|
2021-08-19 08:59:17 +02:00
|
|
|
if (value == null || value == '')
|
|
|
|
return true;
|
|
|
|
|
2021-06-27 15:43:13 +10:00
|
|
|
if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
|
|
|
|
return _('Invalid APN provided');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
o = s.taboption('general', form.Value, 'pincode', _('PIN'));
|
|
|
|
o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
|
|
|
|
|
2019-08-20 15:31:35 +02:00
|
|
|
s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
|
|
|
|
|
|
|
|
o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
|
|
|
|
o.password = true;
|
|
|
|
|
|
|
|
if (L.hasSystemFeature('ipv6')) {
|
2021-06-07 12:43:36 +02:00
|
|
|
o = s.taboption('advanced', form.ListValue, 'ppp_ipv6', _('Obtain IPv6 address'));
|
2021-03-29 20:34:43 +02:00
|
|
|
o.ucioption = 'ipv6';
|
2019-08-20 15:31:35 +02:00
|
|
|
o.value('auto', _('Automatic'));
|
|
|
|
o.value('0', _('Disabled'));
|
|
|
|
o.value('1', _('Manual'));
|
|
|
|
o.default = 'auto';
|
|
|
|
}
|
|
|
|
|
2022-07-28 19:23:21 +03:00
|
|
|
o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Amount of seconds to wait for the modem to become ready'));
|
|
|
|
o.placeholder = '0';
|
|
|
|
o.datatype = 'min(0)';
|
2019-08-20 15:31:35 +02:00
|
|
|
}
|
|
|
|
});
|