Merge "conman:  Add wpa_supplicant control interface connection status." into wifitv
diff --git a/conman/connection_manager.py b/conman/connection_manager.py
index d9ccefc..f925c26 100755
--- a/conman/connection_manager.py
+++ b/conman/connection_manager.py
@@ -272,7 +272,8 @@
         wifi_up = self.is_interface_up(wifi.name)
         self.ifplugd_action(wifi.name, wifi_up)
         if wifi_up:
-          wifi.attach_wpa_control(self._wpa_control_interface)
+          self._status.attached_to_wpa_supplicant = wifi.attach_wpa_control(
+              self._wpa_control_interface)
 
     for path, prefix in ((self._tmp_dir, self.GATEWAY_FILE_PREFIX),
                          (self._interface_status_dir, ''),
@@ -374,7 +375,8 @@
       if not wifi.attached():
         logging.debug('Attempting to attach to wpa control interface for %s',
                       wifi.name)
-        wifi.attach_wpa_control(self._wpa_control_interface)
+        self._status.attached_to_wpa_supplicant = wifi.attach_wpa_control(
+            self._wpa_control_interface)
       wifi.handle_wpa_events()
 
       # Only one wlan_configuration per interface will have access_point ==
diff --git a/conman/interface.py b/conman/interface.py
index 0f42e20..0d81b65 100755
--- a/conman/interface.py
+++ b/conman/interface.py
@@ -333,8 +333,16 @@
     return self._wpa_control and self._wpa_control.attached
 
   def attach_wpa_control(self, path):
+    """Attach to the wpa_supplicant control interface.
+
+    Args:
+      path:  The path containing the wpa_supplicant control interface socket.
+
+    Returns:
+      Whether attaching was successful.
+    """
     if self.attached():
-      return
+      return True
 
     socket = os.path.join(path, self.name)
     if os.path.exists(socket):
@@ -343,7 +351,7 @@
         self._wpa_control.attach()
       except wpactrl.error as e:
         logging.error('Error attaching to wpa_supplicant: %s', e)
-        return
+        return False
 
       for line in self._wpa_control.request('STATUS').splitlines():
         if '=' not in line:
@@ -353,6 +361,11 @@
           self.wpa_supplicant = value == 'COMPLETED'
         elif key == 'ssid' and not self._initialized:
           self.initial_ssid = value
+    else:
+      logging.error('wpa control socket does not exist: %s', socket)
+      return False
+
+    return True
 
   def get_wpa_control(self, socket):
     return wpactrl.WPACtrl(socket)
diff --git a/conman/status.py b/conman/status.py
index 1026a0b..e21dc01 100644
--- a/conman/status.py
+++ b/conman/status.py
@@ -29,6 +29,7 @@
   COULD_REACH_ACS = 'COULD_REACH_ACS'
   CAN_REACH_INTERNET = 'CAN_REACH_INTERNET'
   PROVISIONING_FAILED = 'PROVISIONING_FAILED'
+  ATTACHED_TO_WPA_SUPPLICANT = 'ATTACHED_TO_WPA_SUPPLICANT'
 
 
 # Format:  { proposition: (implications, counter-implications), ... }
@@ -66,6 +67,10 @@
         (P.HAVE_CONFIG,),
         (),
     ),
+    P.ATTACHED_TO_WPA_SUPPLICANT: (
+        (),
+        (),
+    )
 }
 
 
@@ -78,7 +83,7 @@
   def __init__(self, name, export_path):
     self._name = name
     self._export_path = export_path
-    self._value = False
+    self._value = None
     self._implications = set()
     self._counter_implications = set()
     self._impliers = set()