diff --git a/dom/wifi/WifiWorker.js b/dom/wifi/WifiWorker.js index acc5842adf65..baa091f0119a 100644 --- a/dom/wifi/WifiWorker.js +++ b/dom/wifi/WifiWorker.js @@ -443,8 +443,7 @@ var WifiManager = (function() { function stopDhcp(ifname, callback) { controlMessage({ cmd: "dhcp_stop", ifname: ifname }, function(data) { - if (!data.status) - dhcpInfo = null; + dhcpInfo = null; notify("dhcplost"); callback(!data.status); }); @@ -452,8 +451,7 @@ var WifiManager = (function() { function releaseDhcpLease(ifname, callback) { controlMessage({ cmd: "dhcp_release_lease", ifname: ifname }, function(data) { - if (!data.status) - dhcpInfo = null; + dhcpInfo = null; notify("dhcplost"); callback(!data.status); }); @@ -499,11 +497,6 @@ var WifiManager = (function() { fields.prevState = manager.state; manager.state = fields.state; - // If we got disconnected, kill the DHCP client in preparation for - // reconnection. - if (fields.state === "DISCONNECTED" && dhcpInfo) - stopDhcp(manager.ifname, function() {}); - notify("statechange", fields); } @@ -580,6 +573,16 @@ var WifiManager = (function() { notify("supplicantlost"); } + manager.connectionDropped = function(callback) { + // If we got disconnected, kill the DHCP client in preparation for + // reconnection. + resetConnections(manager.ifname, function() { + stopDhcp(manager.ifname, function() { + callback(); + }); + }); + } + manager.start = function() { debug("detected SDK version " + sdkVersion); @@ -722,9 +725,9 @@ var WifiManager = (function() { return false; } if (eventData.indexOf("CTRL-EVENT-DISCONNECTED") === 0) { - notifyStateChange({ state: "DISCONNECTED" }); manager.connectionInfo.bssid = null; manager.connectionInfo.ssid = null; + manager.connectionInfo.id = -1; return true; } if (eventData.indexOf("CTRL-EVENT-CONNECTED") === 0) { @@ -869,11 +872,13 @@ var WifiManager = (function() { // supplicant gracefully, then we need to continue telling it to die // until it does. terminateSupplicant(function (ok) { - stopSupplicant(function (status) { - manager.state = "UNINITIALIZED"; - closeSupplicantConnection(function () { - disableInterface(manager.ifname, function (ok) { - unloadDriver(callback); + manager.connectionDropped(function () { + stopSupplicant(function (status) { + manager.state = "UNINITIALIZED"; + closeSupplicantConnection(function () { + disableInterface(manager.ifname, function (ok) { + unloadDriver(callback); + }); }); }); }); @@ -1230,6 +1235,12 @@ function WifiWorker() { self._fireEvent("onconnecting", { network: netToDOM(self.currentNetwork) }); break; case "ASSOCIATED": + if (!self.currentNetwork) { + self.currentNetwork = + { bssid: WifiManager.connectionInfo.bssid, + ssid: quote(WifiManager.connectionInfo.ssid) }; + } + self.currentNetwork.netId = this.id; WifiManager.getNetworkConfiguration(self.currentNetwork, function (){}); break; @@ -1251,7 +1262,7 @@ function WifiWorker() { // because of that we need to gather information about the current // network here. self.currentNetwork = { ssid: quote(WifiManager.connectionInfo.ssid), - known: true } + netId: WifiManager.connectionInfo.id }; WifiManager.getNetworkConfiguration(self.currentNetwork, function(){}); } @@ -1264,12 +1275,14 @@ function WifiWorker() { self._fireEvent("ondisconnect", {}); self.currentNetwork = null; - // We've disconnected from a network because of a call to forgetNetwork. - // Reconnect to the next available network (if any). - if (self._reconnectOnDisconnect) { - self._reconnectOnDisconnect = false; - WifiManager.reconnect(function(){}); - } + WifiManager.connectionDropped(function() { + // We've disconnected from a network because of a call to forgetNetwork. + // Reconnect to the next available network (if any). + if (self._reconnectOnDisconnect) { + self._reconnectOnDisconnect = false; + WifiManager.reconnect(function(){}); + } + }); break; } @@ -1683,7 +1696,7 @@ WifiWorker.prototype = { let self = this; let configured = this.configuredNetworks[ssid]; this._reconnectOnDisconnect = (this.currentNetwork && - (this.currentNetwork.ssid === ssid)); + (this.currentNetwork.ssid === ssid)); WifiManager.removeNetwork(configured.netId, function(ok) { if (!ok) { self._sendMessage(message, false, "Unable to remove the network", rid, mid);