op-packages/luci-proto-nbiot/htdocs/luci-static/resources/protocol/nbiot.js
github-actions[bot] 263d407c11 🎄 Sync 2026-04-23 03:14:31
2026-04-23 03:14:31 +08:00

120 lines
3.0 KiB
JavaScript

'use strict';
'require rpc';
'require uci';
'require form';
'require network';
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(/^tty[A-Z]/) || list[i].name.match(/^[0-9]+$/))
rv.push(params.path + list[i].name);
return rv.sort();
}
});
network.registerPatternVirtual(/^nbiot-.+$/);
return network.registerProtocol('nbiot', {
getI18n: function() {
return _('NB-IoT (SIM7020E)');
},
getIfname: function() {
return this._ubus('l3_device') || 'nbiot-%s'.format(this.sid);
},
getOpkgPackage: function() {
return 'comgt';
},
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;
o = s.taboption('general', form.Value, '_modem_device', _('Modem device'));
o.ucioption = 'device';
o.rmempty = false;
o.load = function(section_id) {
return callFileList('/dev/').then(L.bind(function(devices) {
for (var i = 0; i < devices.length; i++)
this.value(devices[i]);
return callFileList('/dev/tts/');
}, this)).then(L.bind(function(devices) {
for (var i = 0; i < devices.length; i++)
this.value(devices[i]);
return form.Value.prototype.load.apply(this, [section_id]);
}, this));
};
o = s.taboption('general', form.DummyValue, 'imei', _('IMEI'));
o = s.taboption('general', form.DummyValue, 'ccid', _('SIM CCID'));
o = s.taboption('general', form.Value, 'apn', _('APN'));
o.validate = function(section_id, value) {
if (value == null || value == '')
return true;
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))';
o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
o.value('pap', 'PAP');
o.value('chap', 'CHAP');
o.value('none', 'NONE');
o.default = 'none';
o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
o.depends('auth', 'pap');
o.depends('auth', 'chap');
o.depends('auth', 'both');
o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
o.depends('auth', 'pap');
o.depends('auth', 'chap');
o.depends('auth', 'both');
o.password = true;
o = s.taboption('general', form.Value, 'dialnumber', _('Dial number'));
o.placeholder = '*99***1#';
o = s.taboption('general', form.MultiValue, 'band', _('NB-IoT band'));
o.value(1);
o.value(3);
o.value(5);
o.value(8);
o.value(20);
o.value(28);
o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Maximum amount of seconds to wait for the modem to become ready'));
o.placeholder = '10';
o.datatype = 'min(1)';
}
});