shill: support association with open wifi access points

with this patch, shill organizes scan results into Endpoints and
Services. although this patch does not communicate information about
Services to the UI, one can connect to an open AP by sending the
appropriate message to shill over D-Bus.

known limitations:
- does not communicate to UI
- creates a Service for every Endpoint (note, however, that this
  does not provide the ability to connect to a specific AP)
- only supports open networks

note: a fix to memory management in wifi_integrationtest slipped
into this patch.

BUG=chromium-os:16065
TEST=manual: start shill, use dbus-send to tell shill to connect

Change-Id: I26737f5e61b56497beffb9639f3e347a21ad76d7
Reviewed-on: http://gerrit.chromium.org/gerrit/2910
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/wifi.h b/wifi.h
index f11fcea..f7e851a 100644
--- a/wifi.h
+++ b/wifi.h
@@ -16,6 +16,10 @@
 
 namespace shill {
 
+class WiFiEndpoint;
+typedef scoped_refptr<const WiFiEndpoint> WiFiEndpointConstRefPtr;
+typedef scoped_refptr<WiFiEndpoint> WiFiEndpointRefPtr;
+
 // WiFi class. Specialization of Device for WiFi.
 class WiFi : public Device {
  public:
@@ -35,6 +39,11 @@
                 const std::map<std::string, ::DBus::Variant> &properties);
   void ScanDone();
 
+  // called by WiFiService, to effect changes to wpa_supplicant
+  ::DBus::Path AddNetwork(
+      const std::map<std::string, ::DBus::Variant> &args);
+  void SelectNetwork(const ::DBus::Path &network);
+
  private:
   // SupplicantProcessProxy. provides access to wpa_supplicant's
   // process-level D-Bus APIs.
@@ -89,16 +98,27 @@
     WiFi &wifi_;
   };
 
+  typedef std::map<const std::string, WiFiEndpointRefPtr> EndpointMap;
+  typedef std::map<const std::string, ServiceRefPtr> ServiceMap;
+
   static const char kSupplicantPath[];
   static const char kSupplicantDBusAddr[];
   static const char kSupplicantWiFiDriver[];
   static const char kSupplicantErrorInterfaceExists[];
+  static const char kSupplicantKeyModeNone[];
 
+  void RealScanDone();
+
+  static unsigned int service_id_serial_;
+  ScopedRunnableMethodFactory<WiFi> task_factory_;
+  ControlInterface *control_interface_;
+  EventDispatcher *dispatcher_;
   DBus::Connection dbus_;
   scoped_ptr<SupplicantProcessProxy> supplicant_process_proxy_;
   scoped_ptr<SupplicantInterfaceProxy> supplicant_interface_proxy_;
   bool scan_pending_;
-  std::vector<std::string> ssids_;
+  EndpointMap endpoint_by_bssid_;
+  ServiceMap service_by_private_id_;
 
   // provide WiFiTest access to scan_pending_, so it can determine
   // if the scan completed, or timed out.