protocols: add client side protocol handler implementations
[oweals/luci.git] / protocols / luci-proto-qmi / htdocs / luci-static / resources / protocol / qmi.js
1 'use strict';
2 'require rpc';
3 'require form';
4 'require network';
5
6 var callTTYDevices = rpc.declare({
7         object: 'luci',
8         method: 'getTTYDevices',
9         params: [ 'with_cdc', 'with_tts' ],
10         expect: { result: [] }
11 });
12
13 network.registerPatternVirtual(/^qmi-.+$/);
14 network.registerErrorCode('CALL_FAILED', _('Call failed'));
15 network.registerErrorCode('NO_CID',      _('Unable to obtain client ID'));
16 network.registerErrorCode('PLMN_FAILED', _('Setting PLMN failed'));
17
18 return network.registerProtocol('qmi', {
19         getI18n: function() {
20                 return _('QMI Cellular');
21         },
22
23         getIfname: function() {
24                 return this._ubus('l3_device') || 'qmi-%s'.format(this.sid);
25         },
26
27         getOpkgPackage: function() {
28                 return 'uqmi';
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.Value, 'device', _('Modem device'));
51                 o.rmempty = false;
52                 o.load = function(section_id) {
53                         return callTTYDevices(true, false).then(L.bind(function(devices) {
54                                 if (Array.isArray(devices))
55                                         for (var i = 0; i < devices.length; i++)
56                                                 if (/cdc-wdm/.test(devices[i]))
57                                                         this.value(devices[i]);
58
59                                 return form.Value.prototype.load.apply(this, [section_id]);
60                         }, this));
61                 };
62
63                 s.taboption('general', form.Value, 'apn', _('APN'));
64                 s.taboption('general', form.Value, 'pincode', _('PIN'));
65
66                 o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
67                 o.value('both', 'PAP/CHAP (both)');
68                 o.value('pap', 'PAP');
69                 o.value('chap', 'CHAP');
70                 o.value('none', 'NONE');
71                 o.default = 'none';
72
73                 o = s.taboption('general', form.Value, 'username', _('PAP/CHAP username'));
74                 o.depends('auth', 'pap');
75                 o.depends('auth', 'chap');
76                 o.depends('auth', 'both');
77
78                 o = s.taboption('general', form.Value, 'password', _('PAP/CHAP password'));
79                 o.depends('auth', 'pap');
80                 o.depends('auth', 'chap');
81                 o.depends('auth', 'both');
82                 o.password = true;
83
84                 if (L.hasSystemFeature('ipv6')) {
85                         o = s.taboption('advanced', form.Flag, 'ipv6', _('Enable IPv6 negotiation'));
86                         o.default = o.disabled;
87                 }
88
89                 o = s.taboption('advanced', form.Value, 'delay', _('Modem init timeout'), _('Maximum amount of seconds to wait for the modem to become ready'));
90                 o.placeholder = '10';
91                 o.datatype    = 'min(1)';
92
93                 o = s.taboption('advanced', form.Value, 'mtu', _('Override MTU'));
94                 o.placeholder = dev ? (dev.getMTU() || '1500') : '1500';
95                 o.datatype    = 'max(9200)';
96         }
97 });