wpa_supplicant(hidl): Add set/get for eap private key id

"private_key" field is not used in Android, we instead use the
"key_id" field. So, change the setter to reflect that.

While there,
Set an empty string for eap phase2 method if it's set to none. This is
what is being done currently in the socket interface.

Bug: 35663125
Test: Compiles
Test: Able to connect to Hotspot 2.0 networks.
Change-Id: Ic193fb3606a9e35a3fe3dba36117201d2500183c
diff --git a/wpa_supplicant/hidl/sta_network.cpp b/wpa_supplicant/hidl/sta_network.cpp
index 3d92973..b58d85b 100644
--- a/wpa_supplicant/hidl/sta_network.cpp
+++ b/wpa_supplicant/hidl/sta_network.cpp
@@ -58,7 +58,7 @@
     static_cast<uint32_t>(ISupplicantStaNetwork::EapPhase2Method::AKA_PRIME) +
     1;
 constexpr char const *kEapPhase2MethodStrings[kEapPhase2MethodMax] = {
-    "NULL", "PAP", "MSCHAP", "MSCHAPV2", "GTC", "SIM", "AKA", "AKA'"};
+    "", "PAP", "MSCHAP", "MSCHAPV2", "GTC", "SIM", "AKA", "AKA'"};
 constexpr char kEapPhase2AuthPrefix[] = "auth=";
 constexpr char kEapPhase2AuthEapPrefix[] = "autheap=";
 constexpr char kNetworkEapSimGsmAuthResponse[] = "GSM-AUTH";
@@ -281,12 +281,12 @@
 	    &StaNetwork::setEapClientCertInternal, _hidl_cb, path);
 }
 
-Return<void> StaNetwork::setEapPrivateKey(
-    const hidl_string &path, setEapPrivateKey_cb _hidl_cb)
+Return<void> StaNetwork::setEapPrivateKeyId(
+    const hidl_string &id, setEapPrivateKeyId_cb _hidl_cb)
 {
 	return validateAndCall(
 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-	    &StaNetwork::setEapPrivateKeyInternal, _hidl_cb, path);
+	    &StaNetwork::setEapPrivateKeyIdInternal, _hidl_cb, id);
 }
 
 Return<void> StaNetwork::setEapSubjectMatch(
@@ -493,11 +493,11 @@
 	    &StaNetwork::getEapClientCertInternal, _hidl_cb);
 }
 
-Return<void> StaNetwork::getEapPrivateKey(getEapPrivateKey_cb _hidl_cb)
+Return<void> StaNetwork::getEapPrivateKeyId(getEapPrivateKeyId_cb _hidl_cb)
 {
 	return validateAndCall(
 	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-	    &StaNetwork::getEapPrivateKeyInternal, _hidl_cb);
+	    &StaNetwork::getEapPrivateKeyIdInternal, _hidl_cb);
 }
 
 Return<void> StaNetwork::getEapSubjectMatch(getEapSubjectMatch_cb _hidl_cb)
@@ -918,7 +918,10 @@
 			"EAP method not set"};
 	}
 	std::string eap_phase2_str;
-	if (eap_method == ISupplicantStaNetwork::EapMethod::TTLS &&
+	if (method == ISupplicantStaNetwork::EapPhase2Method::NONE) {
+		eap_phase2_str = "";
+	} else if (
+	    eap_method == ISupplicantStaNetwork::EapMethod::TTLS &&
 	    method == ISupplicantStaNetwork::EapPhase2Method::GTC) {
 		eap_phase2_str = kEapPhase2AuthEapPrefix;
 	} else {
@@ -1004,12 +1007,11 @@
 	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-SupplicantStatus StaNetwork::setEapPrivateKeyInternal(const std::string &path)
+SupplicantStatus StaNetwork::setEapPrivateKeyIdInternal(const std::string &id)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
 	if (setStringFieldAndResetState(
-		path.c_str(), &(wpa_ssid->eap.private_key),
-		"eap private_key")) {
+		id.c_str(), &(wpa_ssid->eap.key_id), "eap key_id")) {
 		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	return {SupplicantStatusCode::SUCCESS, ""};
@@ -1326,14 +1328,14 @@
 		reinterpret_cast<char *>(wpa_ssid->eap.client_cert)};
 }
 
-std::pair<SupplicantStatus, std::string> StaNetwork::getEapPrivateKeyInternal()
+std::pair<SupplicantStatus, std::string>
+StaNetwork::getEapPrivateKeyIdInternal()
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid->eap.private_key) {
+	if (!wpa_ssid->eap.key_id) {
 		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
 	}
-	return {{SupplicantStatusCode::SUCCESS, ""},
-		reinterpret_cast<char *>(wpa_ssid->eap.private_key)};
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->eap.key_id};
 }
 
 std::pair<SupplicantStatus, std::string>
diff --git a/wpa_supplicant/hidl/sta_network.h b/wpa_supplicant/hidl/sta_network.h
index c0df028..c3b1a89 100644
--- a/wpa_supplicant/hidl/sta_network.h
+++ b/wpa_supplicant/hidl/sta_network.h
@@ -104,8 +104,8 @@
 	    const hidl_string& path, setEapCAPath_cb _hidl_cb) override;
 	Return<void> setEapClientCert(
 	    const hidl_string& path, setEapClientCert_cb _hidl_cb) override;
-	Return<void> setEapPrivateKey(
-	    const hidl_string& path, setEapPrivateKey_cb _hidl_cb) override;
+	Return<void> setEapPrivateKeyId(
+	    const hidl_string& id, setEapPrivateKeyId_cb _hidl_cb) override;
 	Return<void> setEapSubjectMatch(
 	    const hidl_string& match, setEapSubjectMatch_cb _hidl_cb) override;
 	Return<void> setEapAltSubjectMatch(
@@ -147,7 +147,8 @@
 	Return<void> getEapCACert(getEapCACert_cb _hidl_cb) override;
 	Return<void> getEapCAPath(getEapCAPath_cb _hidl_cb) override;
 	Return<void> getEapClientCert(getEapClientCert_cb _hidl_cb) override;
-	Return<void> getEapPrivateKey(getEapPrivateKey_cb _hidl_cb) override;
+	Return<void> getEapPrivateKeyId(
+	    getEapPrivateKeyId_cb _hidl_cb) override;
 	Return<void> getEapSubjectMatch(
 	    getEapSubjectMatch_cb _hidl_cb) override;
 	Return<void> getEapAltSubjectMatch(
@@ -216,7 +217,7 @@
 	SupplicantStatus setEapCACertInternal(const std::string& path);
 	SupplicantStatus setEapCAPathInternal(const std::string& path);
 	SupplicantStatus setEapClientCertInternal(const std::string& path);
-	SupplicantStatus setEapPrivateKeyInternal(const std::string& path);
+	SupplicantStatus setEapPrivateKeyIdInternal(const std::string& id);
 	SupplicantStatus setEapSubjectMatchInternal(const std::string& match);
 	SupplicantStatus setEapAltSubjectMatchInternal(
 	    const std::string& match);
@@ -253,7 +254,7 @@
 	std::pair<SupplicantStatus, std::string> getEapCACertInternal();
 	std::pair<SupplicantStatus, std::string> getEapCAPathInternal();
 	std::pair<SupplicantStatus, std::string> getEapClientCertInternal();
-	std::pair<SupplicantStatus, std::string> getEapPrivateKeyInternal();
+	std::pair<SupplicantStatus, std::string> getEapPrivateKeyIdInternal();
 	std::pair<SupplicantStatus, std::string> getEapSubjectMatchInternal();
 	std::pair<SupplicantStatus, std::string>
 	getEapAltSubjectMatchInternal();