Bug 767375 - B2G network manager: expose IP Information of network interfaces (implementation). r=philikon

This commit is contained in:
Shian-Yow Wu 2012-08-13 21:54:42 -04:00
parent 3345c89acf
commit 82c519a7c0
5 changed files with 93 additions and 5 deletions

View File

@ -1765,6 +1765,16 @@ let RILNetworkInterface = {
dhcp: false,
ip: null,
netmask: null,
broadcast: null,
dns1: null,
dns2: null,
httpProxyHost: null,
httpProxyPort: null,
@ -1779,6 +1789,12 @@ let RILNetworkInterface = {
this.connecting = false;
this.cid = datacall.cid;
this.name = datacall.ifname;
this.ip = datacall.ip;
this.netmask = datacall.netmask;
this.broadcast = datacall.broadcast;
this.gateway = datacall.gw;
this.dns1 = datacall.dns[0];
this.dns2 = datacall.dns[1];
if (!this.registeredAsNetworkInterface) {
let networkManager = Cc["@mozilla.org/network/manager;1"]
.getService(Ci.nsINetworkManager);

View File

@ -75,7 +75,7 @@ interface nsIRILVoicemailCallback : nsISupports
void voicemailNotification(in nsIDOMMozVoicemailStatus status);
};
[scriptable, uuid(8a711703-1ee5-4675-9d9a-0b188e944cfe)]
[scriptable, uuid(1e602d20-d066-4399-8997-daf36b3158ef)]
interface nsIRILDataCallInfo : nsISupports
{
/**
@ -86,6 +86,11 @@ interface nsIRILDataCallInfo : nsISupports
readonly attribute AString cid;
readonly attribute AString apn;
readonly attribute AString ifname;
readonly attribute AString ip;
readonly attribute AString netmask;
readonly attribute AString broadcast;
readonly attribute AString gw;
readonly attribute jsval dns;
};
[scriptable, uuid(5bcac053-c245-46f0-bb45-d0039bfb89f5)]

View File

@ -3400,6 +3400,17 @@ RIL.readDataCall_v6 = function readDataCall_v6(options) {
if (options.gw) {
options.gw = options.gw.split(" ")[0];
}
options.ip = null;
options.netmask = null;
options.broadcast = null;
if (options.ipaddr) {
options.ip = options.ipaddr.split("/")[0];
let ip_value = netHelpers.stringToIP(options.ip);
let prefix_len = options.ipaddr.split("/")[1];
let mask_value = netHelpers.makeMask(prefix_len);
options.netmask = netHelpers.ipToString(mask_value);
options.broadcast = netHelpers.ipToString((ip_value & mask_value) + ~mask_value);
}
return options;
};

View File

@ -210,14 +210,16 @@ let libnetutils = (function () {
let obj = {
ret: ret | 0,
ipaddr_str: ipaddrbuf.readString(),
mask: netHelpers.makeMask(prefixLen),
mask: netHelpers.makeMask(prefixLen.value),
gateway_str: gatewaybuf.readString(),
dns1_str: dns1buf.readString(),
dns2_str: dns2buf.readString(),
server_str: serverbuf.readString(),
lease: lease | 0
lease: lease.value | 0
};
obj.ipaddr = netHelpers.stringToIP(obj.ipaddr_str);
obj.mask_str = netHelpers.ipToString(obj.mask);
obj.broadcast_str = netHelpers.ipToString((obj.ipaddr & obj.mask) + ~obj.mask);
obj.gateway = netHelpers.stringToIP(obj.gateway_str);
obj.dns1 = netHelpers.stringToIP(obj.dns1_str);
obj.dns2 = netHelpers.stringToIP(obj.dns2_str);
@ -287,6 +289,32 @@ let libnetutils = (function () {
*/
let netHelpers = {
/**
* Swap byte orders for 32-bit value
*/
swap32: function swap32(n) {
return (((n >> 24) & 0xFF) << 0) |
(((n >> 16) & 0xFF) << 8) |
(((n >> 8) & 0xFF) << 16) |
(((n >> 0) & 0xFF) << 24);
},
/**
* Convert network byte order to host byte order
* Note: Assume that the system is little endian
*/
ntohl: function ntohl(n) {
return this.swap32(n);
},
/**
* Convert host byte order to network byte order
* Note: Assume that the system is little endian
*/
htonl: function htonl(n) {
return this.swap32(n);
},
/**
* Convert integer representation of an IP address to the string
* representation.
@ -332,8 +360,8 @@ let netHelpers = {
makeMask: function makeMask(len) {
let mask = 0;
for (let i = 0; i < len; ++i) {
mask |= (1 << i);
mask |= (0x80000000 >> i);
}
return mask;
return this.ntohl(mask);
}
};

View File

@ -946,6 +946,12 @@ var WifiManager = (function() {
WifiNetworkInterface.registered = true;
}
WifiNetworkInterface.state = Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED;
WifiNetworkInterface.ip = null;
WifiNetworkInterface.netmask = null;
WifiNetworkInterface.broadcast = null;
WifiNetworkInterface.gateway = null;
WifiNetworkInterface.dns1 = null;
WifiNetworkInterface.dns2 = null;
Services.obs.notifyObservers(WifiNetworkInterface,
kNetworkInterfaceStateChangedTopic,
null);
@ -1267,6 +1273,16 @@ let WifiNetworkInterface = {
// to the Network Manager.
dhcp: false,
ip: null,
netmask: null,
broadcast: null,
dns1: null,
dns2: null,
httpProxyHost: null,
httpProxyPort: null,
@ -1498,6 +1514,12 @@ function WifiWorker() {
WifiNetworkInterface.state =
Ci.nsINetworkInterface.NETWORK_STATE_DISCONNECTED;
WifiNetworkInterface.ip = null;
WifiNetworkInterface.netmask = null;
WifiNetworkInterface.broadcast = null;
WifiNetworkInterface.gateway = null;
WifiNetworkInterface.dns1 = null;
WifiNetworkInterface.dns2 = null;
Services.obs.notifyObservers(WifiNetworkInterface,
kNetworkInterfaceStateChangedTopic,
null);
@ -1510,6 +1532,12 @@ function WifiWorker() {
if (this.info) {
WifiNetworkInterface.state =
Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
WifiNetworkInterface.ip = this.info.ipaddr_str;
WifiNetworkInterface.netmask = this.info.mask_str;
WifiNetworkInterface.broadcast = this.info.broadcast_str;
WifiNetworkInterface.gateway = this.info.gateway_str;
WifiNetworkInterface.dns1 = this.info.dns1_str;
WifiNetworkInterface.dns2 = this.info.dns2_str;
Services.obs.notifyObservers(WifiNetworkInterface,
kNetworkInterfaceStateChangedTopic,
null);