2013-11-15 09:35:33 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2014-01-16 01:57:26 +00:00
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
2014-08-06 05:51:00 +00:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2013-11-15 09:35:33 +00:00
|
|
|
|
|
|
|
const NETWORKSERVICE_CONTRACTID = "@mozilla.org/network/service;1";
|
2014-07-10 05:29:47 +00:00
|
|
|
const NETWORKSERVICE_CID = Components.ID("{baec696c-c78d-42db-8b44-603f8fbfafb4}");
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-03-18 09:38:20 +00:00
|
|
|
const TOPIC_PREF_CHANGED = "nsPref:changed";
|
|
|
|
const TOPIC_XPCOM_SHUTDOWN = "xpcom-shutdown";
|
|
|
|
const PREF_NETWORK_DEBUG_ENABLED = "network.debugging.enabled";
|
|
|
|
|
2014-01-29 11:38:50 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "gNetworkWorker",
|
|
|
|
"@mozilla.org/network/worker;1",
|
|
|
|
"nsINetworkWorker");
|
|
|
|
|
2013-11-15 09:35:33 +00:00
|
|
|
// 1xx - Requested action is proceeding
|
|
|
|
const NETD_COMMAND_PROCEEDING = 100;
|
|
|
|
// 2xx - Requested action has been successfully completed
|
|
|
|
const NETD_COMMAND_OKAY = 200;
|
|
|
|
// 4xx - The command is accepted but the requested action didn't
|
|
|
|
// take place.
|
|
|
|
const NETD_COMMAND_FAIL = 400;
|
|
|
|
// 5xx - The command syntax or parameters error
|
|
|
|
const NETD_COMMAND_ERROR = 500;
|
|
|
|
// 6xx - Unsolicited broadcasts
|
|
|
|
const NETD_COMMAND_UNSOLICITED = 600;
|
|
|
|
|
|
|
|
const WIFI_CTRL_INTERFACE = "wl0.1";
|
|
|
|
|
2015-03-18 09:38:20 +00:00
|
|
|
let debug;
|
|
|
|
function updateDebug() {
|
|
|
|
let debugPref = false; // set default value here.
|
|
|
|
try {
|
|
|
|
debugPref = debugPref || Services.prefs.getBoolPref(PREF_NETWORK_DEBUG_ENABLED);
|
|
|
|
} catch (e) {}
|
2014-04-09 06:10:04 +00:00
|
|
|
|
2015-03-18 09:38:20 +00:00
|
|
|
if (debugPref) {
|
|
|
|
debug = function(s) {
|
|
|
|
dump("-*- NetworkService: " + s + "\n");
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
debug = function(s) {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateDebug();
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
function netdResponseType(aCode) {
|
|
|
|
return Math.floor(aCode / 100) * 100;
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
function isError(aCode) {
|
|
|
|
let type = netdResponseType(aCode);
|
2013-11-15 09:35:33 +00:00
|
|
|
return (type !== NETD_COMMAND_PROCEEDING && type !== NETD_COMMAND_OKAY);
|
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
function Task(aId, aParams, aSetupFunction) {
|
|
|
|
this.id = aId;
|
|
|
|
this.params = aParams;
|
|
|
|
this.setupFunction = aSetupFunction;
|
2015-02-11 08:01:08 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
function NetworkWorkerRequestQueue(aNetworkService) {
|
|
|
|
this.networkService = aNetworkService;
|
2015-02-11 08:01:08 +00:00
|
|
|
this.tasks = [];
|
|
|
|
}
|
|
|
|
NetworkWorkerRequestQueue.prototype = {
|
|
|
|
runQueue: function() {
|
|
|
|
if (this.tasks.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let task = this.tasks[0];
|
2015-03-18 09:38:20 +00:00
|
|
|
debug("run task id: " + task.id);
|
2015-02-11 08:01:08 +00:00
|
|
|
|
|
|
|
if (typeof task.setupFunction === 'function') {
|
|
|
|
// If setupFunction returns false, skip sending to Network Worker but call
|
|
|
|
// handleWorkerMessage() directly with task id, as if the response was
|
|
|
|
// returned from Network Worker.
|
|
|
|
if (!task.setupFunction()) {
|
|
|
|
this.networkService.handleWorkerMessage({id: task.id});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gNetworkWorker.postMessage(task.params);
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
enqueue: function(aId, aParams, aSetupFunction) {
|
|
|
|
debug("enqueue id: " + aId);
|
|
|
|
this.tasks.push(new Task(aId, aParams, aSetupFunction));
|
2015-02-11 08:01:08 +00:00
|
|
|
|
|
|
|
if (this.tasks.length === 1) {
|
|
|
|
this.runQueue();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
dequeue: function(aId) {
|
|
|
|
debug("dequeue id: " + aId);
|
2015-02-11 08:01:08 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
if (!this.tasks.length || this.tasks[0].id != aId) {
|
|
|
|
debug("Id " + aId + " is not on top of the queue");
|
2015-02-11 08:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tasks.shift();
|
|
|
|
if (this.tasks.length > 0) {
|
|
|
|
// Run queue on the next tick.
|
|
|
|
Services.tm.currentThread.dispatch(() => {
|
|
|
|
this.runQueue();
|
|
|
|
}, Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-11-15 09:35:33 +00:00
|
|
|
/**
|
|
|
|
* This component watches for network interfaces changing state and then
|
|
|
|
* adjusts routes etc. accordingly.
|
|
|
|
*/
|
|
|
|
function NetworkService() {
|
2015-06-04 03:04:18 +00:00
|
|
|
debug("Starting NetworkService.");
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2014-01-29 11:38:50 +00:00
|
|
|
let self = this;
|
|
|
|
|
|
|
|
if (gNetworkWorker) {
|
|
|
|
let networkListener = {
|
2015-06-04 03:04:18 +00:00
|
|
|
onEvent: function(aEvent) {
|
|
|
|
self.handleWorkerMessage(aEvent);
|
2014-01-29 11:38:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
gNetworkWorker.start(networkListener);
|
|
|
|
}
|
2013-11-15 09:35:33 +00:00
|
|
|
// Callbacks to invoke when a reply arrives from the net_worker.
|
|
|
|
this.controlCallbacks = Object.create(null);
|
2014-01-29 11:38:50 +00:00
|
|
|
|
2015-02-11 08:01:08 +00:00
|
|
|
this.addedRoutes = new Map();
|
|
|
|
this.netWorkerRequestQueue = new NetworkWorkerRequestQueue(this);
|
2014-01-29 11:38:50 +00:00
|
|
|
this.shutdown = false;
|
2015-03-18 09:38:20 +00:00
|
|
|
|
|
|
|
Services.prefs.addObserver(PREF_NETWORK_DEBUG_ENABLED, this, false);
|
|
|
|
Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NetworkService.prototype = {
|
|
|
|
classID: NETWORKSERVICE_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: NETWORKSERVICE_CID,
|
|
|
|
contractID: NETWORKSERVICE_CONTRACTID,
|
|
|
|
classDescription: "Network Service",
|
|
|
|
interfaces: [Ci.nsINetworkService]}),
|
2015-03-18 09:38:20 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkService,
|
|
|
|
Ci.nsIObserver]),
|
|
|
|
|
|
|
|
addedRoutes: null,
|
|
|
|
|
|
|
|
shutdown: false,
|
|
|
|
|
|
|
|
// nsIObserver
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
switch (aTopic) {
|
2015-03-18 09:38:20 +00:00
|
|
|
case TOPIC_PREF_CHANGED:
|
2015-06-04 03:04:18 +00:00
|
|
|
if (aData === PREF_NETWORK_DEBUG_ENABLED) {
|
2015-03-18 09:38:20 +00:00
|
|
|
updateDebug();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TOPIC_XPCOM_SHUTDOWN:
|
|
|
|
debug("NetworkService shutdown");
|
|
|
|
this.shutdown = true;
|
|
|
|
if (gNetworkWorker) {
|
|
|
|
gNetworkWorker.shutdown();
|
|
|
|
gNetworkWorker = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.removeObserver(this, TOPIC_XPCOM_SHUTDOWN);
|
|
|
|
Services.prefs.removeObserver(PREF_NETWORK_DEBUG_ENABLED, this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2013-11-15 09:35:33 +00:00
|
|
|
|
|
|
|
// Helpers
|
|
|
|
|
|
|
|
idgen: 0,
|
2015-06-04 03:04:18 +00:00
|
|
|
controlMessage: function(aParams, aCallback, aSetupFunction) {
|
2014-01-29 11:38:50 +00:00
|
|
|
if (this.shutdown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-11 08:01:08 +00:00
|
|
|
let id = this.idgen++;
|
2015-06-04 03:04:18 +00:00
|
|
|
aParams.id = id;
|
|
|
|
if (aCallback) {
|
|
|
|
this.controlCallbacks[id] = aCallback;
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
2015-02-11 08:01:08 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
// For now, we use aSetupFunction to determine if this command needs to be
|
2015-02-11 08:01:08 +00:00
|
|
|
// queued or not.
|
2015-06-04 03:04:18 +00:00
|
|
|
if (aSetupFunction) {
|
|
|
|
this.netWorkerRequestQueue.enqueue(id, aParams, aSetupFunction);
|
2015-02-11 08:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-29 11:38:50 +00:00
|
|
|
if (gNetworkWorker) {
|
2015-06-04 03:04:18 +00:00
|
|
|
gNetworkWorker.postMessage(aParams);
|
2014-01-29 11:38:50 +00:00
|
|
|
}
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
handleWorkerMessage: function(aResponse) {
|
|
|
|
debug("NetworkManager received message from worker: " + JSON.stringify(aResponse));
|
|
|
|
let id = aResponse.id;
|
|
|
|
if (aResponse.broadcast === true) {
|
|
|
|
Services.obs.notifyObservers(null, aResponse.topic, aResponse.reason);
|
2013-11-15 09:35:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let callback = this.controlCallbacks[id];
|
|
|
|
if (callback) {
|
2015-06-04 03:04:18 +00:00
|
|
|
callback.call(this, aResponse);
|
2013-11-15 09:35:33 +00:00
|
|
|
delete this.controlCallbacks[id];
|
|
|
|
}
|
2015-02-11 08:01:08 +00:00
|
|
|
|
|
|
|
this.netWorkerRequestQueue.dequeue(id);
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// nsINetworkService
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
getNetworkInterfaceStats: function(aInterfaceName, aCallback) {
|
|
|
|
debug("getNetworkInterfaceStats for " + aInterfaceName);
|
2014-01-08 17:10:21 +00:00
|
|
|
|
2014-01-29 11:38:50 +00:00
|
|
|
let file = new FileUtils.File("/proc/net/dev");
|
2014-01-16 01:57:26 +00:00
|
|
|
if (!file) {
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.networkStatsAvailable(false, 0, 0, Date.now());
|
2014-01-16 01:57:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-08 17:10:21 +00:00
|
|
|
|
2015-05-22 02:51:40 +00:00
|
|
|
NetUtil.asyncFetch({
|
|
|
|
uri: NetUtil.newURI(file),
|
|
|
|
loadUsingSystemPrincipal: true
|
|
|
|
}, function(inputStream, status) {
|
2014-08-01 07:08:41 +00:00
|
|
|
let rxBytes = 0,
|
|
|
|
txBytes = 0,
|
|
|
|
now = Date.now();
|
2014-01-16 01:57:26 +00:00
|
|
|
|
|
|
|
if (Components.isSuccessCode(status)) {
|
|
|
|
// Find record for corresponding interface.
|
2014-01-19 09:03:24 +00:00
|
|
|
let statExpr = /(\S+): +(\d+) +\d+ +\d+ +\d+ +\d+ +\d+ +\d+ +\d+ +(\d+) +\d+ +\d+ +\d+ +\d+ +\d+ +\d+ +\d+/;
|
2014-08-01 07:08:41 +00:00
|
|
|
let data =
|
|
|
|
NetUtil.readInputStreamToString(inputStream, inputStream.available())
|
|
|
|
.split("\n");
|
2014-01-16 01:57:26 +00:00
|
|
|
for (let i = 2; i < data.length; i++) {
|
|
|
|
let parseResult = statExpr.exec(data[i]);
|
2015-06-04 03:04:18 +00:00
|
|
|
if (parseResult && parseResult[1] === aInterfaceName) {
|
2014-08-01 07:08:41 +00:00
|
|
|
rxBytes = parseInt(parseResult[2], 10);
|
|
|
|
txBytes = parseInt(parseResult[3], 10);
|
2014-01-16 01:57:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-01 07:08:41 +00:00
|
|
|
// netd always return success even interface doesn't exist.
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.networkStatsAvailable(true, rxBytes, txBytes, now);
|
2015-05-22 02:51:40 +00:00
|
|
|
});
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-07-24 11:16:02 +00:00
|
|
|
setNetworkTetheringAlarm(aEnable, aInterface) {
|
|
|
|
// Method called when enabling disabling tethering, it checks if there is
|
|
|
|
// some alarm active and move from interfaceAlarm to globalAlarm because
|
|
|
|
// interfaceAlarm doens't work in tethering scenario due to forwarding.
|
|
|
|
debug("setNetworkTetheringAlarm for tethering" + aEnable);
|
|
|
|
|
|
|
|
let filename = aEnable ? "/proc/net/xt_quota/" + aInterface + "Alert" :
|
|
|
|
"/proc/net/xt_quota/globalAlert";
|
|
|
|
|
|
|
|
let file = new FileUtils.File(filename);
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NetUtil.asyncFetch({
|
|
|
|
uri: NetUtil.newURI(file),
|
|
|
|
loadUsingSystemPrincipal: true
|
|
|
|
}, (inputStream, status) => {
|
|
|
|
if (Components.isSuccessCode(status)) {
|
|
|
|
let data = NetUtil.readInputStreamToString(inputStream, inputStream.available())
|
|
|
|
.split("\n");
|
|
|
|
if (data) {
|
|
|
|
let threshold = parseInt(data[0], 10);
|
|
|
|
|
|
|
|
this._setNetworkTetheringAlarm(aEnable, aInterface, threshold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_setNetworkTetheringAlarm(aEnable, aInterface, aThreshold, aCallback) {
|
|
|
|
debug("_setNetworkTetheringAlarm for tethering" + aEnable);
|
|
|
|
|
|
|
|
let cmd = aEnable ? "setTetheringAlarm" : "removeTetheringAlarm";
|
|
|
|
|
|
|
|
let params = {
|
|
|
|
cmd: cmd,
|
|
|
|
ifname: aInterface,
|
|
|
|
threshold: aThreshold,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.controlMessage(params, function(aData) {
|
|
|
|
let code = aData.resultCode;
|
|
|
|
let reason = aData.resultReason;
|
|
|
|
let enableString = aEnable ? "Enable" : "Disable";
|
|
|
|
debug(enableString + " tethering Alarm result: Code " + code + " reason " + reason);
|
|
|
|
if (aCallback) {
|
|
|
|
aCallback.networkUsageAlarmResult(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
setNetworkInterfaceAlarm: function(aInterfaceName, aThreshold, aCallback) {
|
|
|
|
if (!aInterfaceName) {
|
|
|
|
aCallback.networkUsageAlarmResult(-1);
|
2013-05-24 09:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 08:03:29 +00:00
|
|
|
let self = this;
|
2015-06-04 03:04:18 +00:00
|
|
|
this._disableNetworkInterfaceAlarm(aInterfaceName, function(aResult) {
|
|
|
|
if (aThreshold < 0) {
|
|
|
|
if (!isError(aResult.resultCode)) {
|
|
|
|
aCallback.networkUsageAlarmResult(null);
|
2014-02-10 08:03:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.networkUsageAlarmResult(aResult.reason);
|
2014-02-10 08:03:29 +00:00
|
|
|
return
|
|
|
|
}
|
2013-05-24 09:28:20 +00:00
|
|
|
|
2015-07-24 11:16:02 +00:00
|
|
|
// Check if tethering is enabled
|
|
|
|
let params = {
|
|
|
|
cmd: "getTetheringStatus"
|
|
|
|
};
|
|
|
|
|
|
|
|
self.controlMessage(params, function(aResult) {
|
|
|
|
if (isError(aResult.resultCode)) {
|
|
|
|
aCallback.networkUsageAlarmResult(aResult.reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aResult.resultReason.indexOf('started') == -1) {
|
|
|
|
// Tethering disabled, set interfaceAlarm
|
|
|
|
self._setNetworkInterfaceAlarm(aInterfaceName, aThreshold, aCallback);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tethering enabled, set globalAlarm
|
|
|
|
self._setNetworkTetheringAlarm(true, aInterfaceName, aThreshold, aCallback);
|
|
|
|
});
|
2014-02-10 08:03:29 +00:00
|
|
|
});
|
2013-05-24 09:28:20 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
_setNetworkInterfaceAlarm: function(aInterfaceName, aThreshold, aCallback) {
|
|
|
|
debug("setNetworkInterfaceAlarm for " + aInterfaceName + " at " + aThreshold + "bytes");
|
2013-05-24 09:28:20 +00:00
|
|
|
|
|
|
|
let params = {
|
|
|
|
cmd: "setNetworkInterfaceAlarm",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
threshold: aThreshold
|
2013-05-24 09:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
params.report = true;
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
if (!isError(aResult.resultCode)) {
|
|
|
|
aCallback.networkUsageAlarmResult(null);
|
2013-05-24 09:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this._enableNetworkInterfaceAlarm(aInterfaceName, aThreshold, aCallback);
|
2013-05-24 09:28:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
_enableNetworkInterfaceAlarm: function(aInterfaceName, aThreshold, aCallback) {
|
|
|
|
debug("enableNetworkInterfaceAlarm for " + aInterfaceName + " at " + aThreshold + "bytes");
|
2013-05-24 09:28:20 +00:00
|
|
|
|
|
|
|
let params = {
|
|
|
|
cmd: "enableNetworkInterfaceAlarm",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
threshold: aThreshold
|
2013-05-24 09:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
params.report = true;
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
if (!isError(aResult.resultCode)) {
|
|
|
|
aCallback.networkUsageAlarmResult(null);
|
2013-05-24 09:28:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.networkUsageAlarmResult(aResult.reason);
|
2013-05-24 09:28:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
_disableNetworkInterfaceAlarm: function(aInterfaceName, aCallback) {
|
|
|
|
debug("disableNetworkInterfaceAlarm for " + aInterfaceName);
|
2013-05-24 09:28:20 +00:00
|
|
|
|
|
|
|
let params = {
|
|
|
|
cmd: "disableNetworkInterfaceAlarm",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
2013-05-24 09:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
params.report = true;
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback(aResult);
|
2013-05-24 09:28:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
setWifiOperationMode: function(aInterfaceName, aMode, aCallback) {
|
|
|
|
debug("setWifiOperationMode on " + aInterfaceName + " to " + aMode);
|
2013-11-15 09:35:33 +00:00
|
|
|
|
|
|
|
let params = {
|
|
|
|
cmd: "setWifiOperationMode",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
mode: aMode
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
params.report = true;
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
if (isError(aResult.resultCode)) {
|
|
|
|
aCallback.wifiOperationModeResult("netd command error");
|
2013-11-15 09:35:33 +00:00
|
|
|
} else {
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.wifiOperationModeResult(null);
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
resetRoutingTable: function(aInterfaceName, aCallback) {
|
2015-01-09 06:45:53 +00:00
|
|
|
let options = {
|
|
|
|
cmd: "removeNetworkRoute",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2015-01-09 06:45:53 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-05-05 03:48:00 +00:00
|
|
|
});
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
setDNS: function(aInterfaceName, aDnsesCount, aDnses, aGatewaysCount,
|
|
|
|
aGateways, aCallback) {
|
|
|
|
debug("Going to set DNS to " + aInterfaceName);
|
2013-11-15 09:35:33 +00:00
|
|
|
let options = {
|
|
|
|
cmd: "setDNS",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
domain: "mozilla." + aInterfaceName + ".domain",
|
|
|
|
dnses: aDnses,
|
|
|
|
gateways: aGateways
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, function(aResult) {
|
|
|
|
aCallback.setDnsResult(aResult.success ? null : aResult.reason);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
setDefaultRoute: function(aInterfaceName, aCount, aGateways,
|
|
|
|
aOldInterfaceName, aCallback) {
|
|
|
|
debug("Going to change default route to " + aInterfaceName);
|
2013-11-15 09:35:33 +00:00
|
|
|
let options = {
|
2014-08-18 03:02:56 +00:00
|
|
|
cmd: "setDefaultRoute",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
oldIfname: (aOldInterfaceName && aOldInterfaceName !== aInterfaceName) ?
|
|
|
|
aOldInterfaceName : null,
|
|
|
|
gateways: aGateways
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
removeDefaultRoute: function(aInterfaceName, aCount, aGateways, aCallback) {
|
|
|
|
debug("Remove default route for " + aInterfaceName);
|
2013-11-15 09:35:33 +00:00
|
|
|
let options = {
|
|
|
|
cmd: "removeDefaultRoute",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
gateways: aGateways
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-05-05 03:48:00 +00:00
|
|
|
});
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
_routeToString: function(aInterfaceName, aHost, aPrefixLength, aGateway) {
|
|
|
|
return aHost + "-" + aPrefixLength + "-" + aGateway + "-" + aInterfaceName;
|
2015-02-11 08:01:08 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
modifyRoute: function(aAction, aInterfaceName, aHost, aPrefixLength, aGateway) {
|
2015-01-09 06:45:53 +00:00
|
|
|
let command;
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
switch (aAction) {
|
2015-01-09 06:45:53 +00:00
|
|
|
case Ci.nsINetworkService.MODIFY_ROUTE_ADD:
|
|
|
|
command = 'addHostRoute';
|
|
|
|
break;
|
|
|
|
case Ci.nsINetworkService.MODIFY_ROUTE_REMOVE:
|
|
|
|
command = 'removeHostRoute';
|
|
|
|
break;
|
|
|
|
default:
|
2015-06-04 03:04:18 +00:00
|
|
|
debug('Unknown action: ' + aAction);
|
2015-01-09 06:45:53 +00:00
|
|
|
return Promise.reject();
|
|
|
|
}
|
2014-08-06 05:51:00 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
let route = this._routeToString(aInterfaceName, aHost, aPrefixLength, aGateway);
|
2015-02-11 08:01:08 +00:00
|
|
|
let setupFunc = () => {
|
|
|
|
let count = this.addedRoutes.get(route);
|
2015-03-18 09:38:20 +00:00
|
|
|
debug(command + ": " + route + " -> " + count);
|
2015-02-11 08:01:08 +00:00
|
|
|
|
|
|
|
// Return false if there is no need to send the command to network worker.
|
2015-06-04 03:04:18 +00:00
|
|
|
if ((aAction == Ci.nsINetworkService.MODIFY_ROUTE_ADD && count) ||
|
|
|
|
(aAction == Ci.nsINetworkService.MODIFY_ROUTE_REMOVE &&
|
2015-02-11 08:01:08 +00:00
|
|
|
(!count || count > 1))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
debug(command + " " + aHost + " on " + aInterfaceName);
|
2013-11-15 09:35:33 +00:00
|
|
|
let options = {
|
2014-08-06 05:51:00 +00:00
|
|
|
cmd: command,
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
gateway: aGateway,
|
|
|
|
prefixLength: aPrefixLength,
|
|
|
|
ip: aHost
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
2015-02-11 08:01:08 +00:00
|
|
|
|
|
|
|
return new Promise((aResolve, aReject) => {
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, (aData) => {
|
2015-02-11 08:01:08 +00:00
|
|
|
let count = this.addedRoutes.get(route);
|
|
|
|
|
|
|
|
// Remove route from addedRoutes on success or failure.
|
2015-06-04 03:04:18 +00:00
|
|
|
if (aAction == Ci.nsINetworkService.MODIFY_ROUTE_REMOVE) {
|
2015-02-11 08:01:08 +00:00
|
|
|
if (count > 1) {
|
|
|
|
this.addedRoutes.set(route, count - 1);
|
|
|
|
} else {
|
|
|
|
this.addedRoutes.delete(route);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
if (aData.error) {
|
|
|
|
aReject(aData.reason);
|
2015-02-11 08:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
if (aAction == Ci.nsINetworkService.MODIFY_ROUTE_ADD) {
|
2015-02-11 08:01:08 +00:00
|
|
|
this.addedRoutes.set(route, count ? count + 1 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
aResolve();
|
|
|
|
}, setupFunc);
|
2014-08-06 05:51:00 +00:00
|
|
|
});
|
2013-11-15 09:35:33 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
addSecondaryRoute: function(aInterfaceName, aRoute, aCallback) {
|
|
|
|
debug("Going to add route to secondary table on " + aInterfaceName);
|
2014-02-24 14:19:20 +00:00
|
|
|
let options = {
|
|
|
|
cmd: "addSecondaryRoute",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
ip: aRoute.ip,
|
|
|
|
prefix: aRoute.prefix,
|
|
|
|
gateway: aRoute.gateway
|
2014-02-24 14:19:20 +00:00
|
|
|
};
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-05-05 03:48:00 +00:00
|
|
|
});
|
2014-02-24 14:19:20 +00:00
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
removeSecondaryRoute: function(aInterfaceName, aRoute, aCallback) {
|
|
|
|
debug("Going to remove route from secondary table on " + aInterfaceName);
|
2014-02-24 14:19:20 +00:00
|
|
|
let options = {
|
|
|
|
cmd: "removeSecondaryRoute",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName,
|
|
|
|
ip: aRoute.ip,
|
|
|
|
prefix: aRoute.prefix,
|
|
|
|
gateway: aRoute.gateway
|
2014-02-24 14:19:20 +00:00
|
|
|
};
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(options, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-05-05 03:48:00 +00:00
|
|
|
});
|
2014-02-24 14:19:20 +00:00
|
|
|
},
|
|
|
|
|
2013-11-15 09:35:33 +00:00
|
|
|
// Enable/Disable DHCP server.
|
2015-06-04 03:04:18 +00:00
|
|
|
setDhcpServer: function(aEnabled, aConfig, aCallback) {
|
|
|
|
if (null === aConfig) {
|
|
|
|
aConfig = {};
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
aConfig.cmd = "setDhcpServer";
|
|
|
|
aConfig.enabled = aEnabled;
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(aConfig, function(aResponse) {
|
|
|
|
if (!aResponse.success) {
|
|
|
|
aCallback.dhcpServerResult('Set DHCP server error');
|
2013-11-15 09:35:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.dhcpServerResult(null);
|
2013-11-15 09:35:33 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Enable/disable WiFi tethering by sending commands to netd.
|
2015-06-04 03:04:18 +00:00
|
|
|
setWifiTethering: function(aEnable, aConfig, aCallback) {
|
2013-11-15 09:35:33 +00:00
|
|
|
// config should've already contained:
|
|
|
|
// .ifname
|
|
|
|
// .internalIfname
|
|
|
|
// .externalIfname
|
2015-06-04 03:04:18 +00:00
|
|
|
aConfig.wifictrlinterfacename = WIFI_CTRL_INTERFACE;
|
|
|
|
aConfig.cmd = "setWifiTethering";
|
2013-11-15 09:35:33 +00:00
|
|
|
|
|
|
|
// The callback function in controlMessage may not be fired immediately.
|
2015-07-24 11:16:02 +00:00
|
|
|
this.controlMessage(aConfig, (aData) => {
|
2015-06-04 03:04:18 +00:00
|
|
|
let code = aData.resultCode;
|
|
|
|
let reason = aData.resultReason;
|
|
|
|
let enable = aData.enable;
|
|
|
|
let enableString = aEnable ? "Enable" : "Disable";
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-03-18 09:38:20 +00:00
|
|
|
debug(enableString + " Wifi tethering result: Code " + code + " reason " + reason);
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-07-24 11:16:02 +00:00
|
|
|
this.setNetworkTetheringAlarm(aEnable, aConfig.externalIfname);
|
|
|
|
|
2013-11-15 09:35:33 +00:00
|
|
|
if (isError(code)) {
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.wifiTetheringEnabledChange("netd command error");
|
2013-11-15 09:35:33 +00:00
|
|
|
} else {
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.wifiTetheringEnabledChange(null);
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Enable/disable USB tethering by sending commands to netd.
|
2015-06-04 03:04:18 +00:00
|
|
|
setUSBTethering: function(aEnable, aConfig, aCallback) {
|
|
|
|
aConfig.cmd = "setUSBTethering";
|
2013-11-15 09:35:33 +00:00
|
|
|
// The callback function in controlMessage may not be fired immediately.
|
2015-07-24 11:16:02 +00:00
|
|
|
this.controlMessage(aConfig, (aData) => {
|
2015-06-04 03:04:18 +00:00
|
|
|
let code = aData.resultCode;
|
|
|
|
let reason = aData.resultReason;
|
|
|
|
let enable = aData.enable;
|
|
|
|
let enableString = aEnable ? "Enable" : "Disable";
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-03-18 09:38:20 +00:00
|
|
|
debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
|
2013-11-15 09:35:33 +00:00
|
|
|
|
2015-07-24 11:16:02 +00:00
|
|
|
this.setNetworkTetheringAlarm(aEnable, aConfig.externalIfname);
|
|
|
|
|
2013-11-15 09:35:33 +00:00
|
|
|
if (isError(code)) {
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.usbTetheringEnabledChange("netd command error");
|
2013-11-15 09:35:33 +00:00
|
|
|
} else {
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.usbTetheringEnabledChange(null);
|
2013-11-15 09:35:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Switch usb function by modifying property of persist.sys.usb.config.
|
2015-06-04 03:04:18 +00:00
|
|
|
enableUsbRndis: function(aEnable, aCallback) {
|
|
|
|
debug("enableUsbRndis: " + aEnable);
|
2013-11-15 09:35:33 +00:00
|
|
|
|
|
|
|
let params = {
|
|
|
|
cmd: "enableUsbRndis",
|
2015-06-04 03:04:18 +00:00
|
|
|
enable: aEnable
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
|
|
|
// Ask net work to report the result when this value is set to true.
|
2015-06-04 03:04:18 +00:00
|
|
|
if (aCallback) {
|
2013-11-15 09:35:33 +00:00
|
|
|
params.report = true;
|
|
|
|
} else {
|
|
|
|
params.report = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The callback function in controlMessage may not be fired immediately.
|
|
|
|
//this._usbTetheringAction = TETHERING_STATE_ONGOING;
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aData) {
|
|
|
|
aCallback.enableUsbRndisResult(aData.result, aData.enable);
|
2013-11-15 09:35:33 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
updateUpStream: function(aPrevious, aCurrent, aCallback) {
|
2013-11-15 09:35:33 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "updateUpStream",
|
2015-06-04 03:04:18 +00:00
|
|
|
preInternalIfname: aPrevious.internalIfname,
|
|
|
|
preExternalIfname: aPrevious.externalIfname,
|
|
|
|
curInternalIfname: aCurrent.internalIfname,
|
|
|
|
curExternalIfname: aCurrent.externalIfname
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aData) {
|
|
|
|
let code = aData.resultCode;
|
|
|
|
let reason = aData.resultReason;
|
2015-03-18 09:38:20 +00:00
|
|
|
debug("updateUpStream result: Code " + code + " reason " + reason);
|
2015-06-04 03:04:18 +00:00
|
|
|
aCallback.updateUpStreamResult(!isError(code), aData.curExternalIfname);
|
2013-11-15 09:35:33 +00:00
|
|
|
});
|
|
|
|
},
|
2014-01-29 11:38:50 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
configureInterface: function(aConfig, aCallback) {
|
2014-08-18 03:02:56 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "configureInterface",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aConfig.ifname,
|
|
|
|
ipaddr: aConfig.ipaddr,
|
|
|
|
mask: aConfig.mask,
|
|
|
|
gateway_long: aConfig.gateway,
|
|
|
|
dns1_long: aConfig.dns1,
|
|
|
|
dns2_long: aConfig.dns2,
|
2014-08-18 03:02:56 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
dhcpRequest: function(aInterfaceName, aCallback) {
|
2014-08-18 03:02:56 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "dhcpRequest",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2014-08-18 03:02:56 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.dhcpRequestResult(!aResult.error, aResult.error ? null : aResult);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
stopDhcp: function(aInterfaceName, aCallback) {
|
2015-05-18 09:41:10 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "stopDhcp",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2015-05-18 09:41:10 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-05-18 09:41:10 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
enableInterface: function(aInterfaceName, aCallback) {
|
2014-08-18 03:02:56 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "enableInterface",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2014-08-18 03:02:56 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
disableInterface: function(aInterfaceName, aCallback) {
|
2014-08-18 03:02:56 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "disableInterface",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2014-08-18 03:02:56 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
resetConnections: function(aInterfaceName, aCallback) {
|
2014-08-18 03:02:56 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "resetConnections",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2014-08-18 03:02:56 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2014-08-18 03:02:56 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
createNetwork: function(aInterfaceName, aCallback) {
|
2015-01-09 06:45:53 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "createNetwork",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2015-01-09 06:45:53 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-01-09 06:45:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
destroyNetwork: function(aInterfaceName, aCallback) {
|
2015-01-09 06:45:53 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "destroyNetwork",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2015-01-09 06:45:53 +00:00
|
|
|
};
|
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
this.controlMessage(params, function(aResult) {
|
|
|
|
aCallback.nativeCommandResult(!aResult.error);
|
2015-01-09 06:45:53 +00:00
|
|
|
});
|
|
|
|
},
|
2015-04-09 11:09:37 +00:00
|
|
|
|
2015-06-04 03:04:18 +00:00
|
|
|
getNetId: function(aInterfaceName) {
|
2015-04-09 11:09:37 +00:00
|
|
|
let params = {
|
|
|
|
cmd: "getNetId",
|
2015-06-04 03:04:18 +00:00
|
|
|
ifname: aInterfaceName
|
2015-04-09 11:09:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return new Promise((aResolve, aReject) => {
|
|
|
|
this.controlMessage(params, result => {
|
|
|
|
if (result.error) {
|
|
|
|
aReject(result.reason);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aResolve(result.netId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2013-11-15 09:35:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkService]);
|