wpa_supplicant(hidl): Add support for get/set raw psk
Bug: 36013886
Test: Compiles & tested by using raw psk to connect to network.
Change-Id: Idb003050cd991d6a994ca2821dac618fe2b363a1
diff --git a/wpa_supplicant/hidl/sta_network.cpp b/wpa_supplicant/hidl/sta_network.cpp
index 3831660..a2d0126 100644
--- a/wpa_supplicant/hidl/sta_network.cpp
+++ b/wpa_supplicant/hidl/sta_network.cpp
@@ -193,6 +193,14 @@
&StaNetwork::setPskPassphraseInternal, _hidl_cb, psk);
}
+Return<void> StaNetwork::setPsk(
+ const hidl_array<uint8_t, 32> &psk, setPsk_cb _hidl_cb)
+{
+ return validateAndCall(
+ this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+ &StaNetwork::setPskInternal, _hidl_cb, psk);
+}
+
Return<void> StaNetwork::setWepKey(
uint32_t key_idx, const hidl_vec<uint8_t> &wep_key, setWepKey_cb _hidl_cb)
{
@@ -415,6 +423,13 @@
&StaNetwork::getPskPassphraseInternal, _hidl_cb);
}
+Return<void> StaNetwork::getPsk(getPsk_cb _hidl_cb)
+{
+ return validateAndCall(
+ this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+ &StaNetwork::getPskInternal, _hidl_cb);
+}
+
Return<void> StaNetwork::getWepKey(uint32_t key_idx, getWepKey_cb _hidl_cb)
{
return validateAndCall(
@@ -795,6 +810,18 @@
return {SupplicantStatusCode::SUCCESS, ""};
}
+SupplicantStatus StaNetwork::setPskInternal(const std::array<uint8_t, 32> &psk)
+{
+ struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
+ WPA_ASSERT(psk.size() == sizeof(wpa_ssid->psk));
+ str_clear_free(wpa_ssid->passphrase);
+ wpa_ssid->passphrase = nullptr;
+ os_memcpy(wpa_ssid->psk, psk.data(), sizeof(wpa_ssid->psk));
+ wpa_ssid->psk_set = 1;
+ resetInternalStateAfterParamsUpdate();
+ return {SupplicantStatusCode::SUCCESS, ""};
+}
+
SupplicantStatus StaNetwork::setWepKeyInternal(
uint32_t key_idx, const std::vector<uint8_t> &wep_key)
{
@@ -1163,11 +1190,23 @@
std::pair<SupplicantStatus, std::string> StaNetwork::getPskPassphraseInternal()
{
struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
- std::string psk;
- if (wpa_ssid->passphrase) {
- psk = wpa_ssid->passphrase;
+ if (!wpa_ssid->passphrase) {
+ return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
}
- return {{SupplicantStatusCode::SUCCESS, ""}, std::move(psk)};
+ return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->passphrase};
+}
+
+std::pair<SupplicantStatus, std::array<uint8_t, 32>>
+StaNetwork::getPskInternal()
+{
+ struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
+ WPA_ASSERT(psk.size() == sizeof(wpa_ssid->psk));
+ if (!wpa_ssid->psk_set) {
+ return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, {}};
+ }
+ std::array<uint8_t, 32> psk;
+ os_memcpy(psk.data(), wpa_ssid->psk, psk.size());
+ return {{SupplicantStatusCode::SUCCESS, ""}, psk};
}
std::pair<SupplicantStatus, std::vector<uint8_t>> StaNetwork::getWepKeyInternal(
diff --git a/wpa_supplicant/hidl/sta_network.h b/wpa_supplicant/hidl/sta_network.h
index c3b1a89..6e8d42b 100644
--- a/wpa_supplicant/hidl/sta_network.h
+++ b/wpa_supplicant/hidl/sta_network.h
@@ -76,6 +76,8 @@
setPairwiseCipher_cb _hidl_cb) override;
Return<void> setPskPassphrase(
const hidl_string& psk, setPskPassphrase_cb _hidl_cb) override;
+ Return<void> setPsk(
+ const hidl_array<uint8_t, 32>& psk, setPsk_cb _hidl_cb) override;
Return<void> setWepKey(
uint32_t key_idx, const hidl_vec<uint8_t>& wep_key,
setWepKey_cb _hidl_cb) override;
@@ -133,6 +135,7 @@
Return<void> getGroupCipher(getGroupCipher_cb _hidl_cb) override;
Return<void> getPairwiseCipher(getPairwiseCipher_cb _hidl_cb) override;
Return<void> getPskPassphrase(getPskPassphrase_cb _hidl_cb) override;
+ Return<void> getPsk(getPsk_cb _hidl_cb) override;
Return<void> getWepKey(
uint32_t key_idx, getWepKey_cb _hidl_cb) override;
Return<void> getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb) override;
@@ -200,6 +203,7 @@
SupplicantStatus setPairwiseCipherInternal(
uint32_t pairwise_cipher_mask);
SupplicantStatus setPskPassphraseInternal(const std::string& psk);
+ SupplicantStatus setPskInternal(const std::array<uint8_t, 32>& psk);
SupplicantStatus setWepKeyInternal(
uint32_t key_idx, const std::vector<uint8_t>& wep_key);
SupplicantStatus setWepTxKeyIdxInternal(uint32_t key_idx);
@@ -237,6 +241,7 @@
std::pair<SupplicantStatus, uint32_t> getGroupCipherInternal();
std::pair<SupplicantStatus, uint32_t> getPairwiseCipherInternal();
std::pair<SupplicantStatus, std::string> getPskPassphraseInternal();
+ std::pair<SupplicantStatus, std::array<uint8_t, 32>> getPskInternal();
std::pair<SupplicantStatus, std::vector<uint8_t>> getWepKeyInternal(
uint32_t key_idx);
std::pair<SupplicantStatus, uint32_t> getWepTxKeyIdxInternal();