Bug 1049460 - Change wpa_supplicant mux/demux method on KK to enable wifi direct. r=vchang

--HG--
extra : rebase_source : 0633f2b2999d9aca03543463164b3de83b67f4f5
This commit is contained in:
Henry Chang 2014-10-08 15:18:35 +08:00
Родитель 5961726451
Коммит 2cfa54eae4
5 изменённых файлов: 63 добавлений и 14 удалений

Просмотреть файл

@ -149,7 +149,7 @@ MozWifiP2pManager.prototype = {
case "WifiP2pManager:getPeerList:Return:OK":
request = this.takeRequest(msg.rid);
Services.DOMRequest.fireSuccess(request, msg.data);
Services.DOMRequest.fireSuccess(request, Cu.cloneInto(msg.data, this._window));
break;
case "WifiP2pManager:getPeerList:Return:NO":

Просмотреть файл

@ -25,6 +25,13 @@ this.WifiCommand = function(aControlMessage, aInterface, aSdkVersion) {
var command = {};
//-------------------------------------------------
// Utilities.
//-------------------------------------------------
command.getSdkVersion = function() {
return aSdkVersion;
};
//-------------------------------------------------
// General commands.
//-------------------------------------------------

Просмотреть файл

@ -608,18 +608,28 @@ function P2pStateMachine(aP2pCommand, aNetUtil) {
_sm.pause();
// Step 1: Connect to p2p0.
aP2pCommand.connectToSupplicant(function (status) {
let detail;
if (0 !== status) {
debug('Failed to connect to p2p0');
onFailure();
// This function will only call back on success.
function connectToSupplicantIfNeeded(callback) {
if (aP2pCommand.getSdkVersion() >= 19) {
// No need to connect to supplicant on KK. Call back directly.
callback();
return;
}
aP2pCommand.connectToSupplicant(function (status) {
if (0 !== status) {
debug('Failed to connect to p2p0');
onFailure();
return;
}
debug('wpa_supplicant p2p0 connected!');
_onSupplicantConnected();
callback();
});
}
debug('wpa_supplicant p2p0 connected!');
_onSupplicantConnected();
// Step 1: Connect to p2p0 if needed.
connectToSupplicantIfNeeded(function callback () {
let detail;
// Step 2: Get MAC address.
if (!_localDevice.address) {

Просмотреть файл

@ -174,6 +174,14 @@ WifiProxyService::Start(nsIWifiEventListener* aListener,
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aListener);
#if ANDROID_VERSION >= 19
// KK changes the way mux'ing/demux'ing different supplicant interfaces
// (e.g. wlan0/p2p0) from multi-sockets to single socket embedded with
// prefixed interface name (e.g. IFNAME=wlan0 xxxxxx). Therefore, we use
// the first given interface as the global interface for KK.
aNumOfInterfaces = 1;
#endif
nsresult rv;
// Since EventRunnable runs in the manner of blocking, we have to
@ -250,6 +258,14 @@ WifiProxyService::WaitForEvent(const nsACString& aInterface)
{
MOZ_ASSERT(NS_IsMainThread());
#if ANDROID_VERSION >= 19
// We will only have one global interface for KK.
if (!mEventThreadList.IsEmpty()) {
nsCOMPtr<nsIRunnable> runnable = new EventRunnable(aInterface);
mEventThreadList[0].mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
return NS_OK;
}
#else
// Dispatch to the event thread which has the given interface name
for (size_t i = 0; i < mEventThreadList.Length(); i++) {
if (mEventThreadList[i].mInterface.Equals(aInterface)) {
@ -258,6 +274,7 @@ WifiProxyService::WaitForEvent(const nsACString& aInterface)
return NS_OK;
}
}
#endif
return NS_ERROR_FAILURE;
}
@ -282,16 +299,27 @@ void
WifiProxyService::DispatchWifiEvent(const nsAString& aEvent, const nsACString& aInterface)
{
MOZ_ASSERT(NS_IsMainThread());
#if ANDROID_VERSION < 19
mListener->OnWaitEvent(aEvent, aInterface);
#else
// The interface might be embedded in the event string such as
// "IFNAME=wlan0 CTRL-EVENT-BSS-ADDED 65 3c:94:d5:7c:11:8b".
// Parse the interface name from the event string and use p2p0
// as the default interface if "IFNAME" is not found.
nsAutoString event;
nsAutoString embeddedInterface(NS_LITERAL_STRING("p2p0"));
if (StringBeginsWith(aEvent, NS_LITERAL_STRING("IFNAME"))) {
// Jump over IFNAME for gonk-kk.
int32_t ifnameFrom = aEvent.FindChar('=') + 1;
int32_t ifnameTo = aEvent.FindChar(' ') - 1;
embeddedInterface = Substring(aEvent, ifnameFrom, ifnameTo - ifnameFrom + 1);
event = Substring(aEvent, aEvent.FindChar(' ') + 1);
}
else {
event = aEvent;
}
// Call the listener.
mListener->OnWaitEvent(event, aInterface);
mListener->OnWaitEvent(event, NS_ConvertUTF16toUTF8(embeddedInterface));
#endif
}
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(WifiProxyService,

Просмотреть файл

@ -134,7 +134,11 @@ var WifiManager = (function() {
if (manager.ifname === iface && handleEvent(event)) {
waitForEvent(iface);
} else if (p2pSupported) {
if (WifiP2pManager.INTERFACE_NAME === iface) {
// Please refer to
// http://androidxref.com/4.4.2_r1/xref/frameworks/base/wifi/java/android/net/wifi/WifiMonitor.java#519
// for interface event mux/demux rules. In short words, both
// 'p2p0' and 'p2p-' should go to Wifi P2P state machine.
if (WifiP2pManager.INTERFACE_NAME === iface || -1 !== iface.indexOf('p2p-')) {
// If the connection is closed, wifi.c::wifi_wait_for_event()
// will still return 'CTRL-EVENT-TERMINATING - connection closed'
// rather than blocking. So when we see this special event string,