Bug 778360 - Don't try to reconnect to a running wpa_supplicant since that confuses the network manager. Instead, ensure that it's well and truly dead before starting. r=gwagner f=hub

This commit is contained in:
Blake Kaplan 2012-08-30 11:08:52 -03:00
parent 75454be03c
commit 235a5b1337

View File

@ -598,7 +598,7 @@ var WifiManager = (function() {
return true;
}
function parseStatus(status, reconnected) {
function parseStatus(status) {
if (status === null) {
debug("Unable to get wpa supplicant's status");
return;
@ -643,7 +643,7 @@ var WifiManager = (function() {
notifyStateChange({ state: state, fromStatus: true });
if (state === "COMPLETED")
onconnected(reconnected);
onconnected();
}
// try to connect to the supplicant
@ -653,7 +653,7 @@ var WifiManager = (function() {
if (ok === 0) {
// Tell the event worker to start waiting for events.
retryTimer = null;
didConnectSupplicant(false, function(){});
didConnectSupplicant(function(){});
return;
}
if (connectTries++ < 3) {
@ -683,15 +683,10 @@ var WifiManager = (function() {
manager.start = function() {
debug("detected SDK version " + sdkVersion + " and device " + device);
// If we reconnected to an already-running supplicant, then manager.state
// will have already been updated to the supplicant's state. Otherwise, we
// started the supplicant ourselves and need to connect.
if (manager.state === "UNINITIALIZED")
connectToSupplicant(connectCallback);
connectToSupplicant(connectCallback);
}
function dhcpAfterConnect() {
function onconnected() {
// For now we do our own DHCP. In the future, this should be handed
// off to the Network Manager.
runDhcp(manager.ifname, function (data) {
@ -725,32 +720,6 @@ var WifiManager = (function() {
});
}
function onconnected(reconnected) {
if (!reconnected) {
dhcpAfterConnect();
return;
}
// We're in the process of reconnecting to a pre-existing wpa_supplicant.
// Check to see if there was already a DHCP process:
getProperty("init.svc.dhcpcd_" + manager.ifname, "stopped", function(value) {
if (value === "running") {
notify("dhcpconnected");
return;
}
// Some phones use a different property name for the dhcpcd daemon.
getProperty("init.svc.dhcpcd", "stopped", function(value) {
if (value === "running") {
notify("dhcpconnected");
return;
}
dhcpAfterConnect();
});
});
}
var supplicantStatesMap = (sdkVersion >= 15) ?
["DISCONNECTED", "INTERFACE_DISABLED", "INACTIVE", "SCANNING",
"AUTHENTICATING", "ASSOCIATING", "ASSOCIATED", "FOUR_WAY_HANDSHAKE",
@ -851,7 +820,7 @@ var WifiManager = (function() {
// Don't call onconnected if we ignored this state change (since we were
// already connected).
if (notifyStateChange({ state: "CONNECTED", BSSID: bssid, id: id }))
onconnected(false);
onconnected();
return true;
}
if (eventData.indexOf("CTRL-EVENT-SCAN-RESULTS") === 0) {
@ -905,49 +874,27 @@ var WifiManager = (function() {
setProperty("ctl.stop", "wpa_supplicant", tick);
}
function didConnectSupplicant(reconnected, callback) {
function didConnectSupplicant(callback) {
waitForEvent();
// Load up the supplicant state.
statusCommand(function(status) {
parseStatus(status, reconnected);
parseStatus(status);
notify("supplicantconnection");
callback();
});
}
function prepareForStartup(callback) {
// First, check to see if there's a wpa_supplicant running that we can
// connect to.
getProperty(SUPP_PROP, "stopped", function (value) {
if (value !== "running") {
stopDhcp(manager.ifname, function() { callback(false) });
return;
}
// It's running, try to reconnect to it.
connectToSupplicant(function (retval) {
if (retval === 0) {
// Successfully reconnected! Don't do anything else.
debug("Successfully connected!");
manager.supplicantStarted = true;
// It is important that we call parseStatus (in
// didConnectSupplicant) before calling the callback here.
// Otherwise, WifiManager.start will reconnect to it.
didConnectSupplicant(true, function() { callback(true) });
return;
}
debug("Didn't connect, trying other method.");
suppressEvents = true;
stopDhcp(manager.ifname, function() {
// Ignore any errors.
killSupplicant(function() {
suppressEvents = false;
callback(false);
});
manager.connectionDropped(function() {
// Ignore any errors and kill any currently-running supplicants. On some
// phones, stopSupplicant won't work for a supplicant that we didn't
// start, so we hand-roll it here.
suppressEvents = true;
killSupplicant(function() {
disableInterface(manager.ifname, function (ok) {
suppressEvents = false;
callback();
});
});
});
@ -994,12 +941,7 @@ var WifiManager = (function() {
kNetworkInterfaceStateChangedTopic,
null);
prepareForStartup(function(already_connected) {
if (already_connected) {
callback(0);
return;
}
prepareForStartup(function() {
loadDriver(function (status) {
if (status < 0) {
callback(status);