mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
Bug 935363 - Add and make use of NetworkService xpcom. r=vyang, r=vchang
This commit is contained in:
parent
e4c2f99011
commit
091bb44eef
@ -411,6 +411,8 @@
|
|||||||
@BINPATH@/components/NetworkInterfaceListService.manifest
|
@BINPATH@/components/NetworkInterfaceListService.manifest
|
||||||
@BINPATH@/components/NetworkManager.js
|
@BINPATH@/components/NetworkManager.js
|
||||||
@BINPATH@/components/NetworkManager.manifest
|
@BINPATH@/components/NetworkManager.manifest
|
||||||
|
@BINPATH@/components/NetworkService.js
|
||||||
|
@BINPATH@/components/NetworkService.manifest
|
||||||
@BINPATH@/components/NetworkStatsManager.js
|
@BINPATH@/components/NetworkStatsManager.js
|
||||||
@BINPATH@/components/NetworkStatsManager.manifest
|
@BINPATH@/components/NetworkStatsManager.manifest
|
||||||
@BINPATH@/components/NetworkStatsServiceProxy.js
|
@BINPATH@/components/NetworkStatsServiceProxy.js
|
||||||
|
@ -38,6 +38,11 @@ XPCOMUtils.defineLazyServiceGetter(this, "networkManager",
|
|||||||
"@mozilla.org/network/manager;1",
|
"@mozilla.org/network/manager;1",
|
||||||
"nsINetworkManager");
|
"nsINetworkManager");
|
||||||
|
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyServiceGetter(this, "networkService",
|
||||||
|
"@mozilla.org/network/service;1",
|
||||||
|
"nsINetworkService");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
XPCOMUtils.defineLazyServiceGetter(this, "appsService",
|
||||||
"@mozilla.org/AppsService;1",
|
"@mozilla.org/AppsService;1",
|
||||||
"nsIAppsService");
|
"nsIAppsService");
|
||||||
@ -429,7 +434,7 @@ this.NetworkStatsService = {
|
|||||||
// Request stats to NetworkManager, which will get stats from netd, passing
|
// Request stats to NetworkManager, which will get stats from netd, passing
|
||||||
// 'networkStatsAvailable' as a callback.
|
// 'networkStatsAvailable' as a callback.
|
||||||
if (interfaceName) {
|
if (interfaceName) {
|
||||||
networkManager.getNetworkInterfaceStats(interfaceName,
|
networkService.getNetworkInterfaceStats(interfaceName,
|
||||||
this.networkStatsAvailable.bind(this, aCallback, aNetId));
|
this.networkStatsAvailable.bind(this, aCallback, aNetId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,6 @@ Cu.import("resource://gre/modules/FileUtils.jsm");
|
|||||||
const NETWORKMANAGER_CONTRACTID = "@mozilla.org/network/manager;1";
|
const NETWORKMANAGER_CONTRACTID = "@mozilla.org/network/manager;1";
|
||||||
const NETWORKMANAGER_CID =
|
const NETWORKMANAGER_CID =
|
||||||
Components.ID("{33901e46-33b8-11e1-9869-f46d04d25bcc}");
|
Components.ID("{33901e46-33b8-11e1-9869-f46d04d25bcc}");
|
||||||
const NETWORKINTERFACE_CONTRACTID = "@mozilla.org/network/interface;1";
|
|
||||||
const NETWORKINTERFACE_CID =
|
|
||||||
Components.ID("{266c3edd-78f0-4512-8178-2d6fee2d35ee}");
|
|
||||||
|
|
||||||
const DEFAULT_PREFERRED_NETWORK_TYPE = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
|
const DEFAULT_PREFERRED_NETWORK_TYPE = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
|
||||||
|
|
||||||
@ -31,6 +28,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gDNSService",
|
|||||||
"@mozilla.org/network/dns-service;1",
|
"@mozilla.org/network/dns-service;1",
|
||||||
"nsIDNSService");
|
"nsIDNSService");
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyServiceGetter(this, "gNetworkService",
|
||||||
|
"@mozilla.org/network/service;1",
|
||||||
|
"nsINetworkService");
|
||||||
|
|
||||||
const TOPIC_INTERFACE_STATE_CHANGED = "network-interface-state-changed";
|
const TOPIC_INTERFACE_STATE_CHANGED = "network-interface-state-changed";
|
||||||
const TOPIC_INTERFACE_REGISTERED = "network-interface-registered";
|
const TOPIC_INTERFACE_REGISTERED = "network-interface-registered";
|
||||||
const TOPIC_INTERFACE_UNREGISTERED = "network-interface-unregistered";
|
const TOPIC_INTERFACE_UNREGISTERED = "network-interface-unregistered";
|
||||||
@ -51,18 +52,6 @@ const KERNEL_NETWORK_ENTRY = "/sys/class/net";
|
|||||||
const TETHERING_TYPE_WIFI = "WiFi";
|
const TETHERING_TYPE_WIFI = "WiFi";
|
||||||
const TETHERING_TYPE_USB = "USB";
|
const TETHERING_TYPE_USB = "USB";
|
||||||
|
|
||||||
// 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_FIRMWARE_AP = "AP";
|
const WIFI_FIRMWARE_AP = "AP";
|
||||||
const WIFI_FIRMWARE_STATION = "STA";
|
const WIFI_FIRMWARE_STATION = "STA";
|
||||||
const WIFI_SECURITY_TYPE_NONE = "open";
|
const WIFI_SECURITY_TYPE_NONE = "open";
|
||||||
@ -101,24 +90,8 @@ const DEFAULT_DNS2 = "8.8.4.4";
|
|||||||
const DEFAULT_WIFI_DHCPSERVER_STARTIP = "192.168.1.10";
|
const DEFAULT_WIFI_DHCPSERVER_STARTIP = "192.168.1.10";
|
||||||
const DEFAULT_WIFI_DHCPSERVER_ENDIP = "192.168.1.30";
|
const DEFAULT_WIFI_DHCPSERVER_ENDIP = "192.168.1.30";
|
||||||
|
|
||||||
const MANUAL_PROXY_CONFIGURATION = 1;
|
|
||||||
|
|
||||||
const DEBUG = false;
|
const DEBUG = false;
|
||||||
|
|
||||||
function netdResponseType(code) {
|
|
||||||
return Math.floor(code/100)*100;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isError(code) {
|
|
||||||
let type = netdResponseType(code);
|
|
||||||
return (type != NETD_COMMAND_PROCEEDING && type != NETD_COMMAND_OKAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isComplete(code) {
|
|
||||||
let type = netdResponseType(code);
|
|
||||||
return (type != NETD_COMMAND_PROCEEDING);
|
|
||||||
}
|
|
||||||
|
|
||||||
function defineLazyRegExp(obj, name, pattern) {
|
function defineLazyRegExp(obj, name, pattern) {
|
||||||
obj.__defineGetter__(name, function() {
|
obj.__defineGetter__(name, function() {
|
||||||
delete obj[name];
|
delete obj[name];
|
||||||
@ -140,19 +113,6 @@ function NetworkManager() {
|
|||||||
Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
|
Services.obs.addObserver(this, TOPIC_XPCOM_SHUTDOWN, false);
|
||||||
Services.obs.addObserver(this, TOPIC_MOZSETTINGS_CHANGED, false);
|
Services.obs.addObserver(this, TOPIC_MOZSETTINGS_CHANGED, false);
|
||||||
|
|
||||||
debug("Starting worker.");
|
|
||||||
this.worker = new ChromeWorker("resource://gre/modules/net_worker.js");
|
|
||||||
this.worker.onmessage = this.handleWorkerMessage.bind(this);
|
|
||||||
this.worker.onerror = function onerror(event) {
|
|
||||||
debug("Received error from worker: " + event.filename +
|
|
||||||
":" + event.lineno + ": " + event.message + "\n");
|
|
||||||
// Prevent the event from bubbling any further.
|
|
||||||
event.preventDefault();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Callbacks to invoke when a reply arrives from the net_worker.
|
|
||||||
this.controlCallbacks = Object.create(null);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this._manageOfflineStatus =
|
this._manageOfflineStatus =
|
||||||
Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
|
Services.prefs.getBoolPref(PREF_MANAGE_OFFLINE_STATUS);
|
||||||
@ -219,13 +179,8 @@ NetworkManager.prototype = {
|
|||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkManager,
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkManager,
|
||||||
Ci.nsISupportsWeakReference,
|
Ci.nsISupportsWeakReference,
|
||||||
Ci.nsIObserver,
|
Ci.nsIObserver,
|
||||||
Ci.nsIWorkerHolder,
|
|
||||||
Ci.nsISettingsServiceCallback]),
|
Ci.nsISettingsServiceCallback]),
|
||||||
|
|
||||||
// nsIWorkerHolder
|
|
||||||
|
|
||||||
worker: null,
|
|
||||||
|
|
||||||
// nsIObserver
|
// nsIObserver
|
||||||
|
|
||||||
observe: function observe(subject, topic, data) {
|
observe: function observe(subject, topic, data) {
|
||||||
@ -240,15 +195,15 @@ NetworkManager.prototype = {
|
|||||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||||
this.removeHostRoutes(network.name);
|
gNetworkService.removeHostRoutes(network.name);
|
||||||
this.addHostRoute(network);
|
gNetworkService.addHostRoute(network);
|
||||||
}
|
}
|
||||||
// Add extra host route. For example, mms proxy or mmsc.
|
// Add extra host route. For example, mms proxy or mmsc.
|
||||||
this.setExtraHostRoute(network);
|
this.setExtraHostRoute(network);
|
||||||
#endif
|
#endif
|
||||||
// Remove pre-created default route and let setAndConfigureActive()
|
// Remove pre-created default route and let setAndConfigureActive()
|
||||||
// to set default route only on preferred network
|
// to set default route only on preferred network
|
||||||
this.removeDefaultRoute(network.name);
|
gNetworkService.removeDefaultRoute(network.name);
|
||||||
this.setAndConfigureActive();
|
this.setAndConfigureActive();
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
// Update data connection when Wifi connected/disconnected
|
// Update data connection when Wifi connected/disconnected
|
||||||
@ -271,17 +226,17 @@ NetworkManager.prototype = {
|
|||||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||||
this.removeHostRoute(network);
|
gNetworkService.removeHostRoute(network);
|
||||||
}
|
}
|
||||||
// Remove extra host route. For example, mms proxy or mmsc.
|
// Remove extra host route. For example, mms proxy or mmsc.
|
||||||
this.removeExtraHostRoute(network);
|
this.removeExtraHostRoute(network);
|
||||||
#endif
|
#endif
|
||||||
// Remove routing table in /proc/net/route
|
// Remove routing table in /proc/net/route
|
||||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_WIFI) {
|
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_WIFI) {
|
||||||
this.resetRoutingTable(network);
|
gNetworkService.resetRoutingTable(network);
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
} else if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE) {
|
} else if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE) {
|
||||||
this.removeDefaultRoute(network.name);
|
gNetworkService.removeDefaultRoute(network.name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,12 +340,12 @@ NetworkManager.prototype = {
|
|||||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||||
this.addHostRoute(network);
|
gNetworkService.addHostRoute(network);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Remove pre-created default route and let setAndConfigureActive()
|
// Remove pre-created default route and let setAndConfigureActive()
|
||||||
// to set default route only on preferred network
|
// to set default route only on preferred network
|
||||||
this.removeDefaultRoute(network.name);
|
gNetworkService.removeDefaultRoute(network.name);
|
||||||
this.setAndConfigureActive();
|
this.setAndConfigureActive();
|
||||||
Services.obs.notifyObservers(network, TOPIC_INTERFACE_REGISTERED, null);
|
Services.obs.notifyObservers(network, TOPIC_INTERFACE_REGISTERED, null);
|
||||||
debug("Network '" + network.name + "' registered.");
|
debug("Network '" + network.name + "' registered.");
|
||||||
@ -411,7 +366,7 @@ NetworkManager.prototype = {
|
|||||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||||
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||||
this.removeHostRoute(network);
|
gNetworkService.removeHostRoute(network);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this.setAndConfigureActive();
|
this.setAndConfigureActive();
|
||||||
@ -456,73 +411,6 @@ NetworkManager.prototype = {
|
|||||||
this.setAndConfigureActive();
|
this.setAndConfigureActive();
|
||||||
},
|
},
|
||||||
|
|
||||||
getNetworkInterfaceStats: function getNetworkInterfaceStats(networkName, callback) {
|
|
||||||
debug("getNetworkInterfaceStats for " + networkName);
|
|
||||||
|
|
||||||
let params = {
|
|
||||||
cmd: "getNetworkInterfaceStats",
|
|
||||||
ifname: networkName
|
|
||||||
};
|
|
||||||
|
|
||||||
params.report = true;
|
|
||||||
params.isAsync = true;
|
|
||||||
|
|
||||||
this.controlMessage(params, function(result) {
|
|
||||||
let success = result.resultCode >= NETD_COMMAND_OKAY &&
|
|
||||||
result.resultCode < NETD_COMMAND_ERROR;
|
|
||||||
callback.networkStatsAvailable(success, result.rxBytes,
|
|
||||||
result.txBytes, result.date);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
setWifiOperationMode: function setWifiOperationMode(interfaceName, mode, callback) {
|
|
||||||
debug("setWifiOperationMode on " + interfaceName + " to " + mode);
|
|
||||||
|
|
||||||
let params = {
|
|
||||||
cmd: "setWifiOperationMode",
|
|
||||||
ifname: interfaceName,
|
|
||||||
mode: mode
|
|
||||||
};
|
|
||||||
|
|
||||||
params.report = true;
|
|
||||||
params.isAsync = true;
|
|
||||||
|
|
||||||
this.controlMessage(params, function(result) {
|
|
||||||
if (isError(result.resultCode)) {
|
|
||||||
callback.wifiOperationModeResult("netd command error");
|
|
||||||
} else {
|
|
||||||
callback.wifiOperationModeResult(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// Helpers
|
|
||||||
|
|
||||||
idgen: 0,
|
|
||||||
controlMessage: function controlMessage(params, callback) {
|
|
||||||
if (callback) {
|
|
||||||
let id = this.idgen++;
|
|
||||||
params.id = id;
|
|
||||||
this.controlCallbacks[id] = callback;
|
|
||||||
}
|
|
||||||
this.worker.postMessage(params);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleWorkerMessage: function handleWorkerMessage(e) {
|
|
||||||
debug("NetworkManager received message from worker: " + JSON.stringify(e.data));
|
|
||||||
let response = e.data;
|
|
||||||
let id = response.id;
|
|
||||||
if (id == 'broadcast') {
|
|
||||||
Services.obs.notifyObservers(null, response.topic, response.reason);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let callback = this.controlCallbacks[id];
|
|
||||||
if (callback) {
|
|
||||||
callback.call(this, response);
|
|
||||||
delete this.controlCallbacks[id];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
setExtraHostRoute: function setExtraHostRoute(network) {
|
setExtraHostRoute: function setExtraHostRoute(network) {
|
||||||
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS) {
|
if (network.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS) {
|
||||||
@ -542,7 +430,7 @@ NetworkManager.prototype = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addHostRouteWithResolve(network, mmsHosts);
|
gNetworkService.addHostRouteWithResolve(network, mmsHosts);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -564,7 +452,7 @@ NetworkManager.prototype = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeHostRouteWithResolve(network, mmsHosts);
|
gNetworkService.removeHostRouteWithResolve(network, mmsHosts);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
#endif // MOZ_B2G_RIL
|
#endif // MOZ_B2G_RIL
|
||||||
@ -582,7 +470,7 @@ NetworkManager.prototype = {
|
|||||||
// The override was just set, so reconfigure the network.
|
// The override was just set, so reconfigure the network.
|
||||||
if (this.active != this._overriddenActive) {
|
if (this.active != this._overriddenActive) {
|
||||||
this.active = this._overriddenActive;
|
this.active = this._overriddenActive;
|
||||||
this.setDefaultRouteAndDNS(oldActive);
|
gNetworkService.setDefaultRouteAndDNS(this.active, oldActive);
|
||||||
Services.obs.notifyObservers(this.active, TOPIC_ACTIVE_CHANGED, null);
|
Services.obs.notifyObservers(this.active, TOPIC_ACTIVE_CHANGED, null);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -593,7 +481,7 @@ NetworkManager.prototype = {
|
|||||||
this.active.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED &&
|
this.active.state == Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED &&
|
||||||
this.active.type == this._preferredNetworkType) {
|
this.active.type == this._preferredNetworkType) {
|
||||||
debug("Active network is already our preferred type.");
|
debug("Active network is already our preferred type.");
|
||||||
this.setDefaultRouteAndDNS(oldActive);
|
gNetworkService.setDefaultRouteAndDNS(this.active, oldActive);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,10 +521,10 @@ NetworkManager.prototype = {
|
|||||||
// Don't set default route on secondary APN
|
// Don't set default route on secondary APN
|
||||||
if (this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
if (this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||
|
||||||
this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
this.active.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_SUPL) {
|
||||||
this.setDNS(this.active);
|
gNetworkService.setDNS(this.active);
|
||||||
} else {
|
} else {
|
||||||
#endif // MOZ_B2G_RIL
|
#endif // MOZ_B2G_RIL
|
||||||
this.setDefaultRouteAndDNS(oldActive);
|
gNetworkService.setDefaultRouteAndDNS(this.active, oldActive);
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -650,88 +538,7 @@ NetworkManager.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
resetRoutingTable: function resetRoutingTable(network) {
|
|
||||||
if (!network.ip || !network.netmask) {
|
|
||||||
debug("Either ip or netmask is null. Cannot reset routing table.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let options = {
|
|
||||||
cmd: "removeNetworkRoute",
|
|
||||||
ifname: network.name,
|
|
||||||
ip : network.ip,
|
|
||||||
netmask: network.netmask,
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
|
|
||||||
#ifdef MOZ_B2G_RIL
|
#ifdef MOZ_B2G_RIL
|
||||||
setDNS: function setDNS(networkInterface) {
|
|
||||||
debug("Going DNS to " + networkInterface.name);
|
|
||||||
let options = {
|
|
||||||
cmd: "setDNS",
|
|
||||||
ifname: networkInterface.name,
|
|
||||||
dns1_str: networkInterface.dns1,
|
|
||||||
dns2_str: networkInterface.dns2
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
#endif
|
|
||||||
|
|
||||||
setDefaultRouteAndDNS: function setDefaultRouteAndDNS(oldInterface) {
|
|
||||||
debug("Going to change route and DNS to " + this.active.name);
|
|
||||||
let options = {
|
|
||||||
cmd: "setDefaultRouteAndDNS",
|
|
||||||
ifname: this.active.name,
|
|
||||||
oldIfname: (oldInterface && oldInterface != this.active) ? oldInterface.name : null,
|
|
||||||
gateway_str: this.active.gateway,
|
|
||||||
dns1_str: this.active.dns1,
|
|
||||||
dns2_str: this.active.dns2
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
this.setNetworkProxy(this.active);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeDefaultRoute: function removeDefaultRoute(ifname) {
|
|
||||||
debug("Remove default route for " + ifname);
|
|
||||||
let options = {
|
|
||||||
cmd: "removeDefaultRoute",
|
|
||||||
ifname: ifname
|
|
||||||
}
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
|
|
||||||
#ifdef MOZ_B2G_RIL
|
|
||||||
addHostRoute: function addHostRoute(network) {
|
|
||||||
debug("Going to add host route on " + network.name);
|
|
||||||
let options = {
|
|
||||||
cmd: "addHostRoute",
|
|
||||||
ifname: network.name,
|
|
||||||
gateway: network.gateway,
|
|
||||||
hostnames: [network.dns1, network.dns2, network.httpProxyHost]
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeHostRoute: function removeHostRoute(network) {
|
|
||||||
debug("Going to remove host route on " + network.name);
|
|
||||||
let options = {
|
|
||||||
cmd: "removeHostRoute",
|
|
||||||
ifname: network.name,
|
|
||||||
gateway: network.gateway,
|
|
||||||
hostnames: [network.dns1, network.dns2, network.httpProxyHost]
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeHostRoutes: function removeHostRoutes(ifname) {
|
|
||||||
debug("Going to remove all host routes on " + ifname);
|
|
||||||
let options = {
|
|
||||||
cmd: "removeHostRoutes",
|
|
||||||
ifname: ifname,
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
|
|
||||||
resolveHostname: function resolveHostname(hosts) {
|
resolveHostname: function resolveHostname(hosts) {
|
||||||
let retval = [];
|
let retval = [];
|
||||||
|
|
||||||
@ -765,60 +572,7 @@ NetworkManager.prototype = {
|
|||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
},
|
},
|
||||||
|
#endif
|
||||||
addHostRouteWithResolve: function addHostRouteWithResolve(network, hosts) {
|
|
||||||
debug("Going to add host route after dns resolution on " + network.name);
|
|
||||||
let options = {
|
|
||||||
cmd: "addHostRoute",
|
|
||||||
ifname: network.name,
|
|
||||||
gateway: network.gateway,
|
|
||||||
hostnames: hosts
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
|
|
||||||
removeHostRouteWithResolve: function removeHostRouteWithResolve(network, hosts) {
|
|
||||||
debug("Going to remove host route after dns resolution on " + network.name);
|
|
||||||
let options = {
|
|
||||||
cmd: "removeHostRoute",
|
|
||||||
ifname: network.name,
|
|
||||||
gateway: network.gateway,
|
|
||||||
hostnames: hosts
|
|
||||||
};
|
|
||||||
this.worker.postMessage(options);
|
|
||||||
},
|
|
||||||
#endif // MOZ_B2G_RIL
|
|
||||||
|
|
||||||
setNetworkProxy: function setNetworkProxy(network) {
|
|
||||||
try {
|
|
||||||
if (!network.httpProxyHost || network.httpProxyHost == "") {
|
|
||||||
// Sets direct connection to internet.
|
|
||||||
Services.prefs.clearUserPref("network.proxy.type");
|
|
||||||
Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
|
|
||||||
Services.prefs.clearUserPref("network.proxy.http");
|
|
||||||
Services.prefs.clearUserPref("network.proxy.http_port");
|
|
||||||
Services.prefs.clearUserPref("network.proxy.ssl");
|
|
||||||
Services.prefs.clearUserPref("network.proxy.ssl_port");
|
|
||||||
debug("No proxy support for " + network.name + " network interface.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug("Going to set proxy settings for " + network.name + " network interface.");
|
|
||||||
// Sets manual proxy configuration.
|
|
||||||
Services.prefs.setIntPref("network.proxy.type", MANUAL_PROXY_CONFIGURATION);
|
|
||||||
// Do not use this proxy server for all protocols.
|
|
||||||
Services.prefs.setBoolPref("network.proxy.share_proxy_settings", false);
|
|
||||||
Services.prefs.setCharPref("network.proxy.http", network.httpProxyHost);
|
|
||||||
Services.prefs.setCharPref("network.proxy.ssl", network.httpProxyHost);
|
|
||||||
let port = network.httpProxyPort == 0 ? 8080 : network.httpProxyPort;
|
|
||||||
Services.prefs.setIntPref("network.proxy.http_port", port);
|
|
||||||
Services.prefs.setIntPref("network.proxy.ssl_port", port);
|
|
||||||
} catch (ex) {
|
|
||||||
debug("Exception " + ex + ". Unable to set proxy setting for "
|
|
||||||
+ network.name + " network interface.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// nsISettingsServiceCallback
|
// nsISettingsServiceCallback
|
||||||
|
|
||||||
@ -926,7 +680,7 @@ NetworkManager.prototype = {
|
|||||||
handleUSBTetheringToggle: function handleUSBTetheringToggle(enable) {
|
handleUSBTetheringToggle: function handleUSBTetheringToggle(enable) {
|
||||||
if (!enable) {
|
if (!enable) {
|
||||||
this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
|
this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
|
||||||
this.enableUsbRndis(false, this.enableUsbRndisResult);
|
gNetworkService.enableUsbRndis(false, this.enableUsbRndisResult.bind(this));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,7 +693,7 @@ NetworkManager.prototype = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.tetheringSettings[SETTINGS_USB_ENABLED] = true;
|
this.tetheringSettings[SETTINGS_USB_ENABLED] = true;
|
||||||
this.enableUsbRndis(true, this.enableUsbRndisResult);
|
gNetworkService.enableUsbRndis(true, this.enableUsbRndisResult.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
getUSBTetheringParameters: function getUSBTetheringParameters(enable, tetheringinterface) {
|
getUSBTetheringParameters: function getUSBTetheringParameters(enable, tetheringinterface) {
|
||||||
@ -1002,25 +756,6 @@ NetworkManager.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Enable/Disable DHCP server.
|
|
||||||
setDhcpServer: function setDhcpServer(enabled, config, callback) {
|
|
||||||
if (null === config) {
|
|
||||||
config = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
config.cmd = "setDhcpServer";
|
|
||||||
config.isAsync = true;
|
|
||||||
config.enabled = enabled;
|
|
||||||
|
|
||||||
this.controlMessage(config, function setDhcpServerResult(response) {
|
|
||||||
if (!response.success) {
|
|
||||||
callback.dhcpServerResult('Set DHCP server error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback.dhcpServerResult(null);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// Enable/disable WiFi tethering by sending commands to netd.
|
// Enable/disable WiFi tethering by sending commands to netd.
|
||||||
setWifiTethering: function setWifiTethering(enable, network, config, callback) {
|
setWifiTethering: function setWifiTethering(enable, network, config, callback) {
|
||||||
if (!network) {
|
if (!network) {
|
||||||
@ -1044,25 +779,11 @@ NetworkManager.prototype = {
|
|||||||
config.ifname = this._tetheringInterface[TETHERING_TYPE_WIFI].internalInterface;
|
config.ifname = this._tetheringInterface[TETHERING_TYPE_WIFI].internalInterface;
|
||||||
config.internalIfname = this._tetheringInterface[TETHERING_TYPE_WIFI].internalInterface;
|
config.internalIfname = this._tetheringInterface[TETHERING_TYPE_WIFI].internalInterface;
|
||||||
config.externalIfname = this._tetheringInterface[TETHERING_TYPE_WIFI].externalInterface;
|
config.externalIfname = this._tetheringInterface[TETHERING_TYPE_WIFI].externalInterface;
|
||||||
config.wifictrlinterfacename = WIFI_CTRL_INTERFACE;
|
|
||||||
|
|
||||||
config.cmd = "setWifiTethering";
|
gNetworkService.setWifiTethering(enable, config, (function (error) {
|
||||||
// The callback function in controlMessage may not be fired immediately.
|
let resetSettings = error;
|
||||||
config.isAsync = true;
|
this.notifyError(resetSettings, callback, error);
|
||||||
this.controlMessage(config, function setWifiTetheringResult(data) {
|
}).bind(this));
|
||||||
let code = data.resultCode;
|
|
||||||
let reason = data.resultReason;
|
|
||||||
let enable = data.enable;
|
|
||||||
let enableString = enable ? "Enable" : "Disable";
|
|
||||||
|
|
||||||
debug(enableString + " Wifi tethering result: Code " + code + " reason " + reason);
|
|
||||||
|
|
||||||
if (isError(code)) {
|
|
||||||
this.notifyError(true, callback, "netd command error");
|
|
||||||
} else {
|
|
||||||
this.notifyError(false, callback, null);
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Enable/disable USB tethering by sending commands to netd.
|
// Enable/disable USB tethering by sending commands to netd.
|
||||||
@ -1072,20 +793,13 @@ NetworkManager.prototype = {
|
|||||||
let params = this.getUSBTetheringParameters(enable, tetheringInterface);
|
let params = this.getUSBTetheringParameters(enable, tetheringInterface);
|
||||||
|
|
||||||
if (params === null) {
|
if (params === null) {
|
||||||
params = {
|
gNetworkService.enableUsbRndis(false, function() {
|
||||||
enable: enable,
|
this.usbTetheringResultReport("Invalid parameters");
|
||||||
resultCode: NETD_COMMAND_ERROR,
|
});
|
||||||
resultReason: "Invalid parameters"
|
|
||||||
};
|
|
||||||
this.enableUsbRndis(false, null);
|
|
||||||
this.usbTetheringResultReport(params);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
params.cmd = "setUSBTethering";
|
gNetworkService.setUSBTethering(enable, params, callback);
|
||||||
// The callback function in controlMessage may not be fired immediately.
|
|
||||||
params.isAsync = true;
|
|
||||||
this.controlMessage(params, callback);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getUsbInterface: function getUsbInterface() {
|
getUsbInterface: function getUsbInterface() {
|
||||||
@ -1105,56 +819,24 @@ NetworkManager.prototype = {
|
|||||||
return DEFAULT_USB_INTERFACE_NAME;
|
return DEFAULT_USB_INTERFACE_NAME;
|
||||||
},
|
},
|
||||||
|
|
||||||
enableUsbRndisResult: function enableUsbRndisResult(data) {
|
enableUsbRndisResult: function enableUsbRndisResult(success, enable) {
|
||||||
let result = data.result;
|
if (success) {
|
||||||
let enable = data.enable;
|
|
||||||
if (result) {
|
|
||||||
this._tetheringInterface[TETHERING_TYPE_USB].internalInterface = this.getUsbInterface();
|
this._tetheringInterface[TETHERING_TYPE_USB].internalInterface = this.getUsbInterface();
|
||||||
this.setUSBTethering(enable,
|
this.setUSBTethering(enable,
|
||||||
this._tetheringInterface[TETHERING_TYPE_USB],
|
this._tetheringInterface[TETHERING_TYPE_USB],
|
||||||
this.usbTetheringResultReport);
|
this.usbTetheringResultReport.bind(this));
|
||||||
} else {
|
} else {
|
||||||
let params = {
|
this.usbTetheringResultReport("Failed to set usb function");
|
||||||
enable: false,
|
|
||||||
resultCode: NETD_COMMAND_ERROR,
|
|
||||||
resultReason: "Failed to set usb function"
|
|
||||||
};
|
|
||||||
this.usbTetheringResultReport(params);
|
|
||||||
throw new Error("failed to set USB Function to adb");
|
throw new Error("failed to set USB Function to adb");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Switch usb function by modifying property of persist.sys.usb.config.
|
|
||||||
enableUsbRndis: function enableUsbRndis(enable, callback) {
|
|
||||||
debug("enableUsbRndis: " + enable);
|
|
||||||
|
|
||||||
let params = {
|
usbTetheringResultReport: function usbTetheringResultReport(error) {
|
||||||
cmd: "enableUsbRndis",
|
|
||||||
enable: enable
|
|
||||||
};
|
|
||||||
// Ask net work to report the result when this value is set to true.
|
|
||||||
if (callback) {
|
|
||||||
params.report = true;
|
|
||||||
} else {
|
|
||||||
params.report = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The callback function in controlMessage may not be fired immediately.
|
|
||||||
params.isAsync = true;
|
|
||||||
this._usbTetheringAction = TETHERING_STATE_ONGOING;
|
|
||||||
this.controlMessage(params, callback);
|
|
||||||
},
|
|
||||||
|
|
||||||
usbTetheringResultReport: function usbTetheringResultReport(data) {
|
|
||||||
let code = data.resultCode;
|
|
||||||
let reason = data.resultReason;
|
|
||||||
let enable = data.enable;
|
|
||||||
let enableString = enable ? "Enable" : "Disable";
|
|
||||||
let settingsLock = gSettingsService.createLock();
|
let settingsLock = gSettingsService.createLock();
|
||||||
|
|
||||||
debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
|
|
||||||
this._usbTetheringAction = TETHERING_STATE_IDLE;
|
this._usbTetheringAction = TETHERING_STATE_IDLE;
|
||||||
// Disable tethering settings when fail to enable it.
|
// Disable tethering settings when fail to enable it.
|
||||||
if (isError(code)) {
|
if (error) {
|
||||||
this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
|
this.tetheringSettings[SETTINGS_USB_ENABLED] = false;
|
||||||
settingsLock.set("tethering.usb.enabled", false, null);
|
settingsLock.set("tethering.usb.enabled", false, null);
|
||||||
// Skip others request when we found an error.
|
// Skip others request when we found an error.
|
||||||
@ -1162,31 +844,15 @@ NetworkManager.prototype = {
|
|||||||
} else {
|
} else {
|
||||||
this.handleLastRequest();
|
this.handleLastRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUpStream: function updateUpStream(previous, current, callback) {
|
onConnectionChangedReport: function onConnectionChangedReport(success, externalIfname) {
|
||||||
let params = {
|
debug("onConnectionChangedReport result: success " + success);
|
||||||
cmd: "updateUpStream",
|
|
||||||
isAsync: true,
|
|
||||||
previous: previous,
|
|
||||||
current: current
|
|
||||||
};
|
|
||||||
|
|
||||||
this.controlMessage(params, callback);
|
if (success) {
|
||||||
},
|
|
||||||
|
|
||||||
onConnectionChangedReport: function onConnectionChangedReport(data) {
|
|
||||||
let code = data.resultCode;
|
|
||||||
let reason = data.resultReason;
|
|
||||||
|
|
||||||
debug("onConnectionChangedReport result: Code " + code + " reason " + reason);
|
|
||||||
|
|
||||||
if (!isError(code)) {
|
|
||||||
// Update the external interface.
|
// Update the external interface.
|
||||||
this._tetheringInterface[TETHERING_TYPE_USB]
|
this._tetheringInterface[TETHERING_TYPE_USB].externalInterface = externalIfname;
|
||||||
.externalInterface = data.current.externalIfname;
|
debug("Change the interface name to " + externalIfname);
|
||||||
debug("Change the interface name to " + data.current.externalIfname);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1220,7 +886,7 @@ NetworkManager.prototype = {
|
|||||||
let callback = (function () {
|
let callback = (function () {
|
||||||
// Update external network interface.
|
// Update external network interface.
|
||||||
debug("Update upstream interface to " + network.name);
|
debug("Update upstream interface to " + network.name);
|
||||||
this.updateUpStream(previous, current, this.onConnectionChangedReport);
|
gNetworkService.updateUpStream(previous, current, this.onConnectionChangedReport.bind(this));
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
|
|
||||||
if (this._usbTetheringAction === TETHERING_STATE_ONGOING) {
|
if (this._usbTetheringAction === TETHERING_STATE_ONGOING) {
|
||||||
|
386
dom/system/gonk/NetworkService.js
Normal file
386
dom/system/gonk/NetworkService.js
Normal file
@ -0,0 +1,386 @@
|
|||||||
|
/* 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");
|
||||||
|
|
||||||
|
const NETWORKSERVICE_CONTRACTID = "@mozilla.org/network/service;1";
|
||||||
|
const NETWORKSERVICE_CID = Components.ID("{a6c58260-46df-11e3-8f96-0800200c9a66}");
|
||||||
|
|
||||||
|
// 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";
|
||||||
|
|
||||||
|
const MANUAL_PROXY_CONFIGURATION = 1;
|
||||||
|
|
||||||
|
const DEBUG = false;
|
||||||
|
|
||||||
|
function netdResponseType(code) {
|
||||||
|
return Math.floor(code / 100) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isError(code) {
|
||||||
|
let type = netdResponseType(code);
|
||||||
|
return (type !== NETD_COMMAND_PROCEEDING && type !== NETD_COMMAND_OKAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
function debug(msg) {
|
||||||
|
dump("-*- NetworkService: " + msg + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component watches for network interfaces changing state and then
|
||||||
|
* adjusts routes etc. accordingly.
|
||||||
|
*/
|
||||||
|
function NetworkService() {
|
||||||
|
if(DEBUG) debug("Starting net_worker.");
|
||||||
|
this.worker = new ChromeWorker("resource://gre/modules/net_worker.js");
|
||||||
|
this.worker.onmessage = this.handleWorkerMessage.bind(this);
|
||||||
|
this.worker.onerror = function onerror(event) {
|
||||||
|
if(DEBUG) debug("Received error from worker: " + event.filename +
|
||||||
|
":" + event.lineno + ": " + event.message + "\n");
|
||||||
|
// Prevent the event from bubbling any further.
|
||||||
|
event.preventDefault();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Callbacks to invoke when a reply arrives from the net_worker.
|
||||||
|
this.controlCallbacks = Object.create(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
NetworkService.prototype = {
|
||||||
|
classID: NETWORKSERVICE_CID,
|
||||||
|
classInfo: XPCOMUtils.generateCI({classID: NETWORKSERVICE_CID,
|
||||||
|
contractID: NETWORKSERVICE_CONTRACTID,
|
||||||
|
classDescription: "Network Service",
|
||||||
|
interfaces: [Ci.nsINetworkService]}),
|
||||||
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkService,
|
||||||
|
Ci.nsISupportsWeakReference,
|
||||||
|
Ci.nsIWorkerHolder]),
|
||||||
|
|
||||||
|
// nsIWorkerHolder
|
||||||
|
|
||||||
|
worker: null,
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
|
||||||
|
idgen: 0,
|
||||||
|
controlMessage: function controlMessage(params, callback) {
|
||||||
|
if (callback) {
|
||||||
|
let id = this.idgen++;
|
||||||
|
params.id = id;
|
||||||
|
this.controlCallbacks[id] = callback;
|
||||||
|
}
|
||||||
|
this.worker.postMessage(params);
|
||||||
|
},
|
||||||
|
|
||||||
|
handleWorkerMessage: function handleWorkerMessage(e) {
|
||||||
|
if(DEBUG) debug("NetworkManager received message from worker: " + JSON.stringify(e.data));
|
||||||
|
let response = e.data;
|
||||||
|
let id = response.id;
|
||||||
|
if (id === 'broadcast') {
|
||||||
|
Services.obs.notifyObservers(null, response.topic, response.reason);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let callback = this.controlCallbacks[id];
|
||||||
|
if (callback) {
|
||||||
|
callback.call(this, response);
|
||||||
|
delete this.controlCallbacks[id];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// nsINetworkService
|
||||||
|
|
||||||
|
getNetworkInterfaceStats: function getNetworkInterfaceStats(networkName, callback) {
|
||||||
|
if(DEBUG) debug("getNetworkInterfaceStats for " + networkName);
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
cmd: "getNetworkInterfaceStats",
|
||||||
|
ifname: networkName
|
||||||
|
};
|
||||||
|
|
||||||
|
params.report = true;
|
||||||
|
params.isAsync = true;
|
||||||
|
|
||||||
|
this.controlMessage(params, function(result) {
|
||||||
|
let success = result.resultCode >= NETD_COMMAND_OKAY &&
|
||||||
|
result.resultCode < NETD_COMMAND_ERROR;
|
||||||
|
callback.networkStatsAvailable(success, result.rxBytes,
|
||||||
|
result.txBytes, result.date);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
setWifiOperationMode: function setWifiOperationMode(interfaceName, mode, callback) {
|
||||||
|
if(DEBUG) debug("setWifiOperationMode on " + interfaceName + " to " + mode);
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
cmd: "setWifiOperationMode",
|
||||||
|
ifname: interfaceName,
|
||||||
|
mode: mode
|
||||||
|
};
|
||||||
|
|
||||||
|
params.report = true;
|
||||||
|
params.isAsync = true;
|
||||||
|
|
||||||
|
this.controlMessage(params, function(result) {
|
||||||
|
if (isError(result.resultCode)) {
|
||||||
|
callback.wifiOperationModeResult("netd command error");
|
||||||
|
} else {
|
||||||
|
callback.wifiOperationModeResult(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
resetRoutingTable: function resetRoutingTable(network) {
|
||||||
|
if (!network.ip || !network.netmask) {
|
||||||
|
if(DEBUG) debug("Either ip or netmask is null. Cannot reset routing table.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let options = {
|
||||||
|
cmd: "removeNetworkRoute",
|
||||||
|
ifname: network.name,
|
||||||
|
ip: network.ip,
|
||||||
|
netmask: network.netmask
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
setDNS: function setDNS(networkInterface) {
|
||||||
|
if(DEBUG) debug("Going DNS to " + networkInterface.name);
|
||||||
|
let options = {
|
||||||
|
cmd: "setDNS",
|
||||||
|
ifname: networkInterface.name,
|
||||||
|
dns1_str: networkInterface.dns1,
|
||||||
|
dns2_str: networkInterface.dns2
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
setDefaultRouteAndDNS: function setDefaultRouteAndDNS(network, oldInterface) {
|
||||||
|
if(DEBUG) debug("Going to change route and DNS to " + network.name);
|
||||||
|
let options = {
|
||||||
|
cmd: "setDefaultRouteAndDNS",
|
||||||
|
ifname: network.name,
|
||||||
|
oldIfname: (oldInterface && oldInterface !== network) ? oldInterface.name : null,
|
||||||
|
gateway_str: network.gateway,
|
||||||
|
dns1_str: network.dns1,
|
||||||
|
dns2_str: network.dns2
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
this.setNetworkProxy(network);
|
||||||
|
},
|
||||||
|
|
||||||
|
removeDefaultRoute: function removeDefaultRoute(ifname) {
|
||||||
|
if(DEBUG) debug("Remove default route for " + ifname);
|
||||||
|
let options = {
|
||||||
|
cmd: "removeDefaultRoute",
|
||||||
|
ifname: ifname
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
addHostRoute: function addHostRoute(network) {
|
||||||
|
if(DEBUG) debug("Going to add host route on " + network.name);
|
||||||
|
let options = {
|
||||||
|
cmd: "addHostRoute",
|
||||||
|
ifname: network.name,
|
||||||
|
gateway: network.gateway,
|
||||||
|
hostnames: [network.dns1, network.dns2, network.httpProxyHost]
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
removeHostRoute: function removeHostRoute(network) {
|
||||||
|
if(DEBUG) debug("Going to remove host route on " + network.name);
|
||||||
|
let options = {
|
||||||
|
cmd: "removeHostRoute",
|
||||||
|
ifname: network.name,
|
||||||
|
gateway: network.gateway,
|
||||||
|
hostnames: [network.dns1, network.dns2, network.httpProxyHost]
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
removeHostRoutes: function removeHostRoutes(ifname) {
|
||||||
|
if(DEBUG) debug("Going to remove all host routes on " + ifname);
|
||||||
|
let options = {
|
||||||
|
cmd: "removeHostRoutes",
|
||||||
|
ifname: ifname,
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
addHostRouteWithResolve: function addHostRouteWithResolve(network, hosts) {
|
||||||
|
if(DEBUG) debug("Going to add host route after dns resolution on " + network.name);
|
||||||
|
let options = {
|
||||||
|
cmd: "addHostRoute",
|
||||||
|
ifname: network.name,
|
||||||
|
gateway: network.gateway,
|
||||||
|
hostnames: hosts
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
removeHostRouteWithResolve: function removeHostRouteWithResolve(network, hosts) {
|
||||||
|
if(DEBUG) debug("Going to remove host route after dns resolution on " + network.name);
|
||||||
|
let options = {
|
||||||
|
cmd: "removeHostRoute",
|
||||||
|
ifname: network.name,
|
||||||
|
gateway: network.gateway,
|
||||||
|
hostnames: hosts
|
||||||
|
};
|
||||||
|
this.worker.postMessage(options);
|
||||||
|
},
|
||||||
|
|
||||||
|
setNetworkProxy: function setNetworkProxy(network) {
|
||||||
|
try {
|
||||||
|
if (!network.httpProxyHost || network.httpProxyHost === "") {
|
||||||
|
// Sets direct connection to internet.
|
||||||
|
Services.prefs.clearUserPref("network.proxy.type");
|
||||||
|
Services.prefs.clearUserPref("network.proxy.share_proxy_settings");
|
||||||
|
Services.prefs.clearUserPref("network.proxy.http");
|
||||||
|
Services.prefs.clearUserPref("network.proxy.http_port");
|
||||||
|
Services.prefs.clearUserPref("network.proxy.ssl");
|
||||||
|
Services.prefs.clearUserPref("network.proxy.ssl_port");
|
||||||
|
if(DEBUG) debug("No proxy support for " + network.name + " network interface.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(DEBUG) debug("Going to set proxy settings for " + network.name + " network interface.");
|
||||||
|
// Sets manual proxy configuration.
|
||||||
|
Services.prefs.setIntPref("network.proxy.type", MANUAL_PROXY_CONFIGURATION);
|
||||||
|
// Do not use this proxy server for all protocols.
|
||||||
|
Services.prefs.setBoolPref("network.proxy.share_proxy_settings", false);
|
||||||
|
Services.prefs.setCharPref("network.proxy.http", network.httpProxyHost);
|
||||||
|
Services.prefs.setCharPref("network.proxy.ssl", network.httpProxyHost);
|
||||||
|
let port = network.httpProxyPort === 0 ? 8080 : network.httpProxyPort;
|
||||||
|
Services.prefs.setIntPref("network.proxy.http_port", port);
|
||||||
|
Services.prefs.setIntPref("network.proxy.ssl_port", port);
|
||||||
|
} catch(ex) {
|
||||||
|
if(DEBUG) debug("Exception " + ex + ". Unable to set proxy setting for " +
|
||||||
|
network.name + " network interface.");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Enable/Disable DHCP server.
|
||||||
|
setDhcpServer: function setDhcpServer(enabled, config, callback) {
|
||||||
|
if (null === config) {
|
||||||
|
config = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
config.cmd = "setDhcpServer";
|
||||||
|
config.isAsync = true;
|
||||||
|
config.enabled = enabled;
|
||||||
|
|
||||||
|
this.controlMessage(config, function setDhcpServerResult(response) {
|
||||||
|
if (!response.success) {
|
||||||
|
callback.dhcpServerResult('Set DHCP server error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback.dhcpServerResult(null);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Enable/disable WiFi tethering by sending commands to netd.
|
||||||
|
setWifiTethering: function setWifiTethering(enable, config, callback) {
|
||||||
|
// config should've already contained:
|
||||||
|
// .ifname
|
||||||
|
// .internalIfname
|
||||||
|
// .externalIfname
|
||||||
|
config.wifictrlinterfacename = WIFI_CTRL_INTERFACE;
|
||||||
|
config.cmd = "setWifiTethering";
|
||||||
|
|
||||||
|
// The callback function in controlMessage may not be fired immediately.
|
||||||
|
config.isAsync = true;
|
||||||
|
this.controlMessage(config, function setWifiTetheringResult(data) {
|
||||||
|
let code = data.resultCode;
|
||||||
|
let reason = data.resultReason;
|
||||||
|
let enable = data.enable;
|
||||||
|
let enableString = enable ? "Enable" : "Disable";
|
||||||
|
|
||||||
|
if(DEBUG) debug(enableString + " Wifi tethering result: Code " + code + " reason " + reason);
|
||||||
|
|
||||||
|
if (isError(code)) {
|
||||||
|
callback.wifiTetheringEnabledChange("netd command error");
|
||||||
|
} else {
|
||||||
|
callback.wifiTetheringEnabledChange(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Enable/disable USB tethering by sending commands to netd.
|
||||||
|
setUSBTethering: function setUSBTethering(enable, config, callback) {
|
||||||
|
config.cmd = "setUSBTethering";
|
||||||
|
// The callback function in controlMessage may not be fired immediately.
|
||||||
|
config.isAsync = true;
|
||||||
|
this.controlMessage(config, function setUsbTetheringResult(data) {
|
||||||
|
let code = data.resultCode;
|
||||||
|
let reason = data.resultReason;
|
||||||
|
let enable = data.enable;
|
||||||
|
let enableString = enable ? "Enable" : "Disable";
|
||||||
|
|
||||||
|
if(DEBUG) debug(enableString + " USB tethering result: Code " + code + " reason " + reason);
|
||||||
|
|
||||||
|
if (isError(code)) {
|
||||||
|
callback.usbTetheringEnabledChange("netd command error");
|
||||||
|
} else {
|
||||||
|
callback.usbTetheringEnabledChange(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Switch usb function by modifying property of persist.sys.usb.config.
|
||||||
|
enableUsbRndis: function enableUsbRndis(enable, callback) {
|
||||||
|
if(DEBUG) debug("enableUsbRndis: " + enable);
|
||||||
|
|
||||||
|
let params = {
|
||||||
|
cmd: "enableUsbRndis",
|
||||||
|
enable: enable
|
||||||
|
};
|
||||||
|
// Ask net work to report the result when this value is set to true.
|
||||||
|
if (callback) {
|
||||||
|
params.report = true;
|
||||||
|
} else {
|
||||||
|
params.report = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The callback function in controlMessage may not be fired immediately.
|
||||||
|
params.isAsync = true;
|
||||||
|
//this._usbTetheringAction = TETHERING_STATE_ONGOING;
|
||||||
|
this.controlMessage(params, function (data) {
|
||||||
|
callback.enableUsbRndisResult(data.result, data.enable);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
updateUpStream: function updateUpStream(previous, current, callback) {
|
||||||
|
let params = {
|
||||||
|
cmd: "updateUpStream",
|
||||||
|
isAsync: true,
|
||||||
|
previous: previous,
|
||||||
|
current: current
|
||||||
|
};
|
||||||
|
|
||||||
|
this.controlMessage(params, function (data) {
|
||||||
|
let code = data.resultCode;
|
||||||
|
let reason = data.resultReason;
|
||||||
|
if(DEBUG) debug("updateUpStream result: Code " + code + " reason " + reason);
|
||||||
|
callback.updateUpStreamResult(!isError(code), data.current.externalIfname);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkService]);
|
3
dom/system/gonk/NetworkService.manifest
Normal file
3
dom/system/gonk/NetworkService.manifest
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# NetworkService.js
|
||||||
|
component {a6c58260-46df-11e3-8f96-0800200c9a66} NetworkService.js
|
||||||
|
contract @mozilla.org/network/service;1 {a6c58260-46df-11e3-8f96-0800200c9a66}
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include "SystemWorkerManager.h"
|
#include "SystemWorkerManager.h"
|
||||||
|
|
||||||
#include "nsINetworkManager.h"
|
#include "nsINetworkService.h"
|
||||||
#include "nsIWifi.h"
|
#include "nsIWifi.h"
|
||||||
#include "nsIWorkerHolder.h"
|
#include "nsIWorkerHolder.h"
|
||||||
#include "nsIXPConnect.h"
|
#include "nsIXPConnect.h"
|
||||||
@ -49,14 +49,10 @@ using namespace mozilla::dom::gonk;
|
|||||||
using namespace mozilla::ipc;
|
using namespace mozilla::ipc;
|
||||||
using namespace mozilla::system;
|
using namespace mozilla::system;
|
||||||
|
|
||||||
#define NS_NETWORKMANAGER_CID \
|
|
||||||
{ 0x33901e46, 0x33b8, 0x11e1, \
|
|
||||||
{ 0x98, 0x69, 0xf4, 0x6d, 0x04, 0xd2, 0x5b, 0xcc } }
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
NS_DEFINE_CID(kWifiWorkerCID, NS_WIFIWORKER_CID);
|
NS_DEFINE_CID(kWifiWorkerCID, NS_WIFIWORKER_CID);
|
||||||
NS_DEFINE_CID(kNetworkManagerCID, NS_NETWORKMANAGER_CID);
|
NS_DEFINE_CID(kNetworkServiceCID, NS_INETWORKSERVICE_IID);
|
||||||
|
|
||||||
// Doesn't carry a reference, we're owned by services.
|
// Doesn't carry a reference, we're owned by services.
|
||||||
SystemWorkerManager *gInstance = nullptr;
|
SystemWorkerManager *gInstance = nullptr;
|
||||||
@ -336,9 +332,9 @@ SystemWorkerManager::GetInterface(const nsIID &aIID, void **aResult)
|
|||||||
reinterpret_cast<nsIWifi**>(aResult));
|
reinterpret_cast<nsIWifi**>(aResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aIID.Equals(NS_GET_IID(nsINetworkManager))) {
|
if (aIID.Equals(NS_GET_IID(nsINetworkService))) {
|
||||||
return CallQueryInterface(mNetdWorker,
|
return CallQueryInterface(mNetdWorker,
|
||||||
reinterpret_cast<nsINetworkManager**>(aResult));
|
reinterpret_cast<nsINetworkService**>(aResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_WARNING("Got nothing for the requested IID!");
|
NS_WARNING("Got nothing for the requested IID!");
|
||||||
@ -393,7 +389,7 @@ SystemWorkerManager::RegisterNfcWorker(const JS::Value& aWorker,
|
|||||||
nsresult
|
nsresult
|
||||||
SystemWorkerManager::InitNetd(JSContext *cx)
|
SystemWorkerManager::InitNetd(JSContext *cx)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIWorkerHolder> worker = do_GetService(kNetworkManagerCID);
|
nsCOMPtr<nsIWorkerHolder> worker = do_GetService(kNetworkServiceCID);
|
||||||
NS_ENSURE_TRUE(worker, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(worker, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
JS::Value workerval;
|
JS::Value workerval;
|
||||||
|
@ -18,6 +18,7 @@ XPIDL_SOURCES += [
|
|||||||
'nsIAudioManager.idl',
|
'nsIAudioManager.idl',
|
||||||
'nsINetworkInterfaceListService.idl',
|
'nsINetworkInterfaceListService.idl',
|
||||||
'nsINetworkManager.idl',
|
'nsINetworkManager.idl',
|
||||||
|
'nsINetworkService.idl',
|
||||||
'nsISystemWorkerManager.idl',
|
'nsISystemWorkerManager.idl',
|
||||||
'nsIVolume.idl',
|
'nsIVolume.idl',
|
||||||
'nsIVolumeMountLock.idl',
|
'nsIVolumeMountLock.idl',
|
||||||
@ -62,9 +63,11 @@ EXTRA_COMPONENTS += [
|
|||||||
'NetworkInterfaceListService.js',
|
'NetworkInterfaceListService.js',
|
||||||
'NetworkInterfaceListService.manifest',
|
'NetworkInterfaceListService.manifest',
|
||||||
'NetworkManager.manifest',
|
'NetworkManager.manifest',
|
||||||
|
'NetworkService.manifest',
|
||||||
]
|
]
|
||||||
EXTRA_PP_COMPONENTS += [
|
EXTRA_PP_COMPONENTS += [
|
||||||
'NetworkManager.js',
|
'NetworkManager.js',
|
||||||
|
'NetworkService.js',
|
||||||
]
|
]
|
||||||
EXTRA_JS_MODULES += [
|
EXTRA_JS_MODULES += [
|
||||||
'net_worker.js',
|
'net_worker.js',
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
|
interface nsIWifiTetheringCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Information about networks that is exposed to network manager API consumers.
|
* Information about networks that is exposed to network manager API consumers.
|
||||||
*/
|
*/
|
||||||
@ -76,64 +78,16 @@ interface nsINetworkInterface : nsISupports
|
|||||||
readonly attribute DOMString httpProxyHost;
|
readonly attribute DOMString httpProxyHost;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The port number of the http proxy server.
|
* The port number of the http proxy server.
|
||||||
*/
|
*/
|
||||||
readonly attribute long httpProxyPort;
|
readonly attribute long httpProxyPort;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
[scriptable, function, uuid(91824160-fb25-11e1-a21f-0800200c9a66)]
|
|
||||||
interface nsIWifiTetheringCallback : nsISupports
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Callback function used to report status to WifiManager.
|
|
||||||
*
|
|
||||||
* @param error
|
|
||||||
* An error message if the operation wasn't successful,
|
|
||||||
* or `null` if it was.
|
|
||||||
*/
|
|
||||||
void wifiTetheringEnabledChange(in jsval error);
|
|
||||||
};
|
|
||||||
|
|
||||||
[scriptable, function, uuid(e079aa2a-ec0a-4bbd-b1a4-d81a9faae464)]
|
|
||||||
interface nsINetworkStatsCallback : nsISupports
|
|
||||||
{
|
|
||||||
void networkStatsAvailable(in boolean success,
|
|
||||||
in unsigned long rxBytes,
|
|
||||||
in unsigned long txBytes,
|
|
||||||
in jsval date);
|
|
||||||
};
|
|
||||||
|
|
||||||
[scriptable, function, uuid(9ede8720-f8bc-11e2-b778-0800200c9a66)]
|
|
||||||
interface nsIWifiOperationModeCallback : nsISupports
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Callback function used to report result to WifiManager.
|
|
||||||
*
|
|
||||||
* @param error
|
|
||||||
* An error message if the operation wasn't successful,
|
|
||||||
* or `null` if it was.
|
|
||||||
*/
|
|
||||||
void wifiOperationModeResult(in jsval error);
|
|
||||||
};
|
|
||||||
|
|
||||||
[scriptable, function, uuid(097878b0-19fc-11e3-8ffd-0800200c9a66)]
|
|
||||||
interface nsISetDhcpServerCallback : nsISupports
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Callback function used to report DHCP server result
|
|
||||||
*
|
|
||||||
* @param error
|
|
||||||
* An error message if the operation wasn't successful,
|
|
||||||
* or `null` if it was.
|
|
||||||
*/
|
|
||||||
void dhcpServerResult(in jsval error);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage network interfaces.
|
* Manage network interfaces.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(f658c740-26bb-11e3-8224-0800200c9a66)]
|
[scriptable, uuid(3ea50550-4b3c-11e3-8f96-0800200c9a66)]
|
||||||
interface nsINetworkManager : nsISupports
|
interface nsINetworkManager : nsISupports
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -217,64 +171,4 @@ interface nsINetworkManager : nsISupports
|
|||||||
in nsINetworkInterface networkInterface,
|
in nsINetworkInterface networkInterface,
|
||||||
in jsval config,
|
in jsval config,
|
||||||
in nsIWifiTetheringCallback callback);
|
in nsIWifiTetheringCallback callback);
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable or disable DHCP server
|
|
||||||
*
|
|
||||||
* @param enabled
|
|
||||||
* Boolean that indicates enabling or disabling DHCP server.
|
|
||||||
*
|
|
||||||
* @param config
|
|
||||||
* Config used to enable the DHCP server. It contains
|
|
||||||
* .startIp start of the ip lease range (string)
|
|
||||||
* .endIp end of the ip lease range (string)
|
|
||||||
* .serverIp ip of the DHCP server (string)
|
|
||||||
* .maskLength the length of the subnet mask
|
|
||||||
* .ifname the interface name
|
|
||||||
*
|
|
||||||
* As for disabling the DHCP server, put this value |null|.
|
|
||||||
*
|
|
||||||
* @param callback
|
|
||||||
* Callback function used to report status.
|
|
||||||
*/
|
|
||||||
void setDhcpServer(in boolean enabled,
|
|
||||||
in jsval config,
|
|
||||||
in nsISetDhcpServerCallback callback);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve network interface stats.
|
|
||||||
*
|
|
||||||
* @param networkName
|
|
||||||
* Select the Network interface to request estats.
|
|
||||||
*
|
|
||||||
* @param callback
|
|
||||||
* Callback to notify result and provide stats, connectionType
|
|
||||||
* and the date when stats are retrieved
|
|
||||||
*/
|
|
||||||
void getNetworkInterfaceStats(in DOMString networkName, in nsINetworkStatsCallback callback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reload Wifi firmware to specific operation mode.
|
|
||||||
*
|
|
||||||
* @param interfaceName
|
|
||||||
* Wifi Network interface name.
|
|
||||||
*
|
|
||||||
* @param mode
|
|
||||||
* AP - Access pointer mode.
|
|
||||||
* P2P - Peer to peer connection mode.
|
|
||||||
* STA - Station mode.
|
|
||||||
*
|
|
||||||
* @param callback
|
|
||||||
* Callback to notify Wifi firmware reload result.
|
|
||||||
*/
|
|
||||||
void setWifiOperationMode(in DOMString interfaceName, in DOMString mode, in nsIWifiOperationModeCallback callback);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set http proxy for specific network
|
|
||||||
*
|
|
||||||
* @param network
|
|
||||||
* Network interface to register.
|
|
||||||
*/
|
|
||||||
void setNetworkProxy(in nsINetworkInterface network);
|
|
||||||
};
|
};
|
||||||
|
298
dom/system/gonk/nsINetworkService.idl
Normal file
298
dom/system/gonk/nsINetworkService.idl
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
|
interface nsINetworkInterface;
|
||||||
|
|
||||||
|
[scriptable, function, uuid(91824160-fb25-11e1-a21f-0800200c9a66)]
|
||||||
|
interface nsIWifiTetheringCallback : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Callback function used to report status to WifiManager.
|
||||||
|
*
|
||||||
|
* @param error
|
||||||
|
* An error message if the operation wasn't successful,
|
||||||
|
* or `null` if it was.
|
||||||
|
*/
|
||||||
|
void wifiTetheringEnabledChange(in jsval error);
|
||||||
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(e079aa2a-ec0a-4bbd-b1a4-d81a9faae464)]
|
||||||
|
interface nsINetworkStatsCallback : nsISupports
|
||||||
|
{
|
||||||
|
void networkStatsAvailable(in boolean success,
|
||||||
|
in unsigned long rxBytes,
|
||||||
|
in unsigned long txBytes,
|
||||||
|
in jsval date);
|
||||||
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(9ede8720-f8bc-11e2-b778-0800200c9a66)]
|
||||||
|
interface nsIWifiOperationModeCallback : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Callback function used to report result to WifiManager.
|
||||||
|
*
|
||||||
|
* @param error
|
||||||
|
* An error message if the operation wasn't successful,
|
||||||
|
* or `null` if it was.
|
||||||
|
*/
|
||||||
|
void wifiOperationModeResult(in jsval error);
|
||||||
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(097878b0-19fc-11e3-8ffd-0800200c9a66)]
|
||||||
|
interface nsISetDhcpServerCallback : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Callback function used to report the DHCP server set result
|
||||||
|
*
|
||||||
|
* @param error
|
||||||
|
* An error message if the operation wasn't successful,
|
||||||
|
* or `null` if it was.
|
||||||
|
*/
|
||||||
|
void dhcpServerResult(in jsval error);
|
||||||
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(32407c50-46c7-11e3-8f96-0800200c9a66)]
|
||||||
|
interface nsIUsbTetheringCallback : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Callback function used to report status of enabling usb tethering.
|
||||||
|
*
|
||||||
|
* @param error
|
||||||
|
* An error message if the operation wasn't successful,
|
||||||
|
* or `null` if it was.
|
||||||
|
*/
|
||||||
|
void usbTetheringEnabledChange(in jsval error);
|
||||||
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(055fd560-46ad-11e3-8f96-0800200c9a66)]
|
||||||
|
interface nsIEnableUsbRndisCallback : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Callback function used to report the status of enabling/disabling usb rndis.
|
||||||
|
*
|
||||||
|
* @param success
|
||||||
|
* Boolean to indicate the operation is successful or not.
|
||||||
|
* @param enable
|
||||||
|
* Boolean to indicate if we are enabling or disabling usb rndis.
|
||||||
|
*/
|
||||||
|
void enableUsbRndisResult(in boolean success, in boolean enable);
|
||||||
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(4f08cc30-46ad-11e3-8f96-0800200c9a66)]
|
||||||
|
interface nsIUpdateUpStreamCallback : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Callback function used to report the result of updating upstream.
|
||||||
|
*
|
||||||
|
* @param success
|
||||||
|
* Boolean to indicate the operation is successful or not.
|
||||||
|
* @param externalIfname
|
||||||
|
* The external interface name.
|
||||||
|
*/
|
||||||
|
void updateUpStreamResult(in boolean success, in DOMString externalIfname);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide network services.
|
||||||
|
*/
|
||||||
|
[scriptable, uuid(a6c58260-46df-11e3-8f96-0800200c9a66)]
|
||||||
|
interface nsINetworkService : nsISupports
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Enable or disable Wifi Tethering
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* Boolean that indicates whether tethering should be enabled (true) or disabled (false).
|
||||||
|
* @param config
|
||||||
|
* The Wifi Tethering configuration from settings db.
|
||||||
|
* @param callback
|
||||||
|
* Callback function used to report status to WifiManager.
|
||||||
|
*/
|
||||||
|
void setWifiTethering(in boolean enabled,
|
||||||
|
in jsval config,
|
||||||
|
in nsIWifiTetheringCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable DHCP server
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* Boolean that indicates enabling or disabling DHCP server.
|
||||||
|
*
|
||||||
|
* @param config
|
||||||
|
* Config used to enable the DHCP server. It contains
|
||||||
|
* .startIp start of the ip lease range (string)
|
||||||
|
* .endIp end of the ip lease range (string)
|
||||||
|
* .serverIp ip of the DHCP server (string)
|
||||||
|
* .maskLength the length of the subnet mask
|
||||||
|
* .ifname the interface name
|
||||||
|
*
|
||||||
|
* As for disabling the DHCP server, put this value |null|.
|
||||||
|
*
|
||||||
|
* @param callback
|
||||||
|
* Callback function used to report status.
|
||||||
|
*/
|
||||||
|
void setDhcpServer(in boolean enabled,
|
||||||
|
in jsval config,
|
||||||
|
in nsISetDhcpServerCallback callback);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve network interface stats.
|
||||||
|
*
|
||||||
|
* @param networkName
|
||||||
|
* Select the Network interface to request estats.
|
||||||
|
*
|
||||||
|
* @param callback
|
||||||
|
* Callback to notify result and provide stats, connectionType
|
||||||
|
* and the date when stats are retrieved
|
||||||
|
*/
|
||||||
|
void getNetworkInterfaceStats(in DOMString networkName, in nsINetworkStatsCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload Wifi firmware to specific operation mode.
|
||||||
|
*
|
||||||
|
* @param interfaceName
|
||||||
|
* Wifi Network interface name.
|
||||||
|
*
|
||||||
|
* @param mode
|
||||||
|
* AP - Access pointer mode.
|
||||||
|
* P2P - Peer to peer connection mode.
|
||||||
|
* STA - Station mode.
|
||||||
|
*
|
||||||
|
* @param callback
|
||||||
|
* Callback to notify Wifi firmware reload result.
|
||||||
|
*/
|
||||||
|
void setWifiOperationMode(in DOMString interfaceName,
|
||||||
|
in DOMString mode,
|
||||||
|
in nsIWifiOperationModeCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set http proxy for specific network
|
||||||
|
*
|
||||||
|
* @param networkInterface
|
||||||
|
* The network interface which contains the http proxy host/port
|
||||||
|
* we want to set.
|
||||||
|
*/
|
||||||
|
void setNetworkProxy(in nsINetworkInterface networkInterface);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set USB tethering.
|
||||||
|
*
|
||||||
|
* @param enabled
|
||||||
|
* Boolean to indicate we are going to enable or disable usb tethering.
|
||||||
|
* @param config
|
||||||
|
* The usb tethering configuration.
|
||||||
|
* @param callback
|
||||||
|
* Callback function used to report the result enabling/disabling usb tethering.
|
||||||
|
*/
|
||||||
|
void setUSBTethering(in boolean enabled,
|
||||||
|
in jsval config,
|
||||||
|
in nsIUsbTetheringCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset routing table.
|
||||||
|
*
|
||||||
|
* @param networkInterface
|
||||||
|
* The network interface we want remove from the routing table.
|
||||||
|
*/
|
||||||
|
void resetRoutingTable(in nsINetworkInterface networkInterface);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DNS.
|
||||||
|
*
|
||||||
|
* @param networkInterface
|
||||||
|
* The network interface which contains the DNS we want to set.
|
||||||
|
*/
|
||||||
|
void setDNS(in nsINetworkInterface networkInterface);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default route and DNS.
|
||||||
|
*
|
||||||
|
* @param networkInterface
|
||||||
|
* The network interface we want to set to the default route and dns.
|
||||||
|
* @param oldInterface
|
||||||
|
* The previous network interface.
|
||||||
|
*/
|
||||||
|
void setDefaultRouteAndDNS(in nsINetworkInterface networkInterface,
|
||||||
|
in nsINetworkInterface oldInterface);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove default route.
|
||||||
|
*
|
||||||
|
* @param interfaceName
|
||||||
|
* The network interface we want remove from the default route.
|
||||||
|
*/
|
||||||
|
void removeDefaultRoute(in DOMString interfaceName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add host route.
|
||||||
|
*
|
||||||
|
* @param networkInterface
|
||||||
|
* The network interface we want to add to the host route.
|
||||||
|
*/
|
||||||
|
void addHostRoute(in nsINetworkInterface networkInterface);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove host route.
|
||||||
|
*
|
||||||
|
* @param network
|
||||||
|
* The network interface we want to remove from the host route.
|
||||||
|
*/
|
||||||
|
void removeHostRoute(in nsINetworkInterface network);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all host routes.
|
||||||
|
*
|
||||||
|
* @param interfaceName
|
||||||
|
* The interface name we want remove from the routing table.
|
||||||
|
*/
|
||||||
|
void removeHostRoutes(in DOMString interfaceName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add host route with resolve.
|
||||||
|
*
|
||||||
|
* @param network
|
||||||
|
* The network interface we want to add to the host route.
|
||||||
|
* @param hosts
|
||||||
|
* The array of host names we want to add.
|
||||||
|
*/
|
||||||
|
void addHostRouteWithResolve(in nsINetworkInterface network, in jsval hosts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove host route with resolve.
|
||||||
|
*
|
||||||
|
* @param network
|
||||||
|
* The network interface we want to remove from the host route.
|
||||||
|
* @param hosts
|
||||||
|
* The array of host names we want to remove.
|
||||||
|
*/
|
||||||
|
void removeHostRouteWithResolve(in nsINetworkInterface network, in jsval hosts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable usb rndis.
|
||||||
|
*
|
||||||
|
* @param enable
|
||||||
|
* Boolean to indicate we want enable or disable usb rndis.
|
||||||
|
* @param callback
|
||||||
|
* Callback function to report the result.
|
||||||
|
*/
|
||||||
|
void enableUsbRndis(in boolean enable,
|
||||||
|
in nsIEnableUsbRndisCallback callback);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update upstream.
|
||||||
|
*
|
||||||
|
* @param previous
|
||||||
|
* The previous internal and external interface.
|
||||||
|
* @param current
|
||||||
|
* The current internal and external interface.
|
||||||
|
* @param callback
|
||||||
|
* Callback function to report the result.
|
||||||
|
*/
|
||||||
|
void updateUpStream(in jsval previous,
|
||||||
|
in jsval current,
|
||||||
|
in nsIUpdateUpStreamCallback callback);
|
||||||
|
};
|
@ -84,6 +84,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "gNetworkManager",
|
|||||||
"@mozilla.org/network/manager;1",
|
"@mozilla.org/network/manager;1",
|
||||||
"nsINetworkManager");
|
"nsINetworkManager");
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyServiceGetter(this, "gNetworkService",
|
||||||
|
"@mozilla.org/network/service;1",
|
||||||
|
"nsINetworkService");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
|
XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
|
||||||
"@mozilla.org/settingsService;1",
|
"@mozilla.org/settingsService;1",
|
||||||
"nsISettingsService");
|
"nsISettingsService");
|
||||||
@ -329,7 +333,7 @@ var WifiManager = (function() {
|
|||||||
if (!network)
|
if (!network)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gNetworkManager.setNetworkProxy(network);
|
gNetworkService.setNetworkProxy(network);
|
||||||
}
|
}
|
||||||
|
|
||||||
var staticIpConfig = Object.create(null);
|
var staticIpConfig = Object.create(null);
|
||||||
@ -864,7 +868,7 @@ var WifiManager = (function() {
|
|||||||
manager.state = "UNINITIALIZED";
|
manager.state = "UNINITIALIZED";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gNetworkManager.setWifiOperationMode(manager.ifname,
|
gNetworkService.setWifiOperationMode(manager.ifname,
|
||||||
WIFI_FIRMWARE_STATION,
|
WIFI_FIRMWARE_STATION,
|
||||||
function (status) {
|
function (status) {
|
||||||
if (status) {
|
if (status) {
|
||||||
|
Loading…
Reference in New Issue
Block a user