shill: Save "Passphrase" property in WiFi services

Save and load the "Passphrase property", as well as saving a few
new Service properties that will be useful later on to get us out
of the habit of parsing the storage identifier.  Also update the
"Connectable" and "need_passphrase" state, so that Chome now
believes this service can be connected to without any user
intervention.

BUG=chromium-os:23467
TEST=Manual: With this change one can manually re-connect to a
stored service without re-entering credentials.

Change-Id: I25e1704ab4f9b6cb0be85d2205acc018415cddfc
Reviewed-on: https://gerrit.chromium.org/gerrit/12962
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
diff --git a/wifi_service.cc b/wifi_service.cc
index 38c0e0b..217dd1e 100644
--- a/wifi_service.cc
+++ b/wifi_service.cc
@@ -33,6 +33,10 @@
 namespace shill {
 
 const char WiFiService::kStorageHiddenSSID[] = "WiFi.HiddenSSID";
+const char WiFiService::kStorageMode[] = "WiFi.Mode";
+const char WiFiService::kStoragePassphrase[] = "Passphrase";
+const char WiFiService::kStorageSecurity[] = "WiFi.Security";
+const char WiFiService::kStorageSSID[] = "SSID";
 
 WiFiService::WiFiService(ControlInterface *control_interface,
                          EventDispatcher *dispatcher,
@@ -171,8 +175,10 @@
     error->Populate(Error::kNotSupported);
   }
 
-  if (error->IsSuccess())
+  if (error->IsSuccess()) {
     passphrase_ = passphrase;
+    need_passphrase_ = false;
+  }
 
   UpdateConnectable();
 }
@@ -215,8 +221,19 @@
   // Load properties specific to WiFi services.
   storage->GetBool(id, kStorageHiddenSSID, &hidden_ssid_);
 
-  // TODO(quiche): Load Passphrase property, ensure that UpdateConnectable
-  // is called (maybe via SetPassphrase). (crosbug.com/23467)
+  // NB: mode, security and ssid parameters are never read in from
+  // Load() as they are provided from the scan.
+
+  string passphrase;
+  if (storage->GetCryptedString(id, kStoragePassphrase, &passphrase)) {
+    Error error;
+    SetPassphrase(passphrase, &error);
+    if (!error.IsSuccess()) {
+      LOG(ERROR) << "Passphrase could not be set: "
+                 << Error::GetName(error.type());
+    }
+  }
+
   return true;
 }
 
@@ -228,7 +245,11 @@
 
   // Save properties specific to WiFi services.
   const string id = GetStorageIdentifier();
-  storage->SetBool(id, kStorageHiddenSSID, &hidden_ssid_);
+  storage->SetBool(id, kStorageHiddenSSID, hidden_ssid_);
+  storage->SetString(id, kStorageMode, mode_);
+  storage->SetCryptedString(id, kStoragePassphrase, passphrase_);
+  storage->SetString(id, kStorageSecurity, security_);
+  storage->SetString(id, kStorageSSID, hex_ssid_);
 
   // TODO(quiche): Save Passphrase property. (crosbug.com/23467)
   return true;