68dfb688cff0b1f4f0cdf2eaff340359ad941fbd
[project/luci.git] / protocols / luci-proto-modemmanager / htdocs / luci-static / resources / protocol / modemmanager.js
1 'use strict';
2 'require rpc';
3 'require form';
4 'require network';
5
6 var callFileList = rpc.declare({
7 object: 'file',
8 method: 'list',
9 params: [ 'path' ],
10 expect: { entries: [] },
11 filter: function(list, params) {
12 var rv = [];
13 for (var i = 0; i < list.length; i++)
14 if (list[i].name.match(/^cdc-wdm/))
15 rv.push(params.path + list[i].name);
16 return rv.sort();
17 }
18 });
19
20 network.registerPatternVirtual(/^mobiledata-.+$/);
21 network.registerErrorCode('CALL_FAILED', _('Call failed'));
22 network.registerErrorCode('NO_CID', _('Unable to obtain client ID'));
23 network.registerErrorCode('PLMN_FAILED', _('Setting PLMN failed'));
24
25 return network.registerProtocol('modemmanager', {
26 getI18n: function() {
27 return _('ModemManager');
28 },
29
30 getIfname: function() {
31 return this._ubus('l3_device') || 'modemmanager-%s'.format(this.sid);
32 },
33
34 getOpkgPackage: function() {
35 return 'modemmanager';
36 },
37
38 isFloating: function() {
39 return true;
40 },
41
42 isVirtual: function() {
43 return true;
44 },
45
46 getDevices: function() {
47 return null;
48 },
49
50 containsDevice: function(ifname) {
51 return (network.getIfnameOf(ifname) == this.getIfname());
52 },
53
54 renderFormOptions: function(s) {
55 var dev = this.getL3Device() || this.getDevice(), o;
56
57 o = s.taboption('general', form.ListValue, 'device', _('Modem device'));
58 o.rmempty = false;
59 o.load = function(section_id) {
60 return callFileList('/dev/').then(L.bind(function(devices) {
61 for (var i = 0; i < devices.length; i++)
62 this.value(devices[i]);
63 return form.Value.prototype.load.apply(this, [section_id]);
64 }, this));
65 };
66
67 s.taboption('general', form.Value, 'apn', _('APN'));
68 s.taboption('general', form.Value, 'pincode', _('PIN'));
69
70 o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
71 o.value('both', _('PAP/CHAP (both)'));
72 o.value('pap', 'PAP');
73 o.value('chap', 'CHAP');
74 o.value('none', _('None'));
75 o.default = 'none';
76
77 o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
78 o.depends('auth', 'pap');
79 o.depends('auth', 'chap');
80 o.depends('auth', 'both');
81
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
88 o = s.taboption('general', form.ListValue, 'iptype', _('IP Type'));
89 o.value('ipv4v6', _('IPv4/IPv6 (both - defaults to IPv4)'))
90 o.value('ipv4', _('IPv4 only'));
91 o.value('ipv6', _('IPv6 only'));
92 o.default = 'ipv4v6';
93
94 o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
95 o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
96 o.datatype = 'max(9200)';
97
98 s.taboption('general', form.Value, 'metric', _('Gateway metric'));
99
100 }
101 });