зеркало из https://github.com/mozilla/gecko-dev.git
Bug 946257 - Update NetUtils and WifiUtils to support KK. r=fabrice, vchang.
This commit is contained in:
Родитель
91507c568f
Коммит
a5f9677c32
|
@ -187,216 +187,7 @@ this.libnetutils = (function() {
|
|||
};
|
||||
|
||||
iface.RESET_ALL_ADDRESSES = iface.RESET_IPV4_ADDRESSES |
|
||||
iface.RESET_IPV6_ADDRESSES
|
||||
|
||||
// dhcp_do_request's interface changed in SDK version 15. We try to hide
|
||||
// this here by implementing the same JS API for both versions.
|
||||
|
||||
let sdkVersion = libcutils.property_get("ro.build.version.sdk") || "0";
|
||||
sdkVersion = parseInt(sdkVersion, 10);
|
||||
if (sdkVersion >= 15) {
|
||||
let ipaddrbuf = ctypes.char.array(4096)();
|
||||
let gatewaybuf = ctypes.char.array(4096)();
|
||||
let prefixLen = ctypes.int();
|
||||
let dns1buf = ctypes.char.array(4096)();
|
||||
let dns2buf = ctypes.char.array(4096)();
|
||||
let dnslistbuf = ctypes.char.ptr.array(4)();
|
||||
let serverbuf = ctypes.char.array(4096)();
|
||||
let lease = ctypes.int();
|
||||
let vendorbuf = ctypes.char.array(4096)();
|
||||
let domainbuf = ctypes.char.array(4096)();
|
||||
let c_dhcp_do_request;
|
||||
let c_dhcp_do_request_renew;
|
||||
|
||||
// also changed for 16 and 18
|
||||
if (sdkVersion >= 18) { // 18 == JB 4.3
|
||||
dnslistbuf[0] = dns1buf;
|
||||
dnslistbuf[1] = dns2buf;
|
||||
c_dhcp_do_request =
|
||||
library.declare("dhcp_do_request", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.char.ptr, // ipaddr
|
||||
ctypes.char.ptr, // gateway
|
||||
ctypes.int.ptr, // prefixlen
|
||||
ctypes.char.ptr.array(), // dns
|
||||
ctypes.char.ptr, // server
|
||||
ctypes.int.ptr, // lease
|
||||
ctypes.char.ptr, // vendorinfo
|
||||
ctypes.char.ptr); // domain
|
||||
c_dhcp_do_request_renew =
|
||||
library.declare("dhcp_do_request_renew", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.char.ptr, // ipaddr
|
||||
ctypes.char.ptr, // gateway
|
||||
ctypes.int.ptr, // prefixlen
|
||||
ctypes.char.ptr.array(), // dns
|
||||
ctypes.char.ptr, // server
|
||||
ctypes.int.ptr, // lease
|
||||
ctypes.char.ptr, // vendorinfo
|
||||
ctypes.char.ptr); // domain
|
||||
} else if (sdkVersion >= 16) { // 16 == JB 4.1
|
||||
c_dhcp_do_request =
|
||||
library.declare("dhcp_do_request", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.char.ptr, // ipaddr
|
||||
ctypes.char.ptr, // gateway
|
||||
ctypes.int.ptr, // prefixlen
|
||||
ctypes.char.ptr, // dns1
|
||||
ctypes.char.ptr, // dns2
|
||||
ctypes.char.ptr, // server
|
||||
ctypes.int.ptr, // lease
|
||||
ctypes.char.ptr); // vendorinfo
|
||||
} else { // ICS
|
||||
c_dhcp_do_request =
|
||||
library.declare("dhcp_do_request", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.char.ptr, // ipaddr
|
||||
ctypes.char.ptr, // gateway
|
||||
ctypes.int.ptr, // prefixlen
|
||||
ctypes.char.ptr, // dns1
|
||||
ctypes.char.ptr, // dns2
|
||||
ctypes.char.ptr, // server
|
||||
ctypes.int.ptr); // lease
|
||||
}
|
||||
|
||||
|
||||
iface.dhcp_do_request = function dhcp_do_request(ifname) {
|
||||
let ret;
|
||||
if (sdkVersion >= 18) {
|
||||
ret = c_dhcp_do_request(ifname,
|
||||
ipaddrbuf,
|
||||
gatewaybuf,
|
||||
prefixLen.address(),
|
||||
dnslistbuf,
|
||||
serverbuf,
|
||||
lease.address(),
|
||||
vendorbuf,
|
||||
domainbuf);
|
||||
} else if (sdkVersion >= 16) {
|
||||
ret = c_dhcp_do_request(ifname,
|
||||
ipaddrbuf,
|
||||
gatewaybuf,
|
||||
prefixLen.address(),
|
||||
dns1buf,
|
||||
dns2buf,
|
||||
serverbuf,
|
||||
lease.address(),
|
||||
vendorbuf);
|
||||
} else {
|
||||
ret = c_dhcp_do_request(ifname,
|
||||
ipaddrbuf,
|
||||
gatewaybuf,
|
||||
prefixLen.address(),
|
||||
dns1buf,
|
||||
dns2buf,
|
||||
serverbuf,
|
||||
lease.address());
|
||||
}
|
||||
|
||||
if (ret && DEBUG) {
|
||||
let error = iface.dhcp_get_errmsg();
|
||||
dump("dhcp_do_request failed - " + error.readString());
|
||||
}
|
||||
let obj = {
|
||||
ret: ret | 0,
|
||||
ipaddr_str: ipaddrbuf.readString(),
|
||||
mask: netHelpers.makeMask(prefixLen.value),
|
||||
gateway_str: gatewaybuf.readString(),
|
||||
dns1_str: dns1buf.readString(),
|
||||
dns2_str: dns2buf.readString(),
|
||||
server_str: serverbuf.readString(),
|
||||
lease: lease.value | 0,
|
||||
vendor_str: vendorbuf.readString(),
|
||||
domain_str: domainbuf.readString()
|
||||
};
|
||||
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);
|
||||
obj.server = netHelpers.stringToIP(obj.server_str);
|
||||
return obj;
|
||||
};
|
||||
|
||||
// dhcp_do_request_renew() went away in newer libnetutils.
|
||||
// .. and then came back in 4.3! XXX implement support for this
|
||||
iface.dhcp_do_request_renew = iface.dhcp_do_request;
|
||||
|
||||
// Same deal with ifc_reset_connections.
|
||||
let c_ifc_reset_connections =
|
||||
library.declare("ifc_reset_connections",
|
||||
ctypes.default_abi,
|
||||
ctypes.int,
|
||||
ctypes.char.ptr,
|
||||
ctypes.int);
|
||||
iface.ifc_reset_connections = function(ifname, reset_mask) {
|
||||
return c_ifc_reset_connections(ifname, reset_mask) | 0;
|
||||
}
|
||||
} else { // version < 15 - we don't care anymore.
|
||||
let ints = ctypes.int.array(8)();
|
||||
let c_dhcp_do_request =
|
||||
library.declare("dhcp_do_request", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.int.ptr, // ipaddr
|
||||
ctypes.int.ptr, // gateway
|
||||
ctypes.int.ptr, // mask
|
||||
ctypes.int.ptr, // dns1
|
||||
ctypes.int.ptr, // dns2
|
||||
ctypes.int.ptr, // server
|
||||
ctypes.int.ptr); // lease
|
||||
let c_dhcp_do_request_renew =
|
||||
library.declare("dhcp_do_request_renew", ctypes.default_abi,
|
||||
ctypes.int, // return value
|
||||
ctypes.char.ptr, // ifname
|
||||
ctypes.int.ptr, // ipaddr
|
||||
ctypes.int.ptr, // gateway
|
||||
ctypes.int.ptr, // mask
|
||||
ctypes.int.ptr, // dns1
|
||||
ctypes.int.ptr, // dns2
|
||||
ctypes.int.ptr, // server
|
||||
ctypes.int.ptr); // lease
|
||||
|
||||
let wrapCFunc = function wrapCFunc(c_fn) {
|
||||
return function(ifname) {
|
||||
let ret = c_fn(ifname,
|
||||
ints.addressOfElement(0),
|
||||
ints.addressOfElement(1),
|
||||
ints.addressOfElement(2),
|
||||
ints.addressOfElement(3),
|
||||
ints.addressOfElement(4),
|
||||
ints.addressOfElement(5),
|
||||
ints.addressOfElement(6));
|
||||
if (ret && DEBUG) {
|
||||
let error = iface.dhcp_get_errmsg();
|
||||
dump("dhcp_do_request_* failed - " + error.readString());
|
||||
}
|
||||
return {ret: ret | 0,
|
||||
ipaddr: ints[0] | 0,
|
||||
gateway: ints[1] | 0,
|
||||
mask: ints[2] | 0,
|
||||
dns1: ints[3] | 0,
|
||||
dns2: ints[4] | 0,
|
||||
server: ints[5] | 0,
|
||||
lease: ints[6] | 0};
|
||||
};
|
||||
};
|
||||
iface.dhcp_do_request = wrapCFunc(c_dhcp_do_request);
|
||||
iface.dhcp_do_request_renew = wrapCFunc(c_dhcp_do_request_renew);
|
||||
let c_ifc_reset_connections =
|
||||
library.declare("ifc_reset_connections",
|
||||
ctypes.default_abi,
|
||||
ctypes.int,
|
||||
ctypes.char.ptr);
|
||||
iface.ifc_reset_connections = function(ifname, reset_mask) {
|
||||
return c_ifc_reset_connections(ifname) | 0;
|
||||
}
|
||||
}
|
||||
iface.RESET_IPV6_ADDRESSES;
|
||||
|
||||
return iface;
|
||||
})();
|
||||
|
|
|
@ -132,6 +132,16 @@ int32_t NetUtils::do_dhcp_do_request(const char *ifname,
|
|||
char domains[PROPERTY_VALUE_MAX];
|
||||
ret = dhcp_do_request(ifname, ipaddr, gateway, prefixLength, dns,
|
||||
server, lease, vendorinfo, domains);
|
||||
} else if (sdkVersion == 19) {
|
||||
// JB 4.4
|
||||
// http://androidxref.com/4.4_r1/xref/system/core/libnetutils/dhcp_utils.c#18
|
||||
DEFINE_DLFUNC(dhcp_do_request, int32_t, const char*, char*, char*, uint32_t*, char**, char*, uint32_t*, char*, char*, char*)
|
||||
USE_DLFUNC(dhcp_do_request)
|
||||
char *dns[3] = {dns1, dns2, nullptr};
|
||||
char domains[PROPERTY_VALUE_MAX];
|
||||
char mtu[PROPERTY_VALUE_MAX];
|
||||
ret = dhcp_do_request(ifname, ipaddr, gateway, prefixLength, dns,
|
||||
server, lease, vendorinfo, domains, mtu);
|
||||
} else {
|
||||
NS_WARNING("Unable to perform do_dhcp_request: unsupported sdk version!");
|
||||
}
|
||||
|
|
|
@ -141,7 +141,6 @@ class ICSWpaSupplicantImpl : public WpaSupplicantImpl
|
|||
public:
|
||||
DEFAULT_IMPL(wifi_load_driver, int32_t, )
|
||||
DEFAULT_IMPL(wifi_unload_driver, int32_t, )
|
||||
DEFAULT_IMPL(wifi_stop_supplicant, int32_t, )
|
||||
|
||||
DEFINE_DLFUNC(wifi_wait_for_event, int32_t, char*, size_t)
|
||||
int32_t do_wifi_wait_for_event(const char *iface, char *buf, size_t len) {
|
||||
|
@ -161,6 +160,12 @@ public:
|
|||
return wifi_start_supplicant();
|
||||
}
|
||||
|
||||
DEFINE_DLFUNC(wifi_stop_supplicant, int32_t)
|
||||
int32_t do_wifi_stop_supplicant(int32_t) {
|
||||
USE_DLFUNC(wifi_stop_supplicant)
|
||||
return wifi_stop_supplicant();
|
||||
}
|
||||
|
||||
DEFINE_DLFUNC(wifi_connect_to_supplicant, int32_t, )
|
||||
int32_t do_wifi_connect_to_supplicant(const char* iface) {
|
||||
USE_DLFUNC(wifi_connect_to_supplicant)
|
||||
|
@ -197,6 +202,12 @@ public:
|
|||
return wifi_start_supplicant(arg);
|
||||
}
|
||||
|
||||
DEFINE_DLFUNC(wifi_stop_supplicant, int32_t, int32_t)
|
||||
int32_t do_wifi_stop_supplicant(int32_t arg) {
|
||||
USE_DLFUNC(wifi_stop_supplicant)
|
||||
return wifi_stop_supplicant(arg);
|
||||
}
|
||||
|
||||
DEFINE_DLFUNC(wifi_connect_to_supplicant, int32_t, const char*)
|
||||
int32_t do_wifi_connect_to_supplicant(const char* iface) {
|
||||
USE_DLFUNC(wifi_connect_to_supplicant)
|
||||
|
@ -210,13 +221,33 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
// KK implementation.
|
||||
// We only redefine the methods that have a different signature than on ICS.
|
||||
class KKWpaSupplicantImpl : public ICSWpaSupplicantImpl
|
||||
{
|
||||
public:
|
||||
DEFINE_DLFUNC(wifi_start_supplicant, int32_t, int32_t)
|
||||
int32_t do_wifi_start_supplicant(int32_t arg) {
|
||||
USE_DLFUNC(wifi_start_supplicant)
|
||||
return wifi_start_supplicant(arg);
|
||||
}
|
||||
|
||||
DEFINE_DLFUNC(wifi_stop_supplicant, int32_t, int32_t)
|
||||
int32_t do_wifi_stop_supplicant(int32_t arg) {
|
||||
USE_DLFUNC(wifi_stop_supplicant)
|
||||
return wifi_stop_supplicant(arg);
|
||||
}
|
||||
};
|
||||
|
||||
// Concrete class to use to access the wpa supplicant.
|
||||
WpaSupplicant::WpaSupplicant()
|
||||
{
|
||||
if (NetUtils::SdkVersion() < 16) {
|
||||
mImpl = new ICSWpaSupplicantImpl();
|
||||
} else {
|
||||
} else if (NetUtils::SdkVersion() < 19) {
|
||||
mImpl = new JBWpaSupplicantImpl();
|
||||
} else {
|
||||
mImpl = new KKWpaSupplicantImpl();
|
||||
}
|
||||
mNetUtils = new NetUtils();
|
||||
};
|
||||
|
@ -278,7 +309,7 @@ bool WpaSupplicant::ExecuteCommand(CommandOptions aOptions,
|
|||
} else if (aOptions.mCmd.EqualsLiteral("start_supplicant")) {
|
||||
aResult.mStatus = mImpl->do_wifi_start_supplicant(0);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("stop_supplicant")) {
|
||||
aResult.mStatus = mImpl->do_wifi_stop_supplicant();
|
||||
aResult.mStatus = mImpl->do_wifi_stop_supplicant(0);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("connect_to_supplicant")) {
|
||||
aResult.mStatus = mImpl->do_wifi_connect_to_supplicant(aInterface.get());
|
||||
} else if (aOptions.mCmd.EqualsLiteral("ifc_enable")) {
|
||||
|
|
|
@ -90,10 +90,10 @@ public:
|
|||
virtual ~WpaSupplicantImpl() {}
|
||||
|
||||
virtual int32_t
|
||||
do_wifi_wait_for_event(const char *iface, char *buf, size_t len) = 0; // ICS != JB
|
||||
do_wifi_wait_for_event(const char *iface, char *buf, size_t len) = 0; // KK == ICS != JB
|
||||
|
||||
virtual int32_t
|
||||
do_wifi_command(const char* iface, const char* cmd, char* buff, size_t* len) = 0; // ICS != JB
|
||||
do_wifi_command(const char* iface, const char* cmd, char* buff, size_t* len) = 0; // KK == ICS != JB
|
||||
|
||||
virtual int32_t
|
||||
do_wifi_load_driver() = 0;
|
||||
|
@ -102,16 +102,16 @@ public:
|
|||
do_wifi_unload_driver() = 0;
|
||||
|
||||
virtual int32_t
|
||||
do_wifi_start_supplicant(int32_t) = 0; // ICS != JB
|
||||
do_wifi_start_supplicant(int32_t) = 0; // ICS != JB == KK
|
||||
|
||||
virtual int32_t
|
||||
do_wifi_stop_supplicant() = 0;
|
||||
do_wifi_stop_supplicant(int32_t) = 0; //ICS != JB == KK
|
||||
|
||||
virtual int32_t
|
||||
do_wifi_connect_to_supplicant(const char* iface) = 0; // ICS != JB
|
||||
do_wifi_connect_to_supplicant(const char* iface) = 0; // KK == ICS != JB
|
||||
|
||||
virtual void
|
||||
do_wifi_close_supplicant_connection(const char* iface) = 0; // ICS != JB
|
||||
do_wifi_close_supplicant_connection(const char* iface) = 0; // KK == ICS != JB
|
||||
};
|
||||
|
||||
// Concrete class to use to access the wpa supplicant.
|
||||
|
|
Загрузка…
Ссылка в новой задаче