2011-09-28 09:16:26 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-05-28 22:25:57 -04:00
|
|
|
/* exported ModemBase, ModemGsm, ModemCdma, BroadbandModem */
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
const { Gio, GObject, NM, NMA } = imports.gi;
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
// _getMobileProvidersDatabase:
|
2013-02-05 04:01:53 -05:00
|
|
|
//
|
2012-11-23 10:46:49 -05:00
|
|
|
// Gets the database of mobile providers, with references between MCCMNC/SID and
|
|
|
|
// operator name
|
2013-02-05 04:01:53 -05:00
|
|
|
//
|
2012-11-23 10:46:49 -05:00
|
|
|
let _mpd;
|
|
|
|
function _getMobileProvidersDatabase() {
|
|
|
|
if (_mpd == null) {
|
|
|
|
try {
|
2017-10-31 06:38:20 -04:00
|
|
|
_mpd = new NMA.MobileProvidersDatabase();
|
2012-11-23 10:46:49 -05:00
|
|
|
_mpd.init(null);
|
|
|
|
} catch (e) {
|
|
|
|
log(e.message);
|
|
|
|
_mpd = null;
|
2012-11-01 12:52:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
return _mpd;
|
2012-11-01 12:52:09 -04:00
|
|
|
}
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
// _findProviderForMccMnc:
|
2019-01-31 08:43:52 -05:00
|
|
|
// @operatorName: operator name
|
|
|
|
// @operatorCode: operator code
|
2013-02-05 04:01:53 -05:00
|
|
|
//
|
|
|
|
// Given an operator name string (which may not be a real operator name) and an
|
|
|
|
// operator code string, tries to find a proper operator name to display.
|
|
|
|
//
|
2019-01-31 08:43:52 -05:00
|
|
|
function _findProviderForMccMnc(operatorName, operatorCode) {
|
|
|
|
if (operatorName) {
|
|
|
|
if (operatorName.length != 0 &&
|
|
|
|
(operatorName.length > 6 || operatorName.length < 5)) {
|
2013-02-05 04:01:53 -05:00
|
|
|
// this looks like a valid name, i.e. not an MCCMNC (that some
|
|
|
|
// devices return when not yet connected
|
2019-01-31 08:43:52 -05:00
|
|
|
return operatorName;
|
2013-02-05 04:01:53 -05:00
|
|
|
}
|
|
|
|
|
2019-01-31 08:43:52 -05:00
|
|
|
if (isNaN(parseInt(operatorName))) {
|
2013-02-05 04:01:53 -05:00
|
|
|
// name is definitely not a MCCMNC, so it may be a name
|
|
|
|
// after all; return that
|
2019-01-31 08:43:52 -05:00
|
|
|
return operatorName;
|
2013-02-05 04:01:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let needle;
|
2019-01-31 08:43:52 -05:00
|
|
|
if ((!operatorName || operatorName.length == 0) && operatorCode)
|
|
|
|
needle = operatorCode;
|
|
|
|
else if (operatorName && (operatorName.length == 6 || operatorName.length == 5))
|
|
|
|
needle = operatorName;
|
2013-02-05 04:01:53 -05:00
|
|
|
else // nothing to search
|
|
|
|
return null;
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
let mpd = _getMobileProvidersDatabase();
|
|
|
|
if (mpd) {
|
|
|
|
let provider = mpd.lookup_3gpp_mcc_mnc(needle);
|
|
|
|
if (provider)
|
|
|
|
return provider.get_name();
|
|
|
|
}
|
|
|
|
return null;
|
2013-02-05 04:01:53 -05:00
|
|
|
}
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
// _findProviderForSid:
|
2013-02-05 04:01:53 -05:00
|
|
|
// @sid: System Identifier of the serving CDMA network
|
|
|
|
//
|
|
|
|
// Tries to find the operator name corresponding to the given SID
|
|
|
|
//
|
2012-11-23 10:46:49 -05:00
|
|
|
function _findProviderForSid(sid) {
|
2019-05-26 12:54:42 -04:00
|
|
|
if (!sid)
|
2012-11-01 12:52:09 -04:00
|
|
|
return null;
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
let mpd = _getMobileProvidersDatabase();
|
|
|
|
if (mpd) {
|
|
|
|
let provider = mpd.lookup_cdma_sid(sid);
|
|
|
|
if (provider)
|
|
|
|
return provider.get_name();
|
2012-11-01 12:52:09 -04:00
|
|
|
}
|
|
|
|
return null;
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
|
|
|
|
2012-11-23 10:46:49 -05:00
|
|
|
|
2019-08-19 20:31:52 -04:00
|
|
|
// ----------------------------------------------------- //
|
|
|
|
// Support for the old ModemManager interface (MM < 0.7) //
|
|
|
|
// ----------------------------------------------------- //
|
2013-02-05 04:01:53 -05:00
|
|
|
|
|
|
|
|
|
|
|
// The following are not the complete interfaces, just the methods we need
|
|
|
|
// (or may need in the future)
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const ModemGsmNetworkInterface = loadInterfaceXML('org.freedesktop.ModemManager.Modem.Gsm.Network');
|
2013-02-05 04:01:53 -05:00
|
|
|
const ModemGsmNetworkProxy = Gio.DBusProxy.makeProxyWrapper(ModemGsmNetworkInterface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const ModemCdmaInterface = loadInterfaceXML('org.freedesktop.ModemManager.Modem.Cdma');
|
2013-02-05 04:01:53 -05:00
|
|
|
const ModemCdmaProxy = Gio.DBusProxy.makeProxyWrapper(ModemCdmaInterface);
|
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
var ModemBase = GObject.registerClass({
|
|
|
|
GTypeFlags: GObject.TypeFlags.ABSTRACT,
|
|
|
|
Properties: {
|
|
|
|
'operator-name': GObject.ParamSpec.string(
|
|
|
|
'operator-name', 'operator-name', 'operator-name',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
null),
|
|
|
|
'signal-quality': GObject.ParamSpec.int(
|
|
|
|
'signal-quality', 'signal-quality', 'signal-quality',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
0, 100, 0),
|
|
|
|
},
|
|
|
|
}, class ModemBase extends GObject.Object {
|
2020-10-15 11:14:55 -04:00
|
|
|
_init() {
|
|
|
|
super._init();
|
|
|
|
this._operatorName = null;
|
|
|
|
this._signalQuality = 0;
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get operatorName() {
|
2020-10-15 11:14:55 -04:00
|
|
|
return this._operatorName;
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get signalQuality() {
|
2020-10-15 11:14:55 -04:00
|
|
|
return this._signalQuality;
|
|
|
|
}
|
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
_setOperatorName(operatorName) {
|
2020-10-15 11:14:55 -04:00
|
|
|
if (this._operatorName == operatorName)
|
2019-05-28 22:25:57 -04:00
|
|
|
return;
|
2020-10-15 11:14:55 -04:00
|
|
|
this._operatorName = operatorName;
|
2019-05-28 22:25:57 -04:00
|
|
|
this.notify('operator-name');
|
|
|
|
}
|
|
|
|
|
|
|
|
_setSignalQuality(signalQuality) {
|
2020-10-15 11:14:55 -04:00
|
|
|
if (this._signalQuality == signalQuality)
|
2019-05-28 22:25:57 -04:00
|
|
|
return;
|
2020-10-15 11:14:55 -04:00
|
|
|
this._signalQuality = signalQuality;
|
2019-05-28 22:25:57 -04:00
|
|
|
this.notify('signal-quality');
|
|
|
|
}
|
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
var ModemGsm = GObject.registerClass(
|
|
|
|
class ModemGsm extends ModemBase {
|
|
|
|
_init(path) {
|
|
|
|
super._init();
|
|
|
|
this._proxy = new ModemGsmNetworkProxy(Gio.DBus.system, 'org.freedesktop.ModemManager', path);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
// Code is duplicated because the function have different signatures
|
2017-10-30 20:38:18 -04:00
|
|
|
this._proxy.connectSignal('SignalQuality', (proxy, sender, [quality]) => {
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(quality);
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2019-01-31 09:08:10 -05:00
|
|
|
this._proxy.connectSignal('RegistrationInfo', (proxy, sender, [_status, code, name]) => {
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setOperatorName(_findProviderForMccMnc(name, code));
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
this._proxy.GetRegistrationInfoRemote(([result], err) => {
|
2011-01-25 16:08:12 -05:00
|
|
|
if (err) {
|
|
|
|
log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-31 09:08:00 -05:00
|
|
|
let [status_, code, name] = result;
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setOperatorName(_findProviderForMccMnc(name, code));
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
this._proxy.GetSignalQualityRemote((result, err) => {
|
2011-01-25 16:08:12 -05:00
|
|
|
if (err) {
|
|
|
|
// it will return an error if the device is not connected
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(0);
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
|
|
|
let [quality] = result;
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(quality);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2019-05-28 22:25:57 -04:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
var ModemCdma = GObject.registerClass(
|
|
|
|
class ModemCdma extends ModemBase {
|
|
|
|
_init(path) {
|
|
|
|
super._init();
|
2011-08-16 08:28:53 -04:00
|
|
|
this._proxy = new ModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager', path);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._proxy.connectSignal('SignalQuality', (proxy, sender, params) => {
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(params[0]);
|
2011-01-25 16:08:12 -05:00
|
|
|
|
|
|
|
// receiving this signal means the device got activated
|
|
|
|
// and we can finally call GetServingSystem
|
|
|
|
if (this.operator_name == null)
|
|
|
|
this._refreshServingSystem();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
|
|
|
this._proxy.GetSignalQualityRemote((result, err) => {
|
2011-01-25 16:08:12 -05:00
|
|
|
if (err) {
|
|
|
|
// it will return an error if the device is not connected
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(0);
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
|
|
|
let [quality] = result;
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(quality);
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2011-01-25 16:08:12 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_refreshServingSystem() {
|
2017-10-30 20:38:18 -04:00
|
|
|
this._proxy.GetServingSystemRemote(([result], err) => {
|
2011-01-25 16:08:12 -05:00
|
|
|
if (err) {
|
|
|
|
// it will return an error if the device is not connected
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setOperatorName(null);
|
2011-01-25 16:08:12 -05:00
|
|
|
} else {
|
2019-01-31 09:08:00 -05:00
|
|
|
let [bandClass_, band_, sid] = result;
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setOperatorName(_findProviderForSid(sid));
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2011-01-25 16:08:12 -05:00
|
|
|
}
|
2019-05-28 22:25:57 -04:00
|
|
|
});
|
2013-02-05 04:01:53 -05:00
|
|
|
|
|
|
|
|
2019-08-19 20:31:52 -04:00
|
|
|
// ------------------------------------------------------- //
|
|
|
|
// Support for the new ModemManager1 interface (MM >= 0.7) //
|
|
|
|
// ------------------------------------------------------- //
|
2013-02-05 04:01:53 -05:00
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const BroadbandModemInterface = loadInterfaceXML('org.freedesktop.ModemManager1.Modem');
|
2013-02-05 04:01:53 -05:00
|
|
|
const BroadbandModemProxy = Gio.DBusProxy.makeProxyWrapper(BroadbandModemInterface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const BroadbandModem3gppInterface = loadInterfaceXML('org.freedesktop.ModemManager1.Modem.Modem3gpp');
|
2013-02-05 04:01:53 -05:00
|
|
|
const BroadbandModem3gppProxy = Gio.DBusProxy.makeProxyWrapper(BroadbandModem3gppInterface);
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const BroadbandModemCdmaInterface = loadInterfaceXML('org.freedesktop.ModemManager1.Modem.ModemCdma');
|
2013-02-05 04:01:53 -05:00
|
|
|
const BroadbandModemCdmaProxy = Gio.DBusProxy.makeProxyWrapper(BroadbandModemCdmaInterface);
|
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
var BroadbandModem = GObject.registerClass({
|
|
|
|
Properties: {
|
|
|
|
'capabilities': GObject.ParamSpec.flags(
|
|
|
|
'capabilities', 'capabilities', 'capabilities',
|
|
|
|
GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,
|
|
|
|
NM.DeviceModemCapabilities.$gtype,
|
2019-08-20 17:43:54 -04:00
|
|
|
NM.DeviceModemCapabilities.NONE),
|
2019-05-28 22:25:57 -04:00
|
|
|
},
|
|
|
|
}, class BroadbandModem extends ModemBase {
|
|
|
|
_init(path, capabilities) {
|
|
|
|
super._init({ capabilities });
|
2020-03-19 07:06:26 -04:00
|
|
|
this._proxy = new BroadbandModemProxy(Gio.DBus.system, 'org.freedesktop.ModemManager1', path);
|
2013-02-05 04:01:53 -05:00
|
|
|
this._proxy_3gpp = new BroadbandModem3gppProxy(Gio.DBus.system, 'org.freedesktop.ModemManager1', path);
|
|
|
|
this._proxy_cdma = new BroadbandModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager1', path);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._proxy.connect('g-properties-changed', (proxy, properties) => {
|
2013-02-05 04:01:53 -05:00
|
|
|
if ('SignalQuality' in properties.deep_unpack())
|
|
|
|
this._reloadSignalQuality();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-02-05 04:01:53 -05:00
|
|
|
this._reloadSignalQuality();
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._proxy_3gpp.connect('g-properties-changed', (proxy, properties) => {
|
2013-02-05 04:01:53 -05:00
|
|
|
let unpacked = properties.deep_unpack();
|
|
|
|
if ('OperatorName' in unpacked || 'OperatorCode' in unpacked)
|
|
|
|
this._reload3gppOperatorName();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-02-05 04:01:53 -05:00
|
|
|
this._reload3gppOperatorName();
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
this._proxy_cdma.connect('g-properties-changed', (proxy, properties) => {
|
2013-02-05 04:01:53 -05:00
|
|
|
let unpacked = properties.deep_unpack();
|
|
|
|
if ('Nid' in unpacked || 'Sid' in unpacked)
|
|
|
|
this._reloadCdmaOperatorName();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-02-05 04:01:53 -05:00
|
|
|
this._reloadCdmaOperatorName();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-05 04:01:53 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadSignalQuality() {
|
2020-03-14 17:42:43 -04:00
|
|
|
let [quality, recent_] = this._proxy.SignalQuality;
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setSignalQuality(quality);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-05 04:01:53 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadOperatorName() {
|
2019-01-31 08:43:52 -05:00
|
|
|
let newName = "";
|
2013-02-05 04:01:53 -05:00
|
|
|
if (this.operator_name_3gpp && this.operator_name_3gpp.length > 0)
|
2019-01-31 08:43:52 -05:00
|
|
|
newName += this.operator_name_3gpp;
|
2013-02-05 04:01:53 -05:00
|
|
|
|
|
|
|
if (this.operator_name_cdma && this.operator_name_cdma.length > 0) {
|
2019-01-31 08:43:52 -05:00
|
|
|
if (newName != "")
|
|
|
|
newName += ", ";
|
|
|
|
newName += this.operator_name_cdma;
|
2013-02-05 04:01:53 -05:00
|
|
|
}
|
|
|
|
|
2019-05-28 22:25:57 -04:00
|
|
|
this._setOperatorName(newName);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-05 04:01:53 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reload3gppOperatorName() {
|
2013-02-05 04:01:53 -05:00
|
|
|
let name = this._proxy_3gpp.OperatorName;
|
|
|
|
let code = this._proxy_3gpp.OperatorCode;
|
2012-11-23 10:46:49 -05:00
|
|
|
this.operator_name_3gpp = _findProviderForMccMnc(name, code);
|
2013-02-05 04:01:53 -05:00
|
|
|
this._reloadOperatorName();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-02-05 04:01:53 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_reloadCdmaOperatorName() {
|
2013-02-05 04:01:53 -05:00
|
|
|
let sid = this._proxy_cdma.Sid;
|
2012-11-23 10:46:49 -05:00
|
|
|
this.operator_name_cdma = _findProviderForSid(sid);
|
2013-02-05 04:01:53 -05:00
|
|
|
this._reloadOperatorName();
|
|
|
|
}
|
2019-05-28 22:25:57 -04:00
|
|
|
});
|