shill-test-proxy: Implement RPC methods (Part 11)

Implementation of the following RPC methods:
1. configure_service_by_guid
2. configure_wifi_service
3. connect_wifi

While there:
1. Remove an errorneous whitespace in |proxy_dbus_shill_wifi_client.cc|
2. Add |SetLogging| call in |init_test_network| RPC method to increase
shill & wpa_supplicant logging at the start of each test.

Bug: 25690385
TEST: `test_that --board=panther chromeos1-dev-host2.cros
network_WiFi_SimpleConnect.wifi_check11g`

Change-Id: Ic5d460bc6e8c6a99bc8c67344f225e729eedffe3
diff --git a/test-rpc-proxy/proxy_dbus_shill_wifi_client.cc b/test-rpc-proxy/proxy_dbus_shill_wifi_client.cc
index fb739e1..8238261 100644
--- a/test-rpc-proxy/proxy_dbus_shill_wifi_client.cc
+++ b/test-rpc-proxy/proxy_dbus_shill_wifi_client.cc
@@ -402,7 +402,7 @@
     auto entry_ids = property_value.Get<std::vector<std::string>>();
     for (const auto& entry_id : entry_ids) {
       brillo::VariantDictionary entry_props;
-      if ((profile->GetEntry(entry_id, &entry_props, nullptr)) && 
+      if ((profile->GetEntry(entry_id, &entry_props, nullptr)) &&
           (entry_props[shill::kNameProperty].Get<std::string>() == ssid)) {
         profile->DeleteEntry(entry_id, nullptr);
       }
diff --git a/test-rpc-proxy/proxy_rpc_server.cc b/test-rpc-proxy/proxy_rpc_server.cc
index ec5c02f..4ddaaa6 100644
--- a/test-rpc-proxy/proxy_rpc_server.cc
+++ b/test-rpc-proxy/proxy_rpc_server.cc
@@ -16,6 +16,8 @@
 
 #include <base/bind.h>
 
+#include "proxy_rpc_in_data_types.h"
+#include "proxy_rpc_out_data_types.h"
 #include "proxy_rpc_server.h"
 #include "proxy_util.h"
 
@@ -85,6 +87,94 @@
   return shill_wifi_client->CleanProfiles();
 }
 
+XmlRpc::XmlRpcValue ConfigureServiceByGuid(
+    XmlRpc::XmlRpcValue params_in,
+    ProxyShillWifiClient* shill_wifi_client) {
+  if (!ValidateNumOfElements(params_in, 1)) {
+    return false;
+  }
+  ConfigureServiceParameters config_params(&params_in[0]);
+  return shill_wifi_client->ConfigureServiceByGuid(
+      config_params.guid_,
+      config_params.autoconnect_type_,
+      config_params.passphrase_);
+}
+
+XmlRpc::XmlRpcValue ConfigureWifiService(
+    XmlRpc::XmlRpcValue params_in,
+    ProxyShillWifiClient* shill_wifi_client) {
+  if (!ValidateNumOfElements(params_in, 1)) {
+    return false;
+  }
+  AssociationParameters assoc_params(&params_in[0]);
+  brillo::VariantDictionary security_params;
+  assoc_params.security_config_->GetServiceProperties(&security_params);
+  return shill_wifi_client->ConfigureWifiService(
+      assoc_params.ssid_,
+      assoc_params.security_config_->security_,
+      security_params,
+      assoc_params.save_credentials_,
+      assoc_params.station_type_,
+      assoc_params.is_hidden_,
+      assoc_params.guid_,
+      assoc_params.autoconnect_type_);
+}
+
+XmlRpc::XmlRpcValue ConnectWifi(
+    XmlRpc::XmlRpcValue params_in,
+    ProxyShillWifiClient* shill_wifi_client) {
+  if (!ValidateNumOfElements(params_in, 1)) {
+    return false;
+  }
+
+  AssociationParameters assoc_params(&params_in[0]);
+  std::string wifi_interface = assoc_params.bgscan_config_->interface_;
+  if (wifi_interface.empty()) {
+    std::vector<std::string> interfaces;
+    if (!shill_wifi_client->ListControlledWifiInterfaces(&interfaces) ||
+        interfaces.empty()) {
+      return false;
+    }
+    wifi_interface = interfaces[0];
+  }
+  shill_wifi_client->ConfigureBgScan(
+      wifi_interface,
+      assoc_params.bgscan_config_->method_,
+      assoc_params.bgscan_config_->short_interval_,
+      assoc_params.bgscan_config_->long_interval_,
+      assoc_params.bgscan_config_->signal_threshold_);
+
+  brillo::VariantDictionary security_params;
+  assoc_params.security_config_->GetServiceProperties(&security_params);
+
+  long discovery_time, association_time, configuration_time;
+  std::string failure_reason;
+  bool is_success = shill_wifi_client->ConnectToWifiNetwork(
+      assoc_params.ssid_,
+      assoc_params.security_config_->security_,
+      security_params,
+      assoc_params.save_credentials_,
+      assoc_params.station_type_,
+      assoc_params.is_hidden_,
+      assoc_params.guid_,
+      assoc_params.autoconnect_type_,
+      GetMillisecondsFromSeconds(assoc_params.discovery_timeout_seconds_),
+      GetMillisecondsFromSeconds(assoc_params.association_timeout_seconds_),
+      GetMillisecondsFromSeconds(assoc_params.configuration_timeout_seconds_),
+      &discovery_time,
+      &association_time,
+      &configuration_time,
+      &failure_reason);
+
+  AssociationResult association_result(
+      is_success,
+      GetSecondsFromMilliseconds(discovery_time),
+      GetSecondsFromMilliseconds(association_time),
+      GetSecondsFromMilliseconds(configuration_time),
+      failure_reason);
+  return association_result.ConvertToXmlRpcValue();
+}
+
 XmlRpc::XmlRpcValue DeleteEntriesForSsid(
     XmlRpc::XmlRpcValue params_in,
     ProxyShillWifiClient* shill_wifi_client) {
@@ -101,6 +191,7 @@
   if (!ValidateNumOfElements(params_in, 0)) {
     return false;
   }
+  shill_wifi_client->SetLogging();
   shill_wifi_client->CleanProfiles();
   shill_wifi_client->RemoveAllWifiEntries();
   shill_wifi_client->RemoveProfile(kTestProfileName);
@@ -433,6 +524,10 @@
   RegisterRpcMethod("push_profile", base::Bind(&PushProfile));
   RegisterRpcMethod("pop_profile", base::Bind(&PopProfile));
   RegisterRpcMethod("clean_profiles", base::Bind(&CleanProfiles));
+  RegisterRpcMethod("configure_service_by_guid",
+                    base::Bind(&ConfigureServiceByGuid));
+  RegisterRpcMethod("configure_wifi_service", base::Bind(&ConfigureWifiService));
+  RegisterRpcMethod("connect_wifi", base::Bind(&ConnectWifi));
   RegisterRpcMethod("delete_entries_for_ssid", base::Bind(&DeleteEntriesForSsid));
   RegisterRpcMethod("init_test_network_state", base::Bind(&InitTestNetworkState));
   RegisterRpcMethod("list_controlled_wifi_interfaces",