shill: reduce delay between scans, when supplicant reports
"No suitable network".

BUG=chromium-os:27309
TEST=WiFiRomaing.001SSIDSwitchBack

Change-Id: Idd738f737abfdbdcf1e79aff21f860b5b52f1110
Reviewed-on: https://gerrit.chromium.org/gerrit/18021
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: mukesh agrawal <quiche@chromium.org>
diff --git a/dbus_bindings/supplicant-interface.xml b/dbus_bindings/supplicant-interface.xml
index 31f870b..6d14343 100644
--- a/dbus_bindings/supplicant-interface.xml
+++ b/dbus_bindings/supplicant-interface.xml
@@ -50,6 +50,7 @@
     <property name="BSSs" type="ao" access="read"/>
     <property name="Networks" type="ao" access="read"/>
     <property name="FastReauth" type="b" access="readwrite"/>
+    <property name="ScanInterval" type="i" access="readwrite"/>
     <signal name="ScanDone">
       <arg name="success" type="b"/>
     </signal>
diff --git a/mock_supplicant_interface_proxy.h b/mock_supplicant_interface_proxy.h
index 43af85f..3a44466 100644
--- a/mock_supplicant_interface_proxy.h
+++ b/mock_supplicant_interface_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -32,6 +32,7 @@
                void(const std::map<std::string, ::DBus::Variant> &args));
   MOCK_METHOD1(SelectNetwork, void(const ::DBus::Path &network));
   MOCK_METHOD1(SetFastReauth, void(bool enabled));
+  MOCK_METHOD1(SetScanInterval, void(int32_t seconds));
 
  private:
   // wifi_ is not used explicitly but its presence here tests that WiFi::Stop
diff --git a/supplicant_interface_proxy.cc b/supplicant_interface_proxy.cc
index e0b1fbc..68359ff 100644
--- a/supplicant_interface_proxy.cc
+++ b/supplicant_interface_proxy.cc
@@ -64,6 +64,10 @@
   return proxy_.FastReauth(enabled);
 }
 
+void SupplicantInterfaceProxy::SetScanInterval(int32 scan_interval) {
+  return proxy_.ScanInterval(scan_interval);
+}
+
 // definitions for private class SupplicantInterfaceProxy::Proxy
 
 SupplicantInterfaceProxy::Proxy::Proxy(
diff --git a/supplicant_interface_proxy.h b/supplicant_interface_proxy.h
index 5d4d32f..87f46cd 100644
--- a/supplicant_interface_proxy.h
+++ b/supplicant_interface_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -38,6 +38,7 @@
       const std::map<std::string, ::DBus::Variant> &args);
   virtual void SelectNetwork(const ::DBus::Path &network);
   virtual void SetFastReauth(bool enabled);
+  virtual void SetScanInterval(int seconds);
 
  private:
   class Proxy : public fi::w1::wpa_supplicant1::Interface_proxy,
diff --git a/supplicant_interface_proxy_interface.h b/supplicant_interface_proxy_interface.h
index 0298a4e..bf60d04 100644
--- a/supplicant_interface_proxy_interface.h
+++ b/supplicant_interface_proxy_interface.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -29,6 +29,7 @@
       const std::map<std::string, ::DBus::Variant> &args) = 0;
   virtual void SelectNetwork(const ::DBus::Path &network) = 0;
   virtual void SetFastReauth(bool enabled) = 0;
+  virtual void SetScanInterval(int seconds) = 0;
 };
 
 }  // namespace shill
diff --git a/wifi.cc b/wifi.cc
index 7749c68..5dc0f56 100644
--- a/wifi.cc
+++ b/wifi.cc
@@ -75,6 +75,7 @@
 // across a suspend/resume.
 const time_t WiFi::kMaxBSSResumeAgeSeconds = 10;
 const char WiFi::kInterfaceStateUnknown[] = "shill-unknown";
+const time_t WiFi::kRescanIntervalSeconds = 1;
 
 WiFi::WiFi(ControlInterface *control_interface,
            EventDispatcher *dispatcher,
@@ -178,7 +179,15 @@
     // crosbug.com/25630
     supplicant_interface_proxy_->SetFastReauth(false);
   } catch (const DBus::Error e) {  // NOLINT
-    LOG(INFO) << "Failed to disable fast_reauth. "
+    LOG(INFO) << "Failed to disable fast_reauth."
+              << "May be running an older version of wpa_supplicant.";
+  }
+
+  try {
+    // Helps with passing WiFiRomaing.001SSIDSwitchBack.
+    supplicant_interface_proxy_->SetScanInterval(kRescanIntervalSeconds);
+  } catch (const DBus::Error e) {  // NOLINT
+    LOG(INFO) << "Failed to set scan_interval. "
               << "May be running an older version of wpa_supplicant.";
   }
 
diff --git a/wifi.h b/wifi.h
index 680457f..3363a98 100644
--- a/wifi.h
+++ b/wifi.h
@@ -169,6 +169,8 @@
   static const char kManagerErrorUnsupportedServiceMode[];
   static const time_t kMaxBSSResumeAgeSeconds;
   static const char kInterfaceStateUnknown[];
+  // Delay between scans when supplicant finds "No suitable network".
+  static const time_t kRescanIntervalSeconds;
 
   std::string CreateBgscanConfigString();
   std::string GetBgscanMethod(Error */* error */) { return bgscan_method_; }