Bug 813880 - Unable to disable network when user connects to wep network with incorrect password. r=mrbkap
authorVincent Chang <vchang@mozilla.com>
Fri, 23 Nov 2012 18:30:33 +0800
changeset 125307 c449c10f282957532e68c9287297c2969b1e7ac6
parent 125306 3f278fad083bda7d0c438f60d6bb6629398c043b
child 125308 865dc2eb00fb06ab790c533a8129351ed31acdad
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs813880
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 813880 - Unable to disable network when user connects to wep network with incorrect password. r=mrbkap
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -798,27 +798,47 @@ var WifiManager = (function() {
      "GROUP_HANDSHAKE", "COMPLETED"]
     :
     ["DISCONNECTED", "INACTIVE", "SCANNING", "ASSOCIATING",
      "ASSOCIATED", "FOUR_WAY_HANDSHAKE", "GROUP_HANDSHAKE",
      "COMPLETED", "DORMANT", "UNINITIALIZED"];
 
   var driverEventMap = { STOPPED: "driverstopped", STARTED: "driverstarted", HANGED: "driverhung" };
 
+  manager.getCurrentNetworkId = function (ssid, callback) {
+    manager.getConfiguredNetworks(function(networks) {
+      if (!networks) {
+        debug("Unable to get configured networks");
+        return callback(null);
+      }
+      for (let net in networks) {
+        let network = networks[net];
+        // Trying to get netId from
+        // 1. CURRENT network.
+        // 2. Trying to associate with SSID 'ssid' event
+        if (network.status === "CURRENT" ||
+            (ssid && ssid === dequote(network.ssid))) {
+          return callback(net);
+        }
+      }
+      callback(null);
+    });
+  }
+
   // handle events sent to us by the event worker
   function handleEvent(event) {
     debug("Event coming in: " + event);
     if (event.indexOf("CTRL-EVENT-") !== 0 && event.indexOf("WPS") !== 0) {
       // Handle connection fail exception on WEP-128, while password length
       // is not 5 nor 13 bytes.
       if (event.indexOf("Association request to the driver failed") !== -1) {
         notify("passwordmaybeincorrect");
         if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-          notify("disconnected");
           manager.authenticationFailuresCount = 0;
+          notify("disconnected", {ssid: manager.connectionInfo.ssid});
         }
         return true;
       }
 
       if (event.indexOf("WPA:") == 0 &&
           event.indexOf("pre-shared key may be incorrect") != -1) {
         notify("passwordmaybeincorrect");
       }
@@ -882,31 +902,31 @@ var WifiManager = (function() {
 
       notifyStateChange({ state: "DISCONNECTED", BSSID: null, id: -1 });
       notify("supplicantlost");
       return false;
     }
     if (eventData.indexOf("CTRL-EVENT-DISCONNECTED") === 0) {
       var token = event.split(" ")[1];
       var bssid = token.split("=")[1];
+      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
+        manager.authenticationFailuresCount = 0;
+        notify("disconnected", {ssid: manager.connectionInfo.ssid});
+      }
       manager.connectionInfo.bssid = null;
       manager.connectionInfo.ssid = null;
       manager.connectionInfo.id = -1;
-      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-        notify("disconnected", {BSSID: bssid});
-        manager.authenticationFailuresCount = 0;
-      }
       return true;
     }
     // Association reject is triggered mostly on incorrect WEP key.
     if (eventData.indexOf("CTRL-EVENT-ASSOC-REJECT") === 0) {
       notify("passwordmaybeincorrect");
       if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-        notify("disconnected");
         manager.authenticationFailuresCount = 0;
+        notify("disconnected", {ssid: manager.connectionInfo.ssid});
       }
       return true;
     }
     if (eventData.indexOf("CTRL-EVENT-CONNECTED") === 0) {
       // Format: CTRL-EVENT-CONNECTED - Connection to 00:1e:58:ec:d5:6d completed (reauth) [id=1 id_str=]
       var bssid = event.split(" ")[4];
       var id = event.substr(event.indexOf("id=")).split(" ")[0];
       // Read current BSSID here, it will always being provided.
@@ -1334,17 +1354,17 @@ var WifiManager = (function() {
 
     if (isPrevStateInHandShake) {
       if (isStateInHandShake) {
         // Increase the count only if we are in the loop.
         if (manager.stateOrdinal(state) > manager.stateOrdinal(prevState)) {
           manager.loopDetectionCount++;
         }
         if (manager.loopDetectionCount > MAX_SUPPLICANT_LOOP_ITERATIONS) {
-          notify("disconnected");
+          notify("disconnected", {ssid: manager.connectionInfo.ssid});
           manager.loopDetectionCount = 0;
         }
       }
     } else {
       // From others state to HandShake state. Reset the count.
       if (isStateInHandShake) {
         manager.loopDetectionCount = 0;
       }
@@ -1797,26 +1817,29 @@ function WifiWorker() {
   WifiManager.ondisconnected = function() {
     // We may fail to establish the connection, re-enable the
     // rest of our networks.
     if (self._needToEnableNetworks) {
       self._enableAllNetworks();
       self._needToEnableNetworks = false;
     }
 
-    var currentNetwork = self.currentNetwork;
-    if (currentNetwork && !isNaN(currentNetwork.netId)) {
-      // Disable the network when password is incorrect.
-      WifiManager.disableNetwork(currentNetwork.netId, function() {});
-    } else {
-      // TODO: We can't get netId when connecting to wep network with
-      // incorrect password, see Bug 813880
-    }
-    self._fireEvent("onconnectingfailed", {network: currentNetwork});
-  };
+    WifiManager.getCurrentNetworkId(this.ssid, function(netId) {
+      // Trying to get netId from current network.
+      if (!netId &&
+          self.currentNetwork &&
+          typeof self.currentNetwork.netId !== "undefined") {
+        netId = self.currentNetwork.netId;
+      }
+      if (netId) {
+        WifiManager.disableNetwork(netId, function() {});
+      }
+    });
+    self._fireEvent("onconnectingfailed", {network: self.currentNetwork});
+  }
 
   WifiManager.onstatechange = function() {
     debug("State change: " + this.prevState + " -> " + this.state);
 
     if (self._connectionInfoTimer &&
         this.state !== "CONNECTED" &&
         this.state !== "COMPLETED") {
       self._stopConnectionInfoTimer();