Bug 859209 - [Buri][Shira][WIFI]It keep Connecting when input wrong password to connect AP security with WEP. r=chucklee
authorVincent Chang <vchang@mozilla.com>
Fri, 18 Oct 2013 16:46:30 +0800
changeset 165076 cfdeb3ec56386549503b9a7d9b1576e99e0f9ce3
parent 165075 e7973650491e8afa69d71395d7f485494b3b66d1
child 165077 432c590d83d3107f48285b89d8c909319c803929
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschucklee
bugs859209
milestone27.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 859209 - [Buri][Shira][WIFI]It keep Connecting when input wrong password to connect AP security with WEP. r=chucklee
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -21,16 +21,17 @@ const WIFIWORKER_CID        = Components
 
 const WIFIWORKER_WORKER     = "resource://gre/modules/wifi_worker.js";
 
 const kNetworkInterfaceStateChangedTopic = "network-interface-state-changed";
 const kMozSettingsChangedObserverTopic   = "mozsettings-changed";
 
 const MAX_RETRIES_ON_AUTHENTICATION_FAILURE = 2;
 const MAX_SUPPLICANT_LOOP_ITERATIONS = 4;
+const MAX_RETRIES_ON_DHCP_FAILURE = 2;
 
 // Settings DB path for wifi
 const SETTINGS_WIFI_ENABLED            = "wifi.enabled";
 const SETTINGS_WIFI_DEBUG_ENABLED      = "wifi.debugging.enabled";
 // Settings DB path for Wifi tethering.
 const SETTINGS_WIFI_TETHERING_ENABLED  = "tethering.wifi.enabled";
 const SETTINGS_WIFI_SSID               = "tethering.wifi.ssid";
 const SETTINGS_WIFI_SECURITY_TYPE      = "tethering.wifi.security.type";
@@ -553,16 +554,31 @@ var WifiManager = (function() {
           (key in staticIpConfig) &&
           staticIpConfig[key].enabled) {
           debug("Run static ip");
           runStaticIp(manager.ifname, key);
           return;
       }
       netUtil.runDhcp(manager.ifname, function(data) {
         dhcpInfo = data.info;
+        if (!dhcpInfo) {
+          if (++manager.dhcpFailuresCount >= MAX_RETRIES_ON_DHCP_FAILURE) {
+            manager.dhcpFailuresCount = 0;
+            notify("disconnected", {ssid: manager.connectionInfo.ssid});
+            return;
+          }
+          // NB: We have to call disconnect first. Otherwise, we only reauth with
+          // the existing AP and don't retrigger DHCP.
+          manager.disconnect(function() {
+            manager.reassociate(function(){});
+          });
+          return;
+        }
+
+        manager.dhcpFailuresCount = 0;
         notify("networkconnected", data);
       });
     });
   }
 
   var supplicantStatesMap = (sdkVersion >= 15) ?
     ["DISCONNECTED", "INTERFACE_DISABLED", "INACTIVE", "SCANNING",
      "AUTHENTICATING", "ASSOCIATING", "ASSOCIATED", "FOUR_WAY_HANDSHAKE",
@@ -784,16 +800,17 @@ var WifiManager = (function() {
   // Initial state.
   manager.state = "UNINITIALIZED";
   manager.tetheringState = "UNINITIALIZED";
   manager.enabled = false;
   manager.supplicantStarted = false;
   manager.connectionInfo = { ssid: null, bssid: null, id: -1 };
   manager.authenticationFailuresCount = 0;
   manager.loopDetectionCount = 0;
+  manager.dhcpFailuresCount = 0;
 
   var waitForDriverReadyTimer = null;
   function cancelWaitForDriverReadyTimer() {
     if (waitForDriverReadyTimer) {
       waitForDriverReadyTimer.cancel();
       waitForDriverReadyTimer = null;
     }
   };
@@ -1818,44 +1835,41 @@ function WifiWorker() {
         // about getting stuck while scanning.
         if (!WifiManager.backgroundScanEnabled && WifiManager.enabled)
           startScanStuckTimer();
         break;
     }
   };
 
   WifiManager.onnetworkconnected = function() {
-    if (this.info) {
-      WifiNetworkInterface.state =
-        Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
-      WifiNetworkInterface.ip = this.info.ipaddr_str;
-      WifiNetworkInterface.netmask = this.info.mask_str;
-      WifiNetworkInterface.broadcast = this.info.broadcast_str;
-      WifiNetworkInterface.gateway = this.info.gateway_str;
-      WifiNetworkInterface.dns1 = this.info.dns1_str;
-      WifiNetworkInterface.dns2 = this.info.dns2_str;
-      Services.obs.notifyObservers(WifiNetworkInterface,
-                                   kNetworkInterfaceStateChangedTopic,
-                                   null);
-
-      self.ipAddress = this.info.ipaddr_str;
-
-      // We start the connection information timer when we associate, but
-      // don't have our IP address until here. Make sure that we fire a new
-      // connectionInformation event with the IP address the next time the
-      // timer fires.
-      self._lastConnectionInfo = null;
-      self._fireEvent("onconnect", { network: netToDOM(self.currentNetwork) });
-    } else {
-      // NB: We have to call disconnect first. Otherwise, we only reauth with
-      // the existing AP and don't retrigger DHCP.
-      WifiManager.disconnect(function() {
-        WifiManager.reassociate(function(){});
-      });
+    if (!this.info) {
+      debug("Network information is invalid.");
+      return;
     }
+
+    WifiNetworkInterface.state =
+      Ci.nsINetworkInterface.NETWORK_STATE_CONNECTED;
+    WifiNetworkInterface.ip = this.info.ipaddr_str;
+    WifiNetworkInterface.netmask = this.info.mask_str;
+    WifiNetworkInterface.broadcast = this.info.broadcast_str;
+    WifiNetworkInterface.gateway = this.info.gateway_str;
+    WifiNetworkInterface.dns1 = this.info.dns1_str;
+    WifiNetworkInterface.dns2 = this.info.dns2_str;
+    Services.obs.notifyObservers(WifiNetworkInterface,
+                                 kNetworkInterfaceStateChangedTopic,
+                                 null);
+
+    self.ipAddress = this.info.ipaddr_str;
+
+    // We start the connection information timer when we associate, but
+    // don't have our IP address until here. Make sure that we fire a new
+    // connectionInformation event with the IP address the next time the
+    // timer fires.
+    self._lastConnectionInfo = null;
+    self._fireEvent("onconnect", { network: netToDOM(self.currentNetwork) });
   };
 
   WifiManager.onscanresultsavailable = function() {
     if (self._scanStuckTimer) {
       // We got scan results! We must not be stuck for now, try again.
       self._scanStuckTimer.cancel();
       self._scanStuckTimer.initWithCallback(scanIsStuck, SCAN_STUCK_WAIT,
                                             Ci.nsITimer.TYPE_ONE_SHOT);