34b71addd67f85033d7f2927e017acfcd21041fc
[project/luci.git] / protocols / luci-proto-modemmanager / htdocs / luci-static / resources / protocol / modemmanager.js
1 'use strict';
2 'require fs';
3 'require form';
4 'require network';
5 'require modemmanager_helper as helper';
6
7 network.registerPatternVirtual(/^mobiledata-.+$/);
8 network.registerErrorCode('MM_CONNECT_FAILED', _('Connection attempt failed.'));
9 network.registerErrorCode('MM_DISCONNECT_IN_PROGRESS', _('Modem disconnection in progress. Please wait.'));
10 network.registerErrorCode('MM_CONNECT_IN_PROGRESS', _('Modem connection in progress. Please wait. This process will timeout after 2 minutes.'));
11 network.registerErrorCode('MM_TEARDOWN_IN_PROGRESS', _('Modem bearer teardown in progress.'));
12 network.registerErrorCode('MM_MODEM_DISABLED', _('Modem is disabled.'));
13 network.registerErrorCode('DEVICE_NOT_MANAGED', _('Device not managed by ModemManager.'));
14 network.registerErrorCode('INVALID_BEARER_LIST', _('Invalid bearer list. Possibly too many bearers created. This protocol supports one and only one bearer.'));
15 network.registerErrorCode('UNKNOWN_METHOD', _('Unknown and unsupported connection method.'));
16 network.registerErrorCode('DISCONNECT_FAILED', _('Disconnection attempt failed.'));
17
18 return network.registerProtocol('modemmanager', {
19 getI18n: function() {
20 return _('ModemManager');
21 },
22
23 getIfname: function() {
24 return this._ubus('l3_device') || 'modemmanager-%s'.format(this.sid);
25 },
26
27 getOpkgPackage: function() {
28 return 'modemmanager';
29 },
30
31 isFloating: function() {
32 return true;
33 },
34
35 isVirtual: function() {
36 return true;
37 },
38
39 getDevices: function() {
40 return null;
41 },
42
43 containsDevice: function(ifname) {
44 return (network.getIfnameOf(ifname) == this.getIfname());
45 },
46
47 renderFormOptions: function(s) {
48 var dev = this.getL3Device() || this.getDevice(), o;
49
50 o = s.taboption('general', form.ListValue, '_modem_device', _('Modem device'));
51 o.ucioption = 'device';
52 o.rmempty = false;
53 o.load = function(section_id) {
54 return helper.getModems().then(L.bind(function(devices) {
55 for (var i = 0; i < devices.length; i++) {
56 var generic = devices[i].modem.generic;
57 this.value(generic.device,
58 '%s - %s'.format(generic.manufacturer, generic.model));
59 }
60 return form.Value.prototype.load.apply(this, [section_id]);
61 }, this));
62 };
63
64 o = s.taboption('general', form.Value, 'apn', _('APN'));
65 o.validate = function(section_id, value) {
66 if (value == null || value == '')
67 return true;
68
69 if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
70 return _('Invalid APN provided');
71
72 return true;
73 };
74
75 o = s.taboption('general', form.Value, 'pincode', _('PIN'));
76 o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
77
78 o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
79 o.value('both', _('PAP/CHAP (both)'));
80 o.value('pap', 'PAP');
81 o.value('chap', 'CHAP');
82 o.value('none', _('None'));
83 o.default = 'none';
84
85 o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
86 o.depends('auth', 'pap');
87 o.depends('auth', 'chap');
88 o.depends('auth', 'both');
89
90 o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
91 o.depends('auth', 'pap');
92 o.depends('auth', 'chap');
93 o.depends('auth', 'both');
94 o.password = true;
95
96 o = s.taboption('general', form.ListValue, 'iptype', _('IP Type'));
97 o.value('ipv4v6', _('IPv4/IPv6 (both - defaults to IPv4)'))
98 o.value('ipv4', _('IPv4 only'));
99 o.value('ipv6', _('IPv6 only'));
100 o.default = 'ipv4v6';
101
102 o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
103 o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
104 o.datatype = 'max(9200)';
105
106 o = s.taboption('general', form.Value, 'signalrate', _('Signal Refresh Rate'), _("In seconds"));
107 o.datatype = 'uinteger';
108 }
109 });