Merge changes I46d85902,Idba0ad35,Ic3718468,Ia1e40e1d,I501f8a02, ...

* changes:
  wpa_supplicant(hidl): Add ANQP stub methods
  wpa_supplicant(hidl): Add P2P stub methods
  wpa_supplicant(hidl): Invalidate objects in HidlManager
  wpa_supplicant(hidl): Use hidl_return_util in |P2pNetwork|
  wpa_supplicant(hidl): Use hidl_return_util in |P2pIface|
  wpa_supplicant(hidl): Use hidl_return_util in |StaNetwork|
  wpa_supplicant(hidl): Use hidl_return_util in |StaIface|
  wpa_supplicant(hidl): Use hidl_return_util in |Supplicant|
  wpa_supplicant(hidl): Helper functions for invoking hidl cont callbacks
diff --git a/wpa_supplicant/hidl/hidl_manager.cpp b/wpa_supplicant/hidl/hidl_manager.cpp
index c5705d1..90a0c22 100644
--- a/wpa_supplicant/hidl/hidl_manager.cpp
+++ b/wpa_supplicant/hidl/hidl_manager.cpp
@@ -91,9 +91,11 @@
     std::map<const std::string, android::sp<ObjectType>> &object_map)
 {
 	// Return failure if we dont have an object for that |key|.
-	if (object_map.find(key) == object_map.end())
+	const auto &object_iter = object_map.find(key);
+	if (object_iter == object_map.end())
 		return 1;
-	object_map.erase(key);
+	object_iter->second->invalidate();
+	object_map.erase(object_iter);
 	return 0;
 }
 
diff --git a/wpa_supplicant/hidl/hidl_return_macros.h b/wpa_supplicant/hidl/hidl_return_macros.h
deleted file mode 100644
index 25e8f49..0000000
--- a/wpa_supplicant/hidl/hidl_return_macros.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * hidl interface for wpa_supplicant daemon
- * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
- *
- * This software may be distributed under the terms of the BSD license.
- * See README for more details.
- */
-
-// Macros to invoke the _hidl_cb to return status along with any return values.
-#define HIDL_RETURN(status_code, ...)                         \
-	do {                                                  \
-		SupplicantStatus status{.code = status_code}; \
-		_hidl_cb(status, ##__VA_ARGS__);              \
-		return Void();                                \
-	} while (false)
diff --git a/wpa_supplicant/hidl/hidl_return_util.h b/wpa_supplicant/hidl/hidl_return_util.h
new file mode 100644
index 0000000..c077fc8
--- /dev/null
+++ b/wpa_supplicant/hidl/hidl_return_util.h
@@ -0,0 +1,101 @@
+/*
+ * hidl interface for wpa_supplicant daemon
+ * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef HIDL_RETURN_UTIL_H_
+#define HIDL_RETURN_UTIL_H_
+
+namespace android {
+namespace hardware {
+namespace wifi {
+namespace supplicant {
+namespace V1_0 {
+namespace implementation {
+namespace hidl_return_util {
+
+/**
+ * These utility functions are used to invoke a method on the provided
+ * HIDL interface object.
+ * These functions checks if the provided HIDL interface object is valid.
+ * a) if valid, Invokes the corresponding internal implementation function of
+ * the HIDL method. It then invokes the HIDL continuation callback with
+ * the status and any returned values.
+ * b) if invalid, invokes the HIDL continuation callback with the
+ * provided error status and default values.
+ */
+// Use for HIDL methods which return only an instance of SupplicantStatus.
+template <typename ObjT, typename WorkFuncT, typename... Args>
+Return<void> validateAndCall(
+    ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
+    const std::function<void(const SupplicantStatus&)>& hidl_cb, Args&&... args)
+{
+	if (obj->isValid()) {
+		hidl_cb((obj->*work)(std::forward<Args>(args)...));
+	} else {
+		hidl_cb({status_code_if_invalid, ""});
+	}
+	return Void();
+}
+
+// Use for HIDL methods which return instance of SupplicantStatus and a single
+// return value.
+template <typename ObjT, typename WorkFuncT, typename ReturnT, typename... Args>
+Return<void> validateAndCall(
+    ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
+    const std::function<void(const SupplicantStatus&, ReturnT)>& hidl_cb,
+    Args&&... args)
+{
+	if (obj->isValid()) {
+		const auto& ret_pair =
+		    (obj->*work)(std::forward<Args>(args)...);
+		const SupplicantStatus& status = std::get<0>(ret_pair);
+		const auto& ret_value = std::get<1>(ret_pair);
+		hidl_cb(status, ret_value);
+	} else {
+		hidl_cb(
+		    {status_code_if_invalid, ""},
+		    typename std::remove_reference<ReturnT>::type());
+	}
+	return Void();
+}
+
+// Use for HIDL methods which return instance of SupplicantStatus and 2 return
+// values.
+template <
+    typename ObjT, typename WorkFuncT, typename ReturnT1, typename ReturnT2,
+    typename... Args>
+Return<void> validateAndCall(
+    ObjT* obj, SupplicantStatusCode status_code_if_invalid, WorkFuncT&& work,
+    const std::function<void(const SupplicantStatus&, ReturnT1, ReturnT2)>&
+	hidl_cb,
+    Args&&... args)
+{
+	if (obj->isValid()) {
+		const auto& ret_tuple =
+		    (obj->*work)(std::forward<Args>(args)...);
+		const SupplicantStatus& status = std::get<0>(ret_tuple);
+		const auto& ret_value1 = std::get<1>(ret_tuple);
+		const auto& ret_value2 = std::get<2>(ret_tuple);
+		hidl_cb(status, ret_value1, ret_value2);
+	} else {
+		hidl_cb(
+		    {status_code_if_invalid, ""},
+		    typename std::remove_reference<ReturnT1>::type(),
+		    typename std::remove_reference<ReturnT2>::type());
+	}
+	return Void();
+}
+
+}  // namespace hidl_util
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace supplicant
+}  // namespace wifi
+}  // namespace hardware
+}  // namespace android
+#endif  // HIDL_RETURN_UTIL_H_
diff --git a/wpa_supplicant/hidl/p2p_iface.cpp b/wpa_supplicant/hidl/p2p_iface.cpp
index e9ee986..47f3cc5 100644
--- a/wpa_supplicant/hidl/p2p_iface.cpp
+++ b/wpa_supplicant/hidl/p2p_iface.cpp
@@ -8,7 +8,7 @@
  */
 
 #include "hidl_manager.h"
-#include "hidl_return_macros.h"
+#include "hidl_return_util.h"
 #include "p2p_iface.h"
 
 namespace android {
@@ -17,137 +17,557 @@
 namespace supplicant {
 namespace V1_0 {
 namespace implementation {
+using hidl_return_util::validateAndCall;
 
-P2pIface::P2pIface(struct wpa_global *wpa_global, const char ifname[])
-    : wpa_global_(wpa_global), ifname_(ifname)
+P2pIface::P2pIface(struct wpa_global* wpa_global, const char ifname[])
+    : wpa_global_(wpa_global), ifname_(ifname), is_valid_(true)
 {
 }
 
+void P2pIface::invalidate() { is_valid_ = false; }
+bool P2pIface::isValid()
+{
+	return (is_valid_ && (retrieveIfacePtr() != nullptr));
+}
 Return<void> P2pIface::getName(getName_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, ifname_);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, ifname_);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::getNameInternal, _hidl_cb);
 }
 
 Return<void> P2pIface::getType(getType_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID,
-		    IfaceType::STA);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, IfaceType::STA);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::getTypeInternal, _hidl_cb);
 }
 
 Return<void> P2pIface::addNetwork(addNetwork_cb _hidl_cb)
 {
-	android::sp<ISupplicantP2pNetwork> network;
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, network);
-	}
-
-	struct wpa_ssid *ssid = wpa_supplicant_add_network(wpa_s);
-	if (!ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, network);
-	}
-
-	HidlManager *hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->getP2pNetworkHidlObjectByIfnameAndNetworkId(
-		wpa_s->ifname, ssid->id, &network)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, network);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, network);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::addNetworkInternal, _hidl_cb);
 }
 
-Return<void> P2pIface::removeNetwork(uint32_t id, removeNetwork_cb _hidl_cb)
+Return<void> P2pIface::removeNetwork(
+    SupplicantNetworkId id, removeNetwork_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	int result = wpa_supplicant_remove_network(wpa_s, id);
-	if (result == -1) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN);
-	}
-
-	if (result != 0) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::removeNetworkInternal, _hidl_cb, id);
 }
 
-Return<void> P2pIface::getNetwork(uint32_t id, getNetwork_cb _hidl_cb)
+Return<void> P2pIface::getNetwork(
+    SupplicantNetworkId id, getNetwork_cb _hidl_cb)
 {
-	android::sp<ISupplicantP2pNetwork> network;
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, network);
-	}
-
-	struct wpa_ssid *ssid = wpa_config_get_network(wpa_s->conf, id);
-	if (!ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, network);
-	}
-
-	HidlManager *hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->getP2pNetworkHidlObjectByIfnameAndNetworkId(
-		wpa_s->ifname, ssid->id, &network)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, network);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, network);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::getNetworkInternal, _hidl_cb, id);
 }
 
 Return<void> P2pIface::listNetworks(listNetworks_cb _hidl_cb)
 {
-	std::vector<uint32_t> network_ids;
-
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, network_ids);
-	}
-
-	for (struct wpa_ssid *wpa_ssid = wpa_s->conf->ssid; wpa_ssid;
-	     wpa_ssid = wpa_ssid->next) {
-		network_ids.emplace_back(wpa_ssid->id);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, network_ids);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::listNetworksInternal, _hidl_cb);
 }
 
 Return<void> P2pIface::registerCallback(
-    const sp<ISupplicantP2pIfaceCallback> &callback,
+    const sp<ISupplicantP2pIfaceCallback>& callback,
     registerCallback_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveP2pIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::registerCallbackInternal, _hidl_cb, callback);
+}
 
-	HidlManager *hidl_manager = HidlManager::getInstance();
+Return<void> P2pIface::getDeviceAddress(getDeviceAddress_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::getDeviceAddressInternal, _hidl_cb);
+}
+
+Return<void> P2pIface::setSsidPostfix(
+    const hidl_string& postfix, setSsidPostfix_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::setSsidPostfixInternal, _hidl_cb, postfix);
+}
+
+Return<void> P2pIface::setGroupIdle(
+    uint32_t timeout_in_sec, setGroupIdle_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::setGroupIdleInternal, _hidl_cb, timeout_in_sec);
+}
+
+Return<void> P2pIface::setPowerSave(bool enable, setPowerSave_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::setPowerSaveInternal, _hidl_cb, enable);
+}
+
+Return<void> P2pIface::find(uint32_t timeout_in_sec, find_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::findInternal, _hidl_cb, timeout_in_sec);
+}
+
+Return<void> P2pIface::stopFind(stopFind_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::stopFindInternal, _hidl_cb);
+}
+
+Return<void> P2pIface::flush(flush_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::flushInternal, _hidl_cb);
+}
+
+Return<void> P2pIface::connect(
+    const hidl_array<uint8_t, 6>& peer_address,
+    ISupplicantP2pIface::WpsProvisionMethod provision_method,
+    const hidl_vec<uint8_t>& pre_selected_pin, bool join_existing_group,
+    bool persistent, uint32_t go_intent, connect_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::connectInternal, _hidl_cb, peer_address,
+	    provision_method, pre_selected_pin, join_existing_group, persistent,
+	    go_intent);
+}
+
+Return<void> P2pIface::cancelConnect(cancelConnect_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::cancelConnectInternal, _hidl_cb);
+}
+
+Return<void> P2pIface::provisionDiscovery(
+    const hidl_array<uint8_t, 6>& peer_address,
+    ISupplicantP2pIface::WpsProvisionMethod provision_method,
+    provisionDiscovery_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::provisionDiscoveryInternal, _hidl_cb, peer_address,
+	    provision_method);
+}
+
+Return<void> P2pIface::addGroup(
+    bool persistent, uint32_t persistent_network_id, addGroup_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::addGroupInternal, _hidl_cb, persistent,
+	    persistent_network_id);
+}
+
+Return<void> P2pIface::removeGroup(
+    const hidl_string& group_ifname, removeGroup_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::removeGroupInternal, _hidl_cb, group_ifname);
+}
+
+Return<void> P2pIface::reject(
+    const hidl_array<uint8_t, 6>& peer_address, reject_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::rejectInternal, _hidl_cb, peer_address);
+}
+
+Return<void> P2pIface::invite(
+    const hidl_string& group_ifname,
+    const hidl_array<uint8_t, 6>& go_device_address,
+    const hidl_array<uint8_t, 6>& peer_address, invite_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::inviteInternal, _hidl_cb, go_device_address,
+	    peer_address);
+}
+
+Return<void> P2pIface::reinvoke(
+    uint32_t persistent_network_id, const hidl_array<uint8_t, 6>& peer_address,
+    reinvoke_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::reinvokeInternal, _hidl_cb, persistent_network_id,
+	    peer_address);
+}
+
+Return<void> P2pIface::configureExtListen(
+    bool enable, uint32_t period_in_millis, uint32_t interval_in_millis,
+    configureExtListen_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::configureExtListenInternal, _hidl_cb, enable,
+	    period_in_millis, interval_in_millis);
+}
+
+Return<void> P2pIface::setListenChannel(
+    uint32_t channel, uint32_t operating_class, setListenChannel_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::setListenChannelInternal, _hidl_cb, channel,
+	    operating_class);
+}
+
+Return<void> P2pIface::getSsid(
+    const hidl_array<uint8_t, 6>& peer_address, getSsid_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::getSsidInternal, _hidl_cb, peer_address);
+}
+
+Return<void> P2pIface::getGroupCapability(
+    const hidl_array<uint8_t, 6>& peer_address, getGroupCapability_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::getGroupCapabilityInternal, _hidl_cb, peer_address);
+}
+
+Return<void> P2pIface::addBonjourService(
+    const hidl_vec<uint8_t>& query, const hidl_vec<uint8_t>& response,
+    addBonjourService_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::addBonjourServiceInternal, _hidl_cb, query, response);
+}
+
+Return<void> P2pIface::removeBonjourService(
+    const hidl_vec<uint8_t>& query, removeBonjourService_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::removeBonjourServiceInternal, _hidl_cb, query);
+}
+
+Return<void> P2pIface::addUpnpService(
+    uint32_t version, const hidl_string& service_name,
+    addUpnpService_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::addUpnpServiceInternal, _hidl_cb, version, service_name);
+}
+
+Return<void> P2pIface::removeUpnpService(
+    uint32_t version, const hidl_string& service_name,
+    removeUpnpService_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::removeUpnpServiceInternal, _hidl_cb, version,
+	    service_name);
+}
+
+Return<void> P2pIface::flushServices(
+    uint32_t version, const hidl_string& service_name,
+    flushServices_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::flushServicesInternal, _hidl_cb, version, service_name);
+}
+
+Return<void> P2pIface::requestServiceDiscovery(
+    const hidl_array<uint8_t, 6>& peer_address, const hidl_vec<uint8_t>& query,
+    requestServiceDiscovery_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::requestServiceDiscoveryInternal, _hidl_cb, version,
+	    peer_address, query);
+}
+
+Return<void> P2pIface::cancelServiceDiscovery(
+    uint64_t identifier, cancelServiceDiscovery_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &P2pIface::cancelServiceDiscoveryInternal, _hidl_cb, identifier);
+}
+
+std::pair<SupplicantStatus, std::string> P2pIface::getNameInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
+}
+
+std::pair<SupplicantStatus, IfaceType> P2pIface::getTypeInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::P2P};
+}
+
+std::pair<SupplicantStatus, sp<ISupplicantP2pNetwork>>
+P2pIface::addNetworkInternal()
+{
+	android::sp<ISupplicantP2pNetwork> network;
+	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
+	struct wpa_ssid* ssid = wpa_supplicant_add_network(wpa_s);
+	if (!ssid) {
+		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
+	}
+	HidlManager* hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->getP2pNetworkHidlObjectByIfnameAndNetworkId(
+		wpa_s->ifname, ssid->id, &network)) {
+		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, network};
+}
+
+SupplicantStatus P2pIface::removeNetworkInternal(SupplicantNetworkId id)
+{
+	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
+	int result = wpa_supplicant_remove_network(wpa_s, id);
+	if (result == -1) {
+		return {SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, ""};
+	}
+	if (result != 0) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+std::pair<SupplicantStatus, sp<ISupplicantP2pNetwork>>
+P2pIface::getNetworkInternal(SupplicantNetworkId id)
+{
+	android::sp<ISupplicantP2pNetwork> network;
+	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
+	struct wpa_ssid* ssid = wpa_config_get_network(wpa_s->conf, id);
+	if (!ssid) {
+		return {{SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, ""},
+			network};
+	}
+	HidlManager* hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->getP2pNetworkHidlObjectByIfnameAndNetworkId(
+		wpa_s->ifname, ssid->id, &network)) {
+		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, network};
+}
+
+std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
+P2pIface::listNetworksInternal()
+{
+	std::vector<SupplicantNetworkId> network_ids;
+	struct wpa_supplicant* wpa_s = retrieveIfacePtr();
+	for (struct wpa_ssid* wpa_ssid = wpa_s->conf->ssid; wpa_ssid;
+	     wpa_ssid = wpa_ssid->next) {
+		network_ids.emplace_back(wpa_ssid->id);
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(network_ids)};
+}
+
+SupplicantStatus P2pIface::registerCallbackInternal(
+    const sp<ISupplicantP2pIfaceCallback>& callback)
+{
+	HidlManager* hidl_manager = HidlManager::getInstance();
 	if (!hidl_manager ||
 	    hidl_manager->addP2pIfaceCallbackHidlObject(ifname_, callback)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
 
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+std::pair<SupplicantStatus, std::array<uint8_t, 6>>
+P2pIface::getDeviceAddressInternal()
+{
+	// TODO: Add implementation.
+	return {{SupplicantStatusCode::SUCCESS, ""}, {}};
+}
+
+SupplicantStatus P2pIface::setSsidPostfixInternal(const hidl_string& postfix)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::setGroupIdleInternal(uint32_t timeout_in_sec)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::setPowerSaveInternal(bool enable)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::findInternal(uint32_t timeout_in_sec)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::stopFindInternal()
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::flushInternal()
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+std::pair<SupplicantStatus, std::vector<uint8_t>> P2pIface::connectInternal(
+    const hidl_array<uint8_t, 6>& peer_address,
+    ISupplicantP2pIface::WpsProvisionMethod provision_method,
+    const hidl_vec<uint8_t>& pre_selected_pin, bool join_existing_group,
+    bool persistent, uint32_t go_intent)
+{
+	// TODO: Add implementation.
+	return {{SupplicantStatusCode::SUCCESS, ""}, {}};
+}
+
+SupplicantStatus P2pIface::cancelConnectInternal()
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::provisionDiscoveryInternal(
+    const hidl_array<uint8_t, 6>& peer_address,
+    ISupplicantP2pIface::WpsProvisionMethod provision_method)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::addGroupInternal(
+    bool persistent, uint32_t persistent_network_id)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::removeGroupInternal(const hidl_string& group_ifname)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::rejectInternal(
+    const hidl_array<uint8_t, 6>& peer_address)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::inviteInternal(
+    const hidl_string& group_ifname,
+    const hidl_array<uint8_t, 6>& go_device_address,
+    const hidl_array<uint8_t, 6>& peer_address)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::reinvokeInternal(
+    uint32_t persistent_network_id, const hidl_array<uint8_t, 6>& peer_address)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::configureExtListenInternal(
+    bool enable, uint32_t period_in_millis, uint32_t interval_in_millis)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::setListenChannelInternal(
+    uint32_t channel, uint32_t operating_class)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+std::pair<SupplicantStatus, std::vector<uint8_t>> P2pIface::getSsidInternal(
+    const hidl_array<uint8_t, 6>& peer_address)
+{
+	// TODO: Add implementation.
+	return {{SupplicantStatusCode::SUCCESS, ""}, {}};
+}
+
+std::pair<SupplicantStatus, uint32_t> P2pIface::getGroupCapabilityInternal(
+    const hidl_array<uint8_t, 6>& peer_address)
+{
+	// TODO: Add implementation.
+	return {{SupplicantStatusCode::SUCCESS, ""}, 0};
+}
+
+SupplicantStatus P2pIface::addBonjourServiceInternal(
+    const hidl_vec<uint8_t>& query, const hidl_vec<uint8_t>& response)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::removeBonjourServiceInternal(
+    const hidl_vec<uint8_t>& query)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::addUpnpServiceInternal(
+    uint32_t version, const hidl_string& service_name)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::removeUpnpServiceInternal(
+    uint32_t version, const hidl_string& service_name)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus P2pIface::flushServicesInternal(
+    uint32_t version, const hidl_string& service_name)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+std::pair<SupplicantStatus, uint64_t> P2pIface::requestServiceDiscoveryInternal(
+    const hidl_array<uint8_t, 6>& peer_address, const hidl_vec<uint8_t>& query)
+{
+	// TODO: Add implementation.
+	return {{SupplicantStatusCode::SUCCESS, ""}, 0};
+}
+
+SupplicantStatus P2pIface::cancelServiceDiscoveryInternal(uint64_t identifier)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
 /**
@@ -156,10 +576,10 @@
  * If the underlying iface is removed, then all RPC method calls on this object
  * will return failure.
  */
-wpa_supplicant *P2pIface::retrieveP2pIfacePtr()
+wpa_supplicant* P2pIface::retrieveIfacePtr()
 {
 	return wpa_supplicant_get_iface(
-	    (struct wpa_global *)wpa_global_, ifname_.c_str());
+	    (struct wpa_global*)wpa_global_, ifname_.c_str());
 }
 
 }  // namespace implementation
diff --git a/wpa_supplicant/hidl/p2p_iface.h b/wpa_supplicant/hidl/p2p_iface.h
index a003cf5..f4992c3 100644
--- a/wpa_supplicant/hidl/p2p_iface.h
+++ b/wpa_supplicant/hidl/p2p_iface.h
@@ -10,6 +10,9 @@
 #ifndef WPA_SUPPLICANT_HIDL_P2P_IFACE_H
 #define WPA_SUPPLICANT_HIDL_P2P_IFACE_H
 
+#include <array>
+#include <vector>
+
 #include <android-base/macros.h>
 
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIface.h>
@@ -42,27 +45,167 @@
 public:
 	P2pIface(struct wpa_global* wpa_global, const char ifname[]);
 	~P2pIface() override = default;
+	// Refer to |StaIface::invalidate()|.
+	void invalidate();
+	bool isValid();
 
 	// Hidl methods exposed.
 	Return<void> getName(getName_cb _hidl_cb) override;
 	Return<void> getType(getType_cb _hidl_cb) override;
 	Return<void> addNetwork(addNetwork_cb _hidl_cb) override;
 	Return<void> removeNetwork(
-	    uint32_t id, removeNetwork_cb _hidl_cb) override;
-	Return<void> getNetwork(uint32_t id, getNetwork_cb _hidl_cb) override;
+	    SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;
+	Return<void> getNetwork(
+	    SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
 	Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
 	Return<void> registerCallback(
 	    const sp<ISupplicantP2pIfaceCallback>& callback,
 	    registerCallback_cb _hidl_cb) override;
+	Return<void> getDeviceAddress(getDeviceAddress_cb _hidl_cb) override;
+	Return<void> setSsidPostfix(
+	    const hidl_string& postfix, setSsidPostfix_cb _hidl_cb) override;
+	Return<void> setGroupIdle(
+	    uint32_t timeout_in_sec, setGroupIdle_cb _hidl_cb) override;
+	Return<void> setPowerSave(
+	    bool enable, setPowerSave_cb _hidl_cb) override;
+	Return<void> find(uint32_t timeout_in_sec, find_cb _hidl_cb) override;
+	Return<void> stopFind(stopFind_cb _hidl_cb) override;
+	Return<void> flush(flush_cb _hidl_cb) override;
+	Return<void> connect(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    ISupplicantP2pIface::WpsProvisionMethod provision_method,
+	    const hidl_vec<uint8_t>& pre_selected_pin, bool join_existing_group,
+	    bool persistent, uint32_t go_intent, connect_cb _hidl_cb) override;
+	Return<void> cancelConnect(cancelConnect_cb _hidl_cb) override;
+	Return<void> provisionDiscovery(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    ISupplicantP2pIface::WpsProvisionMethod provision_method,
+	    provisionDiscovery_cb _hidl_cb) override;
+	Return<void> addGroup(
+	    bool persistent, uint32_t persistent_network_id,
+	    addGroup_cb _hidl_cb) override;
+	Return<void> removeGroup(
+	    const hidl_string& group_ifname, removeGroup_cb _hidl_cb) override;
+	Return<void> reject(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    reject_cb _hidl_cb) override;
+	Return<void> invite(
+	    const hidl_string& group_ifname,
+	    const hidl_array<uint8_t, 6>& go_device_address,
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    invite_cb _hidl_cb) override;
+	Return<void> reinvoke(
+	    uint32_t persistent_network_id,
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    reinvoke_cb _hidl_cb) override;
+	Return<void> configureExtListen(
+	    bool enable, uint32_t period_in_millis, uint32_t interval_in_millis,
+	    configureExtListen_cb _hidl_cb) override;
+	Return<void> setListenChannel(
+	    uint32_t channel, uint32_t operating_class,
+	    setListenChannel_cb _hidl_cb) override;
+	Return<void> getSsid(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    getSsid_cb _hidl_cb) override;
+	Return<void> getGroupCapability(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    getGroupCapability_cb _hidl_cb) override;
+	Return<void> addBonjourService(
+	    const hidl_vec<uint8_t>& query, const hidl_vec<uint8_t>& response,
+	    addBonjourService_cb _hidl_cb) override;
+	Return<void> removeBonjourService(
+	    const hidl_vec<uint8_t>& query,
+	    removeBonjourService_cb _hidl_cb) override;
+	Return<void> addUpnpService(
+	    uint32_t version, const hidl_string& service_name,
+	    addUpnpService_cb _hidl_cb) override;
+	Return<void> removeUpnpService(
+	    uint32_t version, const hidl_string& service_name,
+	    removeUpnpService_cb _hidl_cb) override;
+	Return<void> flushServices(
+	    uint32_t version, const hidl_string& service_name,
+	    flushServices_cb _hidl_cb) override;
+	Return<void> requestServiceDiscovery(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    const hidl_vec<uint8_t>& query,
+	    requestServiceDiscovery_cb _hidl_cb) override;
+	Return<void> cancelServiceDiscovery(
+	    uint64_t identifier, cancelServiceDiscovery_cb _hidl_cb) override;
 
 private:
-	struct wpa_supplicant* retrieveP2pIfacePtr();
+	// Corresponding worker functions for the HIDL methods.
+	std::pair<SupplicantStatus, std::string> getNameInternal();
+	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
+	std::pair<SupplicantStatus, sp<ISupplicantP2pNetwork>>
+	addNetworkInternal();
+	SupplicantStatus removeNetworkInternal(SupplicantNetworkId id);
+	std::pair<SupplicantStatus, sp<ISupplicantP2pNetwork>>
+	getNetworkInternal(SupplicantNetworkId id);
+	std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
+	listNetworksInternal();
+	SupplicantStatus registerCallbackInternal(
+	    const sp<ISupplicantP2pIfaceCallback>& callback);
+	std::pair<SupplicantStatus, std::array<uint8_t, 6>>
+	getDeviceAddressInternal();
+	SupplicantStatus setSsidPostfixInternal(const hidl_string& postfix);
+	SupplicantStatus setGroupIdleInternal(uint32_t timeout_in_sec);
+	SupplicantStatus setPowerSaveInternal(bool enable);
+	SupplicantStatus findInternal(uint32_t timeout_in_sec);
+	SupplicantStatus stopFindInternal();
+	SupplicantStatus flushInternal();
+	std::pair<SupplicantStatus, std::vector<uint8_t>> connectInternal(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    ISupplicantP2pIface::WpsProvisionMethod provision_method,
+	    const hidl_vec<uint8_t>& pre_selected_pin, bool join_existing_group,
+	    bool persistent, uint32_t go_intent);
+	SupplicantStatus cancelConnectInternal();
+	SupplicantStatus provisionDiscoveryInternal(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    ISupplicantP2pIface::WpsProvisionMethod provision_method);
+	SupplicantStatus addGroupInternal(
+	    bool persistent, uint32_t persistent_network_id);
+	SupplicantStatus removeGroupInternal(const hidl_string& group_ifname);
+	SupplicantStatus rejectInternal(
+	    const hidl_array<uint8_t, 6>& peer_address);
+	SupplicantStatus inviteInternal(
+	    const hidl_string& group_ifname,
+	    const hidl_array<uint8_t, 6>& go_device_address,
+	    const hidl_array<uint8_t, 6>& peer_address);
+	SupplicantStatus reinvokeInternal(
+	    uint32_t persistent_network_id,
+	    const hidl_array<uint8_t, 6>& peer_address);
+	SupplicantStatus configureExtListenInternal(
+	    bool enable, uint32_t period_in_millis,
+	    uint32_t interval_in_millis);
+	SupplicantStatus setListenChannelInternal(
+	    uint32_t channel, uint32_t operating_class);
+	std::pair<SupplicantStatus, std::vector<uint8_t>> getSsidInternal(
+	    const hidl_array<uint8_t, 6>& peer_address);
+	std::pair<SupplicantStatus, uint32_t> getGroupCapabilityInternal(
+	    const hidl_array<uint8_t, 6>& peer_address);
+	SupplicantStatus addBonjourServiceInternal(
+	    const hidl_vec<uint8_t>& query, const hidl_vec<uint8_t>& response);
+	SupplicantStatus removeBonjourServiceInternal(
+	    const hidl_vec<uint8_t>& query);
+	SupplicantStatus addUpnpServiceInternal(
+	    uint32_t version, const hidl_string& service_name);
+	SupplicantStatus removeUpnpServiceInternal(
+	    uint32_t version, const hidl_string& service_name);
+	SupplicantStatus flushServicesInternal(
+	    uint32_t version, const hidl_string& service_name);
+	std::pair<SupplicantStatus, uint64_t> requestServiceDiscoveryInternal(
+	    const hidl_array<uint8_t, 6>& peer_address,
+	    const hidl_vec<uint8_t>& query);
+	SupplicantStatus cancelServiceDiscoveryInternal(uint64_t identifier);
+
+	struct wpa_supplicant* retrieveIfacePtr();
 
 	// Reference to the global wpa_struct. This is assumed to be valid for
 	// the lifetime of the process.
 	const struct wpa_global* wpa_global_;
 	// Name of the iface this hidl object controls
 	const std::string ifname_;
+	bool is_valid_;
 
 	DISALLOW_COPY_AND_ASSIGN(P2pIface);
 };
diff --git a/wpa_supplicant/hidl/p2p_network.cpp b/wpa_supplicant/hidl/p2p_network.cpp
index 7de950e..ce02179 100644
--- a/wpa_supplicant/hidl/p2p_network.cpp
+++ b/wpa_supplicant/hidl/p2p_network.cpp
@@ -8,7 +8,7 @@
  */
 
 #include "hidl_manager.h"
-#include "hidl_return_macros.h"
+#include "hidl_return_util.h"
 #include "p2p_network.h"
 
 namespace android {
@@ -17,65 +17,78 @@
 namespace supplicant {
 namespace V1_0 {
 namespace implementation {
+using hidl_return_util::validateAndCall;
 
 P2pNetwork::P2pNetwork(
     struct wpa_global *wpa_global, const char ifname[], int network_id)
-    : wpa_global_(wpa_global), ifname_(ifname), network_id_(network_id)
+    : wpa_global_(wpa_global),
+      ifname_(ifname),
+      network_id_(network_id),
+      is_valid_(true)
 {
 }
 
+void P2pNetwork::invalidate() { is_valid_ = false; }
+bool P2pNetwork::isValid()
+{
+	return (is_valid_ && (retrieveNetworkPtr() != nullptr));
+}
+
 Return<void> P2pNetwork::getId(getId_cb _hidl_cb)
 {
-	uint32_t id = UINT32_MAX;
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID, id);
-	}
-
-	id = network_id_;
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, id);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &P2pNetwork::getIdInternal, _hidl_cb);
 }
 
 Return<void> P2pNetwork::getInterfaceName(getInterfaceName_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, ifname_);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, ifname_);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &P2pNetwork::getInterfaceNameInternal, _hidl_cb);
 }
 
 Return<void> P2pNetwork::getType(getType_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID,
-		    IfaceType::P2P);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, IfaceType::P2P);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &P2pNetwork::getTypeInternal, _hidl_cb);
 }
 
 Return<void> P2pNetwork::registerCallback(
     const sp<ISupplicantP2pNetworkCallback> &callback,
     registerCallback_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &P2pNetwork::registerCallbackInternal, _hidl_cb, callback);
+}
 
+std::pair<SupplicantStatus, uint32_t> P2pNetwork::getIdInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, network_id_};
+}
+
+std::pair<SupplicantStatus, std::string> P2pNetwork::getInterfaceNameInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
+}
+
+std::pair<SupplicantStatus, IfaceType> P2pNetwork::getTypeInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::P2P};
+}
+
+SupplicantStatus P2pNetwork::registerCallbackInternal(
+    const sp<ISupplicantP2pNetworkCallback> &callback)
+{
 	HidlManager *hidl_manager = HidlManager::getInstance();
 	if (!hidl_manager ||
 	    hidl_manager->addP2pNetworkCallbackHidlObject(
 		ifname_, network_id_, callback)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
 /**
diff --git a/wpa_supplicant/hidl/p2p_network.h b/wpa_supplicant/hidl/p2p_network.h
index 92eddd2..023e902 100644
--- a/wpa_supplicant/hidl/p2p_network.h
+++ b/wpa_supplicant/hidl/p2p_network.h
@@ -44,6 +44,9 @@
 	P2pNetwork(
 	    struct wpa_global* wpa_global, const char ifname[], int network_id);
 	~P2pNetwork() override = default;
+	// Refer to |StaIface::invalidate()|.
+	void invalidate();
+	bool isValid();
 
 	// Hidl methods exposed.
 	Return<void> getId(getId_cb _hidl_cb) override;
@@ -54,6 +57,13 @@
 	    registerCallback_cb _hidl_cb) override;
 
 private:
+	// Corresponding worker functions for the HIDL methods.
+	std::pair<SupplicantStatus, uint32_t> getIdInternal();
+	std::pair<SupplicantStatus, std::string> getInterfaceNameInternal();
+	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
+	SupplicantStatus registerCallbackInternal(
+	    const sp<ISupplicantP2pNetworkCallback>& callback);
+
 	struct wpa_ssid* retrieveNetworkPtr();
 	struct wpa_supplicant* retrieveIfacePtr();
 
@@ -64,6 +74,7 @@
 	const std::string ifname_;
 	// Id of the network this hidl object controls.
 	const int network_id_;
+	bool is_valid_;
 
 	DISALLOW_COPY_AND_ASSIGN(P2pNetwork);
 };
diff --git a/wpa_supplicant/hidl/sta_iface.cpp b/wpa_supplicant/hidl/sta_iface.cpp
index e3a384b..4379dd5 100644
--- a/wpa_supplicant/hidl/sta_iface.cpp
+++ b/wpa_supplicant/hidl/sta_iface.cpp
@@ -8,7 +8,7 @@
  */
 
 #include "hidl_manager.h"
-#include "hidl_return_macros.h"
+#include "hidl_return_util.h"
 #include "sta_iface.h"
 
 namespace android {
@@ -17,216 +17,278 @@
 namespace supplicant {
 namespace V1_0 {
 namespace implementation {
+using hidl_return_util::validateAndCall;
 
 StaIface::StaIface(struct wpa_global *wpa_global, const char ifname[])
-    : wpa_global_(wpa_global), ifname_(ifname)
+    : wpa_global_(wpa_global), ifname_(ifname), is_valid_(true)
 {
 }
 
+void StaIface::invalidate() { is_valid_ = false; }
+bool StaIface::isValid()
+{
+	return (is_valid_ && (retrieveIfacePtr() != nullptr));
+}
+
 Return<void> StaIface::getName(getName_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, ifname_);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, ifname_);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::getNameInternal, _hidl_cb);
 }
 
 Return<void> StaIface::getType(getType_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID,
-		    IfaceType::STA);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, IfaceType::STA);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::getTypeInternal, _hidl_cb);
 }
 
 Return<void> StaIface::addNetwork(addNetwork_cb _hidl_cb)
 {
-	android::sp<ISupplicantStaNetwork> network;
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, network);
-	}
-
-	struct wpa_ssid *ssid = wpa_supplicant_add_network(wpa_s);
-	if (!ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, network);
-	}
-
-	HidlManager *hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(
-		wpa_s->ifname, ssid->id, &network)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, network);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, network);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::addNetworkInternal, _hidl_cb);
 }
 
-Return<void> StaIface::removeNetwork(uint32_t id, removeNetwork_cb _hidl_cb)
+Return<void> StaIface::removeNetwork(
+    SupplicantNetworkId id, removeNetwork_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	int result = wpa_supplicant_remove_network(wpa_s, id);
-	if (result == -1) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN);
-	}
-
-	if (result != 0) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::removeNetworkInternal, _hidl_cb, id);
 }
 
-Return<void> StaIface::getNetwork(uint32_t id, getNetwork_cb _hidl_cb)
+Return<void> StaIface::getNetwork(
+    SupplicantNetworkId id, getNetwork_cb _hidl_cb)
 {
-	android::sp<ISupplicantStaNetwork> network;
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, network);
-	}
-
-	struct wpa_ssid *ssid = wpa_config_get_network(wpa_s->conf, id);
-	if (!ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, network);
-	}
-
-	HidlManager *hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(
-		wpa_s->ifname, ssid->id, &network)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN, network);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, network);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::getNetworkInternal, _hidl_cb, id);
 }
 
 Return<void> StaIface::listNetworks(listNetworks_cb _hidl_cb)
 {
-	std::vector<uint32_t> network_ids;
-
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID, network_ids);
-	}
-
-	for (struct wpa_ssid *wpa_ssid = wpa_s->conf->ssid; wpa_ssid;
-	     wpa_ssid = wpa_ssid->next) {
-		network_ids.emplace_back(wpa_ssid->id);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, network_ids);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::listNetworksInternal, _hidl_cb);
 }
 
 Return<void> StaIface::registerCallback(
     const sp<ISupplicantStaIfaceCallback> &callback,
     registerCallback_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	HidlManager *hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->addStaIfaceCallbackHidlObject(ifname_, callback)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::registerCallbackInternal, _hidl_cb, callback);
 }
 
 Return<void> StaIface::reassociate(reassociate_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::reassociateInternal, _hidl_cb);
 }
 
 Return<void> StaIface::reconnect(reconnect_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
-	}
-	if (!wpa_s->disconnected) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_NOT_DISCONNECTED);
-	}
-
-	wpas_request_connection(wpa_s);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::reconnectInternal, _hidl_cb);
 }
 
 Return<void> StaIface::disconnect(disconnect_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_DISABLED);
-	}
-
-	wpas_request_disconnection(wpa_s);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::disconnectInternal, _hidl_cb);
 }
 
 Return<void> StaIface::setPowerSave(bool enable, setPowerSave_cb _hidl_cb)
 {
-	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	if (wpa_drv_set_p2p_powersave(wpa_s, enable, -1, -1)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::setPowerSaveInternal, _hidl_cb, enable);
 }
 
 Return<void> StaIface::initiateTdlsDiscover(
-    const hidl_array<uint8_t, 6 /* 6 */> &mac_address,
-    initiateTdlsDiscover_cb _hidl_cb)
+    const hidl_array<uint8_t, 6> &mac_address, initiateTdlsDiscover_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::initiateTdlsDiscoverInternal, _hidl_cb, mac_address);
+}
+
+Return<void> StaIface::initiateTdlsSetup(
+    const hidl_array<uint8_t, 6> &mac_address, initiateTdlsSetup_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::initiateTdlsSetupInternal, _hidl_cb, mac_address);
+}
+
+Return<void> StaIface::initiateTdlsTeardown(
+    const hidl_array<uint8_t, 6> &mac_address, initiateTdlsTeardown_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::initiateTdlsTeardownInternal, _hidl_cb, mac_address);
+}
+Return<void> StaIface::initiateAnqpQuery(
+    const hidl_array<uint8_t, 6> &mac_address,
+    const hidl_vec<ISupplicantStaIface::AnqpInfoId> &info_elements,
+    const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes> &sub_types,
+    initiateAnqpQuery_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::initiateAnqpQueryInternal, _hidl_cb, mac_address,
+	    info_elements, sub_types);
+}
+
+Return<void> StaIface::initiateHs20IconQuery(
+    const hidl_array<uint8_t, 6> &mac_address, const hidl_string &file_name,
+    initiateHs20IconQuery_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &StaIface::initiateHs20IconQueryInternal, _hidl_cb, mac_address,
+	    file_name);
+}
+
+std::pair<SupplicantStatus, std::string> StaIface::getNameInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
+}
+
+std::pair<SupplicantStatus, IfaceType> StaIface::getTypeInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA};
+}
+
+std::pair<SupplicantStatus, sp<ISupplicantNetwork>>
+StaIface::addNetworkInternal()
+{
+	android::sp<ISupplicantStaNetwork> network;
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	struct wpa_ssid *ssid = wpa_supplicant_add_network(wpa_s);
+	if (!ssid) {
+		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
+	}
+	HidlManager *hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(
+		wpa_s->ifname, ssid->id, &network)) {
+		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, network};
+}
+
+SupplicantStatus StaIface::removeNetworkInternal(SupplicantNetworkId id)
 {
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
+	int result = wpa_supplicant_remove_network(wpa_s, id);
+	if (result == -1) {
+		return {SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, ""};
 	}
-
-	if (!mac_address.data()) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+	if (result != 0) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
 
+std::pair<SupplicantStatus, sp<ISupplicantNetwork>>
+StaIface::getNetworkInternal(SupplicantNetworkId id)
+{
+	android::sp<ISupplicantStaNetwork> network;
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	struct wpa_ssid *ssid = wpa_config_get_network(wpa_s->conf, id);
+	if (!ssid) {
+		return {{SupplicantStatusCode::FAILURE_NETWORK_UNKNOWN, ""},
+			network};
+	}
+	HidlManager *hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->getStaNetworkHidlObjectByIfnameAndNetworkId(
+		wpa_s->ifname, ssid->id, &network)) {
+		return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""}, network};
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, network};
+}
+
+std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
+StaIface::listNetworksInternal()
+{
+	std::vector<SupplicantNetworkId> network_ids;
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	for (struct wpa_ssid *wpa_ssid = wpa_s->conf->ssid; wpa_ssid;
+	     wpa_ssid = wpa_ssid->next) {
+		network_ids.emplace_back(wpa_ssid->id);
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(network_ids)};
+}
+
+SupplicantStatus StaIface::registerCallbackInternal(
+    const sp<ISupplicantStaIfaceCallback> &callback)
+{
+	HidlManager *hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->addStaIfaceCallbackHidlObject(ifname_, callback)) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaIface::reassociateInternal()
+{
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
+		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
+	}
+	wpas_request_connection(wpa_s);
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaIface::reconnectInternal()
+{
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
+		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
+	}
+	if (!wpa_s->disconnected) {
+		return {SupplicantStatusCode::FAILURE_IFACE_NOT_DISCONNECTED,
+			""};
+	}
+	wpas_request_connection(wpa_s);
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaIface::disconnectInternal()
+{
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
+		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
+	}
+	wpas_request_disconnection(wpa_s);
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaIface::setPowerSaveInternal(bool enable)
+{
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
+	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
+		return {SupplicantStatusCode::FAILURE_IFACE_DISABLED, ""};
+	}
+	if (wpa_drv_set_p2p_powersave(wpa_s, enable, -1, -1)) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaIface::initiateTdlsDiscoverInternal(
+    const std::array<uint8_t, 6> &mac_address)
+{
+	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	int ret;
 	const u8 *peer = mac_address.data();
 	if (wpa_tdls_is_external_setup(wpa_s->wpa)) {
@@ -235,25 +297,15 @@
 		ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
 	}
 	if (ret) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaIface::initiateTdlsSetup(
-    const hidl_array<uint8_t, 6 /* 6 */> &mac_address,
-    initiateTdlsSetup_cb _hidl_cb)
+SupplicantStatus StaIface::initiateTdlsSetupInternal(
+    const std::array<uint8_t, 6> &mac_address)
 {
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	if (!mac_address.data()) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
-	}
-
 	int ret;
 	const u8 *peer = mac_address.data();
 	if (wpa_tdls_is_external_setup(wpa_s->wpa) &&
@@ -264,25 +316,15 @@
 		ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
 	}
 	if (ret) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaIface::initiateTdlsTeardown(
-    const hidl_array<uint8_t, 6 /* 6 */> &mac_address,
-    initiateTdlsTeardown_cb _hidl_cb)
+SupplicantStatus StaIface::initiateTdlsTeardownInternal(
+    const std::array<uint8_t, 6> &mac_address)
 {
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
-	if (!wpa_s) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_IFACE_INVALID);
-	}
-
-	if (!mac_address.data()) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
-	}
-
 	int ret;
 	const u8 *peer = mac_address.data();
 	if (wpa_tdls_is_external_setup(wpa_s->wpa) &&
@@ -292,12 +334,26 @@
 	} else {
 		ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
 	}
-
 	if (ret) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
 
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+SupplicantStatus StaIface::initiateAnqpQueryInternal(
+    const std::array<uint8_t, 6> &mac_address,
+    const std::vector<ISupplicantStaIface::AnqpInfoId> &info_elements,
+    const std::vector<ISupplicantStaIface::Hs20AnqpSubtypes> &sub_types)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaIface::initiateHs20IconQueryInternal(
+    const std::array<uint8_t, 6> &mac_address, const std::string &file_name)
+{
+	// TODO: Add implementation.
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
 /**
diff --git a/wpa_supplicant/hidl/sta_iface.h b/wpa_supplicant/hidl/sta_iface.h
index f246bbc..a4177aa 100644
--- a/wpa_supplicant/hidl/sta_iface.h
+++ b/wpa_supplicant/hidl/sta_iface.h
@@ -10,6 +10,9 @@
 #ifndef WPA_SUPPLICANT_HIDL_STA_IFACE_H
 #define WPA_SUPPLICANT_HIDL_STA_IFACE_H
 
+#include <array>
+#include <vector>
+
 #include <android-base/macros.h>
 
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIface.h>
@@ -43,14 +46,29 @@
 public:
 	StaIface(struct wpa_global* wpa_global, const char ifname[]);
 	~StaIface() override = default;
+	// HIDL does not provide a built-in mechanism to let the server
+	// invalidate a HIDL interface object after creation. If any client
+	// process holds onto a reference to the object in their context,
+	// any method calls on that reference will continue to be directed to
+	// the server.
+	// However Supplicant HAL needs to control the lifetime of these
+	// objects. So, add a public |invalidate| method to all |Iface| and
+	// |Network| objects.
+	// This will be used to mark an object invalid when the corresponding
+	// iface or network is removed.
+	// All HIDL method implementations should check if the object is still
+	// marked valid before processing them.
+	void invalidate();
+	bool isValid();
 
 	// Hidl methods exposed.
 	Return<void> getName(getName_cb _hidl_cb) override;
 	Return<void> getType(getType_cb _hidl_cb) override;
 	Return<void> addNetwork(addNetwork_cb _hidl_cb) override;
 	Return<void> removeNetwork(
-	    uint32_t id, removeNetwork_cb _hidl_cb) override;
-	Return<void> getNetwork(uint32_t id, getNetwork_cb _hidl_cb) override;
+	    SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;
+	Return<void> getNetwork(
+	    SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
 	Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
 	Return<void> registerCallback(
 	    const sp<ISupplicantStaIfaceCallback>& callback,
@@ -61,16 +79,56 @@
 	Return<void> setPowerSave(
 	    bool enable, setPowerSave_cb _hidl_cb) override;
 	Return<void> initiateTdlsDiscover(
-	    const hidl_array<uint8_t, 6 /* 6 */>& mac_address,
+	    const hidl_array<uint8_t, 6>& mac_address,
 	    initiateTdlsDiscover_cb _hidl_cb) override;
 	Return<void> initiateTdlsSetup(
-	    const hidl_array<uint8_t, 6 /* 6 */>& mac_address,
+	    const hidl_array<uint8_t, 6>& mac_address,
 	    initiateTdlsSetup_cb _hidl_cb) override;
 	Return<void> initiateTdlsTeardown(
-	    const hidl_array<uint8_t, 6 /* 6 */>& mac_address,
+	    const hidl_array<uint8_t, 6>& mac_address,
 	    initiateTdlsTeardown_cb _hidl_cb) override;
+	Return<void> initiateAnqpQuery(
+	    const hidl_array<uint8_t, 6>& mac_address,
+	    const hidl_vec<ISupplicantStaIface::AnqpInfoId>& info_elements,
+	    const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes>& sub_types,
+	    initiateAnqpQuery_cb _hidl_cb) override;
+	Return<void> initiateHs20IconQuery(
+	    const hidl_array<uint8_t, 6>& mac_address,
+	    const hidl_string& file_name,
+	    initiateHs20IconQuery_cb _hidl_cb) override;
 
 private:
+	// Corresponding worker functions for the HIDL methods.
+	std::pair<SupplicantStatus, std::string> getNameInternal();
+	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
+	std::pair<SupplicantStatus, sp<ISupplicantNetwork>>
+	addNetworkInternal();
+	SupplicantStatus removeNetworkInternal(SupplicantNetworkId id);
+	std::pair<SupplicantStatus, sp<ISupplicantNetwork>> getNetworkInternal(
+	    SupplicantNetworkId id);
+	std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
+	listNetworksInternal();
+	SupplicantStatus registerCallbackInternal(
+	    const sp<ISupplicantStaIfaceCallback>& callback);
+	SupplicantStatus reassociateInternal();
+	SupplicantStatus reconnectInternal();
+	SupplicantStatus disconnectInternal();
+	SupplicantStatus setPowerSaveInternal(bool enable);
+	SupplicantStatus initiateTdlsDiscoverInternal(
+	    const std::array<uint8_t, 6>& mac_address);
+	SupplicantStatus initiateTdlsSetupInternal(
+	    const std::array<uint8_t, 6>& mac_address);
+	SupplicantStatus initiateTdlsTeardownInternal(
+	    const std::array<uint8_t, 6>& mac_address);
+	SupplicantStatus initiateAnqpQueryInternal(
+	    const std::array<uint8_t, 6>& mac_address,
+	    const std::vector<ISupplicantStaIface::AnqpInfoId>& info_elements,
+	    const std::vector<ISupplicantStaIface::Hs20AnqpSubtypes>&
+		sub_types);
+	SupplicantStatus initiateHs20IconQueryInternal(
+	    const std::array<uint8_t, 6>& mac_address,
+	    const std::string& file_name);
+
 	struct wpa_supplicant* retrieveIfacePtr();
 
 	// Reference to the global wpa_struct. This is assumed to be valid for
@@ -78,6 +136,7 @@
 	const struct wpa_global* wpa_global_;
 	// Name of the iface this hidl object controls
 	const std::string ifname_;
+	bool is_valid_;
 
 	DISALLOW_COPY_AND_ASSIGN(StaIface);
 };
diff --git a/wpa_supplicant/hidl/sta_network.cpp b/wpa_supplicant/hidl/sta_network.cpp
index c782101..15e628f 100644
--- a/wpa_supplicant/hidl/sta_network.cpp
+++ b/wpa_supplicant/hidl/sta_network.cpp
@@ -8,7 +8,7 @@
  */
 
 #include "hidl_manager.h"
-#include "hidl_return_macros.h"
+#include "hidl_return_util.h"
 #include "sta_network.h"
 
 namespace {
@@ -56,106 +56,446 @@
 namespace supplicant {
 namespace V1_0 {
 namespace implementation {
+using hidl_return_util::validateAndCall;
 
 StaNetwork::StaNetwork(
     struct wpa_global *wpa_global, const char ifname[], int network_id)
-    : wpa_global_(wpa_global), ifname_(ifname), network_id_(network_id)
+    : wpa_global_(wpa_global),
+      ifname_(ifname),
+      network_id_(network_id),
+      is_valid_(true)
 {
 }
 
+void StaNetwork::invalidate() { is_valid_ = false; }
+bool StaNetwork::isValid()
+{
+	return (is_valid_ && (retrieveNetworkPtr() != nullptr));
+}
+
 Return<void> StaNetwork::getId(getId_cb _hidl_cb)
 {
-	uint32_t id = UINT32_MAX;
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID, id);
-	}
-
-	id = network_id_;
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, id);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getIdInternal, _hidl_cb);
 }
 
 Return<void> StaNetwork::getInterfaceName(getInterfaceName_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, ifname_);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, ifname_);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getInterfaceNameInternal, _hidl_cb);
 }
 
 Return<void> StaNetwork::getType(getType_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_INVALID,
-		    IfaceType::STA);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, IfaceType::STA);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getTypeInternal, _hidl_cb);
 }
 
 Return<void> StaNetwork::registerCallback(
     const sp<ISupplicantStaNetworkCallback> &callback,
     registerCallback_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
-	HidlManager *hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->addStaNetworkCallbackHidlObject(
-		ifname_, network_id_, callback)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::registerCallbackInternal, _hidl_cb, callback);
 }
 
 Return<void> StaNetwork::setSsid(
     const hidl_vec<uint8_t> &ssid, setSsid_cb _hidl_cb)
 {
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setSsidInternal, _hidl_cb, ssid);
+}
 
+Return<void> StaNetwork::setBssid(
+    const hidl_array<uint8_t, 6> &bssid, setBssid_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setBssidInternal, _hidl_cb, bssid);
+}
+
+Return<void> StaNetwork::setScanSsid(bool enable, setScanSsid_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setScanSsidInternal, _hidl_cb, enable);
+}
+
+Return<void> StaNetwork::setKeyMgmt(
+    uint32_t key_mgmt_mask, setKeyMgmt_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setKeyMgmtInternal, _hidl_cb, key_mgmt_mask);
+}
+
+Return<void> StaNetwork::setProto(uint32_t proto_mask, setProto_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setProtoInternal, _hidl_cb, proto_mask);
+}
+
+Return<void> StaNetwork::setAuthAlg(
+    uint32_t auth_alg_mask,
+    std::function<void(const SupplicantStatus &status)> _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setAuthAlgInternal, _hidl_cb, auth_alg_mask);
+}
+
+Return<void> StaNetwork::setGroupCipher(
+    uint32_t group_cipher_mask, setGroupCipher_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setGroupCipherInternal, _hidl_cb, group_cipher_mask);
+}
+
+Return<void> StaNetwork::setPairwiseCipher(
+    uint32_t pairwise_cipher_mask, setPairwiseCipher_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setPairwiseCipherInternal, _hidl_cb,
+	    pairwise_cipher_mask);
+}
+
+Return<void> StaNetwork::setPskPassphrase(
+    const hidl_string &psk, setPskPassphrase_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setPskPassphraseInternal, _hidl_cb, psk);
+}
+
+Return<void> StaNetwork::setWepKey(
+    uint32_t key_idx, const hidl_vec<uint8_t> &wep_key, setWepKey_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setWepKeyInternal, _hidl_cb, key_idx, wep_key);
+}
+
+Return<void> StaNetwork::setWepTxKeyIdx(
+    uint32_t key_idx, setWepTxKeyIdx_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setWepTxKeyIdxInternal, _hidl_cb, key_idx);
+}
+
+Return<void> StaNetwork::setRequirePmf(bool enable, setRequirePmf_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setRequirePmfInternal, _hidl_cb, enable);
+}
+
+Return<void> StaNetwork::setEapMethod(
+    ISupplicantStaNetwork::EapMethod method, setEapMethod_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapMethodInternal, _hidl_cb, method);
+}
+
+Return<void> StaNetwork::setEapPhase2Method(
+    ISupplicantStaNetwork::EapPhase2Method method,
+    setEapPhase2Method_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapPhase2MethodInternal, _hidl_cb, method);
+}
+
+Return<void> StaNetwork::setEapIdentity(
+    const hidl_vec<uint8_t> &identity, setEapIdentity_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapIdentityInternal, _hidl_cb, identity);
+}
+
+Return<void> StaNetwork::setEapAnonymousIdentity(
+    const hidl_vec<uint8_t> &identity, setEapAnonymousIdentity_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapAnonymousIdentityInternal, _hidl_cb, identity);
+}
+
+Return<void> StaNetwork::setEapPassword(
+    const hidl_vec<uint8_t> &password, setEapPassword_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapPasswordInternal, _hidl_cb, password);
+}
+
+Return<void> StaNetwork::setEapCACert(
+    const hidl_string &path, setEapCACert_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapCACertInternal, _hidl_cb, path);
+}
+
+Return<void> StaNetwork::setEapCAPath(
+    const hidl_string &path, setEapCAPath_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapCAPathInternal, _hidl_cb, path);
+}
+
+Return<void> StaNetwork::setEapClientCert(
+    const hidl_string &path, setEapClientCert_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapClientCertInternal, _hidl_cb, path);
+}
+
+Return<void> StaNetwork::setEapPrivateKey(
+    const hidl_string &path, setEapPrivateKey_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapPrivateKeyInternal, _hidl_cb, path);
+}
+
+Return<void> StaNetwork::setEapSubjectMatch(
+    const hidl_string &match, setEapSubjectMatch_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapSubjectMatchInternal, _hidl_cb, match);
+}
+
+Return<void> StaNetwork::setEapAltSubjectMatch(
+    const hidl_string &match, setEapAltSubjectMatch_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapAltSubjectMatchInternal, _hidl_cb, match);
+}
+
+Return<void> StaNetwork::setEapEngine(bool enable, setEapEngine_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapEngineInternal, _hidl_cb, enable);
+}
+
+Return<void> StaNetwork::setEapEngineID(
+    const hidl_string &id, setEapEngineID_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapEngineIDInternal, _hidl_cb, id);
+}
+
+Return<void> StaNetwork::setEapDomainSuffixMatch(
+    const hidl_string &match, setEapDomainSuffixMatch_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::setEapDomainSuffixMatchInternal, _hidl_cb, match);
+}
+
+Return<void> StaNetwork::getSsid(getSsid_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getSsidInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getBssid(getBssid_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getBssidInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getScanSsid(getScanSsid_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getScanSsidInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getKeyMgmt(getKeyMgmt_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getKeyMgmtInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getProto(getProto_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getProtoInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getAuthAlg(getAuthAlg_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getAuthAlgInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getGroupCipher(getGroupCipher_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getGroupCipherInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getPairwiseCipher(getPairwiseCipher_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getPairwiseCipherInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getPskPassphrase(getPskPassphrase_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getPskPassphraseInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getWepKey(uint32_t key_idx, getWepKey_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getWepKeyInternal, _hidl_cb, key_idx);
+}
+
+Return<void> StaNetwork::getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getWepTxKeyIdxInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::getRequirePmf(getRequirePmf_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::getRequirePmfInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::enable(bool no_connect, enable_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::enableInternal, _hidl_cb, no_connect);
+}
+
+Return<void> StaNetwork::disable(disable_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::disableInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::select(select_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::selectInternal, _hidl_cb);
+}
+
+Return<void> StaNetwork::sendNetworkEapSimGsmAuthResponse(
+    const ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams &params,
+    sendNetworkEapSimGsmAuthResponse_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::sendNetworkEapSimGsmAuthResponseInternal, _hidl_cb,
+	    params);
+}
+
+Return<void> StaNetwork::sendNetworkEapSimUmtsAuthResponse(
+    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams &params,
+    sendNetworkEapSimUmtsAuthResponse_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::sendNetworkEapSimUmtsAuthResponseInternal, _hidl_cb,
+	    params);
+}
+
+Return<void> StaNetwork::sendNetworkEapIdentityResponse(
+    const hidl_vec<uint8_t> &identity,
+    sendNetworkEapIdentityResponse_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_NETWORK_INVALID,
+	    &StaNetwork::sendNetworkEapIdentityResponseInternal, _hidl_cb,
+	    identity);
+}
+
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getIdInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, network_id_};
+}
+
+std::pair<SupplicantStatus, std::string> StaNetwork::getInterfaceNameInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, ifname_};
+}
+
+std::pair<SupplicantStatus, IfaceType> StaNetwork::getTypeInternal()
+{
+	return {{SupplicantStatusCode::SUCCESS, ""}, IfaceType::STA};
+}
+
+SupplicantStatus StaNetwork::registerCallbackInternal(
+    const sp<ISupplicantStaNetworkCallback> &callback)
+{
+	HidlManager *hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->addStaNetworkCallbackHidlObject(
+		ifname_, network_id_, callback)) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus StaNetwork::setSsidInternal(const std::vector<uint8_t> &ssid)
+{
+	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
 	if (ssid.size() == 0 ||
 	    ssid.size() >
 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
 					  SSID_MAX_LEN_IN_BYTES)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
-
 	if (setByteArrayFieldAndResetState(
 		ssid.data(), ssid.size(), &(wpa_ssid->ssid),
 		&(wpa_ssid->ssid_len), "ssid")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	if (wpa_ssid->passphrase) {
 		wpa_config_update_psk(wpa_ssid);
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setBssid(
-    const hidl_array<uint8_t, 6 /* 6 */> &bssid, setBssid_cb _hidl_cb)
+SupplicantStatus StaNetwork::setBssidInternal(
+    const std::array<uint8_t, 6> &bssid)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
-	if (!bssid.data()) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
-	}
-
 	int prev_bssid_set = wpa_ssid->bssid_set;
 	u8 prev_bssid[ETH_ALEN];
 	os_memcpy(prev_bssid, wpa_ssid->bssid, ETH_ALEN);
@@ -173,156 +513,111 @@
 	     os_memcmp(wpa_ssid->bssid, prev_bssid, ETH_ALEN) != 0)) {
 		wpas_notify_network_bssid_set_changed(wpa_s, wpa_ssid);
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setScanSsid(bool enable, setScanSsid_cb _hidl_cb)
+SupplicantStatus StaNetwork::setScanSsidInternal(bool enable)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	wpa_ssid->scan_ssid = enable ? 1 : 0;
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setKeyMgmt(
-    uint32_t key_mgmt_mask, setKeyMgmt_cb _hidl_cb)
+SupplicantStatus StaNetwork::setKeyMgmtInternal(uint32_t key_mgmt_mask)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (key_mgmt_mask & ~kAllowedKeyMgmtMask) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	wpa_ssid->key_mgmt = key_mgmt_mask;
 	wpa_printf(MSG_MSGDUMP, "key_mgmt: 0x%x", wpa_ssid->key_mgmt);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setProto(uint32_t proto_mask, setProto_cb _hidl_cb)
+SupplicantStatus StaNetwork::setProtoInternal(uint32_t proto_mask)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (proto_mask & ~kAllowedproto_mask) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	wpa_ssid->proto = proto_mask;
 	wpa_printf(MSG_MSGDUMP, "proto: 0x%x", wpa_ssid->proto);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setAuthAlg(
-    uint32_t auth_alg_mask,
-    std::function<void(const SupplicantStatus &status)> _hidl_cb)
+SupplicantStatus StaNetwork::setAuthAlgInternal(uint32_t auth_alg_mask)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (auth_alg_mask & ~kAllowedauth_alg_mask) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	wpa_ssid->auth_alg = auth_alg_mask;
 	wpa_printf(MSG_MSGDUMP, "auth_alg: 0x%x", wpa_ssid->auth_alg);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setGroupCipher(
-    uint32_t group_cipher_mask, setGroupCipher_cb _hidl_cb)
+SupplicantStatus StaNetwork::setGroupCipherInternal(uint32_t group_cipher_mask)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (group_cipher_mask & ~kAllowedgroup_cipher_mask) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	wpa_ssid->group_cipher = group_cipher_mask;
 	wpa_printf(MSG_MSGDUMP, "group_cipher: 0x%x", wpa_ssid->group_cipher);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setPairwiseCipher(
-    uint32_t pairwise_cipher_mask, setPairwiseCipher_cb _hidl_cb)
+SupplicantStatus StaNetwork::setPairwiseCipherInternal(
+    uint32_t pairwise_cipher_mask)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (pairwise_cipher_mask & ~kAllowedpairwise_cipher_mask) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	wpa_ssid->pairwise_cipher = pairwise_cipher_mask;
 	wpa_printf(
 	    MSG_MSGDUMP, "pairwise_cipher: 0x%x", wpa_ssid->pairwise_cipher);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setPskPassphrase(
-    const hidl_string &psk, setPskPassphrase_cb _hidl_cb)
+SupplicantStatus StaNetwork::setPskPassphraseInternal(const std::string &psk)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (isPskPassphraseValid(psk)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	if (wpa_ssid->passphrase &&
 	    os_strlen(wpa_ssid->passphrase) == psk.size() &&
 	    os_memcmp(wpa_ssid->passphrase, psk.c_str(), psk.size()) == 0) {
-		HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+		return {SupplicantStatusCode::SUCCESS, ""};
 	}
 	// Flag to indicate if raw psk is calculated or not using
 	// |wpa_config_update_psk|. Deferred if ssid not already set.
 	wpa_ssid->psk_set = 0;
 	if (setStringKeyFieldAndResetState(
 		psk.c_str(), &(wpa_ssid->passphrase), "psk passphrase")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	if (wpa_ssid->ssid_len) {
 		wpa_config_update_psk(wpa_ssid);
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setWepKey(
-    uint32_t key_idx, const hidl_vec<uint8_t> &wep_key, setWepKey_cb _hidl_cb)
+SupplicantStatus StaNetwork::setWepKeyInternal(
+    uint32_t key_idx, const std::vector<uint8_t> &wep_key)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (key_idx >=
 	    static_cast<uint32_t>(
 		ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	if (wep_key.size() !=
 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
@@ -330,7 +625,7 @@
 	    wep_key.size() !=
 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
 					  WEP104_KEY_LEN_IN_BYTES)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	os_memcpy(wpa_ssid->wep_key[key_idx], wep_key.data(), wep_key.size());
 	wpa_ssid->wep_key_len[key_idx] = wep_key.size();
@@ -339,52 +634,36 @@
 	    MSG_MSGDUMP, msg_dump_title.c_str(), wpa_ssid->wep_key[key_idx],
 	    wpa_ssid->wep_key_len[key_idx]);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setWepTxKeyIdx(
-    uint32_t key_idx, setWepTxKeyIdx_cb _hidl_cb)
+SupplicantStatus StaNetwork::setWepTxKeyIdxInternal(uint32_t key_idx)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (key_idx >=
 	    static_cast<uint32_t>(
 		ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_ARGS_INVALID);
+		return {SupplicantStatusCode::FAILURE_ARGS_INVALID, ""};
 	}
 	wpa_ssid->wep_tx_keyidx = key_idx;
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setRequirePmf(bool enable, setRequirePmf_cb _hidl_cb)
+SupplicantStatus StaNetwork::setRequirePmfInternal(bool enable)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	wpa_ssid->ieee80211w =
 	    enable ? MGMT_FRAME_PROTECTION_REQUIRED : NO_MGMT_FRAME_PROTECTION;
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapMethod(
-    ISupplicantStaNetwork::EapMethod method, setEapMethod_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapMethodInternal(
+    ISupplicantStaNetwork::EapMethod method)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
 	int retrieved_vendor, retrieved_method;
-
 	const char *method_str =
 	    kEapMethodStrings[static_cast<uint32_t>(method)];
 	// This string lookup is needed to check if the device supports the
@@ -392,9 +671,8 @@
 	retrieved_method = eap_peer_get_type(method_str, &retrieved_vendor);
 	if (retrieved_vendor == EAP_VENDOR_IETF &&
 	    retrieved_method == EAP_TYPE_NONE) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
 	if (wpa_ssid->eap.eap_methods) {
 		os_free(wpa_ssid->eap.eap_methods);
 	}
@@ -406,7 +684,7 @@
 	wpa_ssid->eap.eap_methods =
 	    (eap_method_type *)os_malloc(sizeof(eap_method_type) * 2);
 	if (!wpa_ssid->eap.eap_methods) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	wpa_ssid->eap.eap_methods[0].vendor = retrieved_vendor;
 	wpa_ssid->eap.eap_methods[0].method = retrieved_method;
@@ -421,432 +699,263 @@
 	} else {
 		wpa_ssid->non_leap++;
 	}
-
 	wpa_hexdump(
 	    MSG_MSGDUMP, "eap methods", (u8 *)wpa_ssid->eap.eap_methods,
 	    sizeof(eap_method_type) * 2);
 	resetInternalStateAfterParamsUpdate();
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapPhase2Method(
-    ISupplicantStaNetwork::EapPhase2Method method,
-    setEapPhase2Method_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapPhase2MethodInternal(
+    ISupplicantStaNetwork::EapPhase2Method method)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		kEapPhase2MethodStrings[static_cast<uint32_t>(method)],
 		&(wpa_ssid->eap.phase2), "eap phase2")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapIdentity(
-    const hidl_vec<uint8_t> &identity, setEapIdentity_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapIdentityInternal(
+    const std::vector<uint8_t> &identity)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setByteArrayFieldAndResetState(
 		identity.data(), identity.size(), &(wpa_ssid->eap.identity),
 		&(wpa_ssid->eap.identity_len), "eap identity")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapAnonymousIdentity(
-    const hidl_vec<uint8_t> &identity, setEapAnonymousIdentity_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapAnonymousIdentityInternal(
+    const std::vector<uint8_t> &identity)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setByteArrayFieldAndResetState(
 		identity.data(), identity.size(),
 		&(wpa_ssid->eap.anonymous_identity),
 		&(wpa_ssid->eap.anonymous_identity_len),
 		"eap anonymous_identity")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapPassword(
-    const hidl_vec<uint8_t> &password, setEapPassword_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapPasswordInternal(
+    const std::vector<uint8_t> &password)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setByteArrayKeyFieldAndResetState(
 		password.data(), password.size(), &(wpa_ssid->eap.password),
 		&(wpa_ssid->eap.password_len), "eap password")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	wpa_ssid->eap.flags &= ~EAP_CONFIG_FLAGS_PASSWORD_NTHASH;
 	wpa_ssid->eap.flags &= ~EAP_CONFIG_FLAGS_EXT_PASSWORD;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapCACert(
-    const hidl_string &path, setEapCACert_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapCACertInternal(const std::string &path)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		path.c_str(), &(wpa_ssid->eap.ca_cert), "eap ca_cert")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapCAPath(
-    const hidl_string &path, setEapCAPath_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapCAPathInternal(const std::string &path)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		path.c_str(), &(wpa_ssid->eap.ca_path), "eap ca_path")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapClientCert(
-    const hidl_string &path, setEapClientCert_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapClientCertInternal(const std::string &path)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		path.c_str(), &(wpa_ssid->eap.client_cert),
 		"eap client_cert")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapPrivateKey(
-    const hidl_string &path, setEapPrivateKey_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapPrivateKeyInternal(const std::string &path)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		path.c_str(), &(wpa_ssid->eap.private_key),
 		"eap private_key")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapSubjectMatch(
-    const hidl_string &match, setEapSubjectMatch_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapSubjectMatchInternal(
+    const std::string &match)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		match.c_str(), &(wpa_ssid->eap.subject_match),
 		"eap subject_match")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapAltSubjectMatch(
-    const hidl_string &match, setEapAltSubjectMatch_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapAltSubjectMatchInternal(
+    const std::string &match)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		match.c_str(), &(wpa_ssid->eap.altsubject_match),
 		"eap altsubject_match")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapEngine(bool enable, setEapEngine_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapEngineInternal(bool enable)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	wpa_ssid->eap.engine = enable ? 1 : 0;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapEngineID(
-    const hidl_string &id, setEapEngineID_cb _hidl_cb)
-
+SupplicantStatus StaNetwork::setEapEngineIDInternal(const std::string &id)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		id.c_str(), &(wpa_ssid->eap.engine_id), "eap engine_id")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::setEapDomainSuffixMatch(
-    const hidl_string &match, setEapDomainSuffixMatch_cb _hidl_cb)
+SupplicantStatus StaNetwork::setEapDomainSuffixMatchInternal(
+    const std::string &match)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (setStringFieldAndResetState(
 		match.c_str(), &(wpa_ssid->eap.domain_suffix_match),
 		"eap domain_suffix_match")) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::getSsid(getSsid_cb _hidl_cb)
+std::pair<SupplicantStatus, std::vector<uint8_t>> StaNetwork::getSsidInternal()
 {
+	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
 	std::vector<uint8_t> ssid;
-	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, ssid);
-	}
-
 	ssid.assign(wpa_ssid->ssid, wpa_ssid->ssid + wpa_ssid->ssid_len);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, ssid);
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(ssid)};
 }
 
-Return<void> StaNetwork::getBssid(getBssid_cb _hidl_cb)
+std::pair<SupplicantStatus, std::array<uint8_t, 6>>
+StaNetwork::getBssidInternal()
 {
-	hidl_array<uint8_t, 6> bssid;
-	os_memcpy(bssid.data(), kZeroBssid, ETH_ALEN);
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, bssid);
-	}
-
+	std::array<uint8_t, 6> bssid{};
+	os_memcpy(bssid.data(), kZeroBssid, ETH_ALEN);
 	if (wpa_ssid->bssid_set) {
 		os_memcpy(bssid.data(), wpa_ssid->bssid, ETH_ALEN);
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, bssid);
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(bssid)};
 }
 
-Return<void> StaNetwork::getScanSsid(getScanSsid_cb _hidl_cb)
+std::pair<SupplicantStatus, bool> StaNetwork::getScanSsidInternal()
 {
-	bool enabled = false;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, enabled);
-	}
-
-	enabled = (wpa_ssid->scan_ssid == 1);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, enabled);
+	return {{SupplicantStatusCode::SUCCESS, ""},
+		(wpa_ssid->scan_ssid == 1)};
 }
 
-Return<void> StaNetwork::getKeyMgmt(getKeyMgmt_cb _hidl_cb)
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getKeyMgmtInternal()
 {
-	uint32_t key_mgmt_mask = 0;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-		    key_mgmt_mask);
-	}
-
-	key_mgmt_mask = wpa_ssid->key_mgmt;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, key_mgmt_mask);
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->key_mgmt};
 }
 
-Return<void> StaNetwork::getProto(getProto_cb _hidl_cb)
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getProtoInternal()
 {
-	uint32_t proto_mask = 0;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, proto_mask);
-	}
-
-	proto_mask = wpa_ssid->proto;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, proto_mask);
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->proto};
 }
 
-Return<void> StaNetwork::getAuthAlg(getAuthAlg_cb _hidl_cb)
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getAuthAlgInternal()
 {
-	uint32_t auth_alg_mask = 0;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-		    auth_alg_mask);
-	}
-
-	auth_alg_mask = wpa_ssid->auth_alg;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, auth_alg_mask);
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->auth_alg};
 }
 
-Return<void> StaNetwork::getGroupCipher(getGroupCipher_cb _hidl_cb)
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getGroupCipherInternal()
 {
-	uint32_t group_cipher_mask = 0;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-		    group_cipher_mask);
-	}
-
-	group_cipher_mask = wpa_ssid->group_cipher;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, group_cipher_mask);
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->group_cipher};
 }
 
-Return<void> StaNetwork::getPairwiseCipher(getPairwiseCipher_cb _hidl_cb)
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getPairwiseCipherInternal()
 {
-	uint32_t pairwise_cipher_mask = 0;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-		    pairwise_cipher_mask);
-	}
-
-	pairwise_cipher_mask = wpa_ssid->pairwise_cipher;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, pairwise_cipher_mask);
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->pairwise_cipher};
 }
 
-Return<void> StaNetwork::getPskPassphrase(getPskPassphrase_cb _hidl_cb)
+std::pair<SupplicantStatus, std::string> StaNetwork::getPskPassphraseInternal()
 {
-	hidl_string psk;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID, psk);
-	}
-
+	std::string psk;
 	if (wpa_ssid->passphrase) {
 		psk = wpa_ssid->passphrase;
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, psk);
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(psk)};
 }
 
-Return<void> StaNetwork::getWepKey(uint32_t key_idx, getWepKey_cb _hidl_cb)
+std::pair<SupplicantStatus, std::vector<uint8_t>> StaNetwork::getWepKeyInternal(
+    uint32_t key_idx)
 {
 	std::vector<uint8_t> wep_key;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, wep_key);
-		return Void();
-	}
-
 	if (key_idx >=
 	    static_cast<uint32_t>(
 		ISupplicantStaNetwork::ParamSizeLimits::WEP_KEYS_MAX_NUM)) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_ARGS_INVALID, wep_key);
+		return {{SupplicantStatusCode::FAILURE_ARGS_INVALID, ""},
+			wep_key};
 	}
-
 	wep_key.assign(
 	    wpa_ssid->wep_key[key_idx],
 	    wpa_ssid->wep_key[key_idx] + wpa_ssid->wep_key_len[key_idx]);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, wep_key);
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(wep_key)};
 }
 
-Return<void> StaNetwork::getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb)
+std::pair<SupplicantStatus, uint32_t> StaNetwork::getWepTxKeyIdxInternal()
 {
-	uint32_t wep_tx_key_idx = UINT32_MAX;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID,
-		    wep_tx_key_idx);
-	}
-
-	wep_tx_key_idx = wpa_ssid->wep_tx_keyidx;
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, wep_tx_key_idx);
+	return {{SupplicantStatusCode::SUCCESS, ""}, wpa_ssid->wep_tx_keyidx};
 }
 
-Return<void> StaNetwork::getRequirePmf(getRequirePmf_cb _hidl_cb)
+std::pair<SupplicantStatus, bool> StaNetwork::getRequirePmfInternal()
 {
-	bool enabled = false;
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_NETWORK_INVALID, enabled);
-	}
-
-	enabled = (wpa_ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, enabled);
+	return {{SupplicantStatusCode::SUCCESS, ""},
+		(wpa_ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED)};
 }
 
-Return<void> StaNetwork::enable(bool no_connect, enable_cb _hidl_cb)
+SupplicantStatus StaNetwork::enableInternal(bool no_connect)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (wpa_ssid->disabled != 0) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	if (no_connect) {
 		wpa_ssid->disabled = 0;
@@ -855,55 +964,37 @@
 		wpa_s->scan_min_time.usec = 0;
 		wpa_supplicant_enable_network(wpa_s, wpa_ssid);
 	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::disable(disable_cb _hidl_cb)
+SupplicantStatus StaNetwork::disableInternal()
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (wpa_ssid->disabled == 2) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	wpa_supplicant_disable_network(wpa_s, wpa_ssid);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::select(select_cb _hidl_cb)
+SupplicantStatus StaNetwork::selectInternal()
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	if (wpa_ssid->disabled == 2) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
-
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	wpa_s->scan_min_time.sec = 0;
 	wpa_s->scan_min_time.usec = 0;
 	wpa_supplicant_select_network(wpa_s, wpa_ssid);
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::sendNetworkEapSimGsmAuthResponse(
-    const ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams &params,
-    sendNetworkEapSimGsmAuthResponse_cb _hidl_cb)
+SupplicantStatus StaNetwork::sendNetworkEapSimGsmAuthResponseInternal(
+    const ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams &params)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	// Convert the incoming parameters to a string to pass to
 	// wpa_supplicant.
 	std::string ctrl_rsp_param;
@@ -912,7 +1003,7 @@
 	uint32_t sres_hex_len = params.sres.size() * 2 + 1;
 	char *sres_hex = (char *)malloc(sres_hex_len);
 	if (!kc_hex || !sres_hex) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	wpa_snprintf_hex(
 	    kc_hex, kc_hex_len, params.kc.data(), params.kc.size());
@@ -922,30 +1013,23 @@
 	ctrl_rsp_param += kc_hex;
 	ctrl_rsp_param += " sres:";
 	ctrl_rsp_param += sres_hex;
-
 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	if (wpa_supplicant_ctrl_rsp_handle(
 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str())) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
 	wpa_hexdump_ascii_key(
 	    MSG_DEBUG, "network sim gsm auth response param",
 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::sendNetworkEapSimUmtsAuthResponse(
-    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams &params,
-    sendNetworkEapSimUmtsAuthResponse_cb _hidl_cb)
+SupplicantStatus StaNetwork::sendNetworkEapSimUmtsAuthResponseInternal(
+    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams &params)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	// Convert the incoming parameters to a string to pass to
 	// wpa_supplicant.
 	std::string ctrl_rsp_param;
@@ -956,7 +1040,7 @@
 	uint32_t res_hex_len = params.res.size() * 2 + 1;
 	char *res_hex = (char *)malloc(res_hex_len);
 	if (!ik_hex || !ck_hex || !res_hex) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	wpa_snprintf_hex(
 	    ik_hex, ik_hex_len, params.ik.data(), params.ik.size());
@@ -970,54 +1054,45 @@
 	ctrl_rsp_param += ck_hex;
 	ctrl_rsp_param += " res:";
 	ctrl_rsp_param += res_hex;
-
 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_SIM;
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	if (wpa_supplicant_ctrl_rsp_handle(
 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str())) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
 	wpa_hexdump_ascii_key(
 	    MSG_DEBUG, "network sim umts auth response param",
 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
-Return<void> StaNetwork::sendNetworkEapIdentityResponse(
-    const hidl_vec<uint8_t> &identity,
-    sendNetworkEapIdentityResponse_cb _hidl_cb)
+SupplicantStatus StaNetwork::sendNetworkEapIdentityResponseInternal(
+    const std::vector<uint8_t> &identity)
 {
 	struct wpa_ssid *wpa_ssid = retrieveNetworkPtr();
-	if (!wpa_ssid) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_NETWORK_INVALID);
-	}
-
 	// Convert the incoming parameters to a string to pass to
 	// wpa_supplicant.
 	uint32_t identity_hex_len = identity.size() * 2 + 1;
 	char *identity_hex = (char *)malloc(identity_hex_len);
 	std::string ctrl_rsp_param;
 	if (!identity_hex) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	wpa_snprintf_hex(
 	    identity_hex, identity_hex_len, identity.data(), identity.size());
 	ctrl_rsp_param = identity_hex;
-
 	enum wpa_ctrl_req_type rtype = WPA_CTRL_REQ_EAP_IDENTITY;
 	struct wpa_supplicant *wpa_s = retrieveIfacePtr();
 	if (wpa_supplicant_ctrl_rsp_handle(
 		wpa_s, wpa_ssid, rtype, ctrl_rsp_param.c_str())) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
 	}
 	eapol_sm_notify_ctrl_response(wpa_s->eapol);
 	wpa_hexdump_ascii_key(
 	    MSG_DEBUG, "network identity response param",
 	    (const u8 *)ctrl_rsp_param.c_str(), ctrl_rsp_param.size());
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return {SupplicantStatusCode::SUCCESS, ""};
 }
 
 /**
@@ -1052,7 +1127,7 @@
  *
  * Returns 0 if valid, 1 otherwise.
  */
-int StaNetwork::isPskPassphraseValid(const hidl_string &psk)
+int StaNetwork::isPskPassphraseValid(const std::string &psk)
 {
 	if (psk.size() <
 		static_cast<uint32_t>(ISupplicantStaNetwork::ParamSizeLimits::
diff --git a/wpa_supplicant/hidl/sta_network.h b/wpa_supplicant/hidl/sta_network.h
index a2055c3..f35f230 100644
--- a/wpa_supplicant/hidl/sta_network.h
+++ b/wpa_supplicant/hidl/sta_network.h
@@ -10,6 +10,9 @@
 #ifndef WPA_SUPPLICANT_HIDL_STA_NETWORK_H
 #define WPA_SUPPLICANT_HIDL_STA_NETWORK_H
 
+#include <array>
+#include <vector>
+
 #include <android-base/macros.h>
 
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h>
@@ -44,6 +47,9 @@
 	StaNetwork(
 	    struct wpa_global* wpa_global, const char ifname[], int network_id);
 	~StaNetwork() override = default;
+	// Refer to |StaIface::invalidate()|.
+	void invalidate();
+	bool isValid();
 
 	// Hidl methods exposed.
 	Return<void> getId(getId_cb _hidl_cb) override;
@@ -55,8 +61,7 @@
 	Return<void> setSsid(
 	    const hidl_vec<uint8_t>& ssid, setSsid_cb _hidl_cb) override;
 	Return<void> setBssid(
-	    const hidl_array<uint8_t, 6 /* 6 */>& bssid,
-	    setBssid_cb _hidl_cb) override;
+	    const hidl_array<uint8_t, 6>& bssid, setBssid_cb _hidl_cb) override;
 	Return<void> setScanSsid(bool enable, setScanSsid_cb _hidl_cb) override;
 	Return<void> setKeyMgmt(
 	    uint32_t key_mgmt_mask, setKeyMgmt_cb _hidl_cb) override;
@@ -142,9 +147,75 @@
 	    sendNetworkEapIdentityResponse_cb _hidl_cb) override;
 
 private:
+	// Corresponding worker functions for the HIDL methods.
+	std::pair<SupplicantStatus, uint32_t> getIdInternal();
+	std::pair<SupplicantStatus, std::string> getInterfaceNameInternal();
+	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
+	SupplicantStatus registerCallbackInternal(
+	    const sp<ISupplicantStaNetworkCallback>& callback);
+	SupplicantStatus setSsidInternal(const std::vector<uint8_t>& ssid);
+	SupplicantStatus setBssidInternal(const std::array<uint8_t, 6>& bssid);
+	SupplicantStatus setScanSsidInternal(bool enable);
+	SupplicantStatus setKeyMgmtInternal(uint32_t key_mgmt_mask);
+	SupplicantStatus setProtoInternal(uint32_t proto_mask);
+	SupplicantStatus setAuthAlgInternal(uint32_t auth_alg_mask);
+	SupplicantStatus setGroupCipherInternal(uint32_t group_cipher_mask);
+	SupplicantStatus setPairwiseCipherInternal(
+	    uint32_t pairwise_cipher_mask);
+	SupplicantStatus setPskPassphraseInternal(const std::string& psk);
+	SupplicantStatus setWepKeyInternal(
+	    uint32_t key_idx, const std::vector<uint8_t>& wep_key);
+	SupplicantStatus setWepTxKeyIdxInternal(uint32_t key_idx);
+	SupplicantStatus setRequirePmfInternal(bool enable);
+	SupplicantStatus setEapMethodInternal(
+	    ISupplicantStaNetwork::EapMethod method);
+	SupplicantStatus setEapPhase2MethodInternal(
+	    ISupplicantStaNetwork::EapPhase2Method method);
+	SupplicantStatus setEapIdentityInternal(
+	    const std::vector<uint8_t>& identity);
+	SupplicantStatus setEapAnonymousIdentityInternal(
+	    const std::vector<uint8_t>& identity);
+	SupplicantStatus setEapPasswordInternal(
+	    const std::vector<uint8_t>& password);
+	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 setEapSubjectMatchInternal(const std::string& match);
+	SupplicantStatus setEapAltSubjectMatchInternal(
+	    const std::string& match);
+	SupplicantStatus setEapEngineInternal(bool enable);
+	SupplicantStatus setEapEngineIDInternal(const std::string& id);
+	SupplicantStatus setEapDomainSuffixMatchInternal(
+	    const std::string& match);
+	std::pair<SupplicantStatus, std::vector<uint8_t>> getSsidInternal();
+	std::pair<SupplicantStatus, std::array<uint8_t, 6>> getBssidInternal();
+	std::pair<SupplicantStatus, bool> getScanSsidInternal();
+	std::pair<SupplicantStatus, uint32_t> getKeyMgmtInternal();
+	std::pair<SupplicantStatus, uint32_t> getProtoInternal();
+	std::pair<SupplicantStatus, uint32_t> getAuthAlgInternal();
+	std::pair<SupplicantStatus, uint32_t> getGroupCipherInternal();
+	std::pair<SupplicantStatus, uint32_t> getPairwiseCipherInternal();
+	std::pair<SupplicantStatus, std::string> getPskPassphraseInternal();
+	std::pair<SupplicantStatus, std::vector<uint8_t>> getWepKeyInternal(
+	    uint32_t key_idx);
+	std::pair<SupplicantStatus, uint32_t> getWepTxKeyIdxInternal();
+	std::pair<SupplicantStatus, bool> getRequirePmfInternal();
+	SupplicantStatus enableInternal(bool no_connect);
+	SupplicantStatus disableInternal();
+	SupplicantStatus selectInternal();
+	SupplicantStatus sendNetworkEapSimGsmAuthResponseInternal(
+	    const ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams&
+		params);
+	SupplicantStatus sendNetworkEapSimUmtsAuthResponseInternal(
+	    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams&
+		params);
+	SupplicantStatus sendNetworkEapIdentityResponseInternal(
+	    const std::vector<uint8_t>& identity);
+
 	struct wpa_ssid* retrieveNetworkPtr();
 	struct wpa_supplicant* retrieveIfacePtr();
-	int isPskPassphraseValid(const android::hardware::hidl_string& psk);
+	int isPskPassphraseValid(const std::string& psk);
 	void resetInternalStateAfterParamsUpdate();
 	int setStringFieldAndResetState(
 	    const char* value, uint8_t** to_update_field,
@@ -171,6 +242,7 @@
 	const std::string ifname_;
 	// Id of the network this hidl object controls.
 	const int network_id_;
+	bool is_valid_;
 
 	DISALLOW_COPY_AND_ASSIGN(StaNetwork);
 };
diff --git a/wpa_supplicant/hidl/supplicant.cpp b/wpa_supplicant/hidl/supplicant.cpp
index f32ceb9..aba4402 100644
--- a/wpa_supplicant/hidl/supplicant.cpp
+++ b/wpa_supplicant/hidl/supplicant.cpp
@@ -8,7 +8,7 @@
  */
 
 #include "hidl_manager.h"
-#include "hidl_return_macros.h"
+#include "hidl_return_util.h"
 #include "supplicant.h"
 
 namespace android {
@@ -17,6 +17,7 @@
 namespace supplicant {
 namespace V1_0 {
 namespace implementation {
+using hidl_return_util::validateAndCall;
 
 // These are hardcoded for android.
 const char Supplicant::kDriverName[] = "nl80211";
@@ -24,93 +25,148 @@
     "/data/misc/wifi/wpa_supplicant.conf";
 
 Supplicant::Supplicant(struct wpa_global* global) : wpa_global_(global) {}
+bool Supplicant::isValid()
+{
+	// This top level object cannot be invalidated.
+	return true;
+}
+
 Return<void> Supplicant::getInterface(
     const IfaceInfo& iface_info, getInterface_cb _hidl_cb)
 {
-	struct wpa_supplicant* wpa_s =
-	    wpa_supplicant_get_iface(wpa_global_, iface_info.name.c_str());
-	if (!wpa_s) {
-		HIDL_RETURN(
-		    SupplicantStatusCode::FAILURE_IFACE_UNKNOWN, nullptr);
-	}
-
-	HidlManager* hidl_manager = HidlManager::getInstance();
-	if (iface_info.type == IfaceType::P2P) {
-		android::sp<ISupplicantP2pIface> iface;
-		if (!hidl_manager ||
-		    hidl_manager->getP2pIfaceHidlObjectByIfname(
-			wpa_s->ifname, &iface)) {
-			HIDL_RETURN(
-			    SupplicantStatusCode::FAILURE_UNKNOWN, iface);
-		}
-
-		HIDL_RETURN(SupplicantStatusCode::SUCCESS, iface);
-	} else {
-		android::sp<ISupplicantStaIface> iface;
-		if (!hidl_manager ||
-		    hidl_manager->getStaIfaceHidlObjectByIfname(
-			wpa_s->ifname, &iface)) {
-			HIDL_RETURN(
-			    SupplicantStatusCode::FAILURE_UNKNOWN, iface);
-		}
-
-		HIDL_RETURN(SupplicantStatusCode::SUCCESS, iface);
-	}
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &Supplicant::getInterfaceInternal, _hidl_cb, iface_info);
 }
 
 Return<void> Supplicant::listInterfaces(listInterfaces_cb _hidl_cb)
 {
-	std::vector<ISupplicant::IfaceInfo> ifaces;
-	for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
-	     wpa_s = wpa_s->next) {
-		if (wpa_s->global->p2p_init_wpa_s == wpa_s) {
-			ifaces.emplace_back({IfaceType::P2P, wpa_s->ifname});
-		} else {
-			ifaces.emplace_back({IfaceType::STA, wpa_s->ifname});
-		}
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS, ifaces);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &Supplicant::listInterfacesInternal, _hidl_cb);
 }
 
 Return<void> Supplicant::registerCallback(
     const sp<ISupplicantCallback>& callback, registerCallback_cb _hidl_cb)
 {
-	HidlManager* hidl_manager = HidlManager::getInstance();
-	if (!hidl_manager ||
-	    hidl_manager->addSupplicantCallbackHidlObject(callback)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
-
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &Supplicant::registerCallbackInternal, _hidl_cb, callback);
 }
 
 Return<void> Supplicant::setDebugParams(
     ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys,
     setDebugParams_cb _hidl_cb)
 {
-	if (wpa_supplicant_set_debug_params(
-		wpa_global_, static_cast<uint32_t>(level), show_timestamp,
-		show_keys)) {
-		HIDL_RETURN(SupplicantStatusCode::FAILURE_UNKNOWN);
-	}
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &Supplicant::setDebugParamsInternal, _hidl_cb, level,
+	    show_timestamp, show_keys);
+}
 
-	HIDL_RETURN(SupplicantStatusCode::SUCCESS);
+Return<void> Supplicant::setConcurrencyPriority(
+    IfaceType type, setConcurrencyPriority_cb _hidl_cb)
+{
+	return validateAndCall(
+	    this, SupplicantStatusCode::FAILURE_IFACE_INVALID,
+	    &Supplicant::setConcurrencyPriorityInternal, _hidl_cb, type);
 }
 
 Return<ISupplicant::DebugLevel> Supplicant::getDebugLevel()
 {
+	// TODO: Add SupplicantStatus in this method return for uniformity with
+	// the other methods in supplicant HIDL interface.
 	return (ISupplicant::DebugLevel)wpa_debug_level;
 }
 
 Return<bool> Supplicant::isDebugShowTimestampEnabled()
 {
-	return (wpa_debug_timestamp ? true : false);
+	// TODO: Add SupplicantStatus in this method return for uniformity with
+	// the other methods in supplicant HIDL interface.
+	return ((wpa_debug_timestamp != 0) ? true : false);
 }
 
 Return<bool> Supplicant::isDebugShowKeysEnabled()
 {
-	return (wpa_debug_show_keys ? true : false);
+	// TODO: Add SupplicantStatus in this method return for uniformity with
+	// the other methods in supplicant HIDL interface.
+	return ((wpa_debug_show_keys != 0) ? true : false);
+}
+
+std::pair<SupplicantStatus, sp<ISupplicantIface>>
+Supplicant::getInterfaceInternal(const IfaceInfo& iface_info)
+{
+	struct wpa_supplicant* wpa_s =
+	    wpa_supplicant_get_iface(wpa_global_, iface_info.name.c_str());
+	if (!wpa_s) {
+		return {{SupplicantStatusCode::FAILURE_IFACE_UNKNOWN, ""},
+			nullptr};
+	}
+	HidlManager* hidl_manager = HidlManager::getInstance();
+	if (iface_info.type == IfaceType::P2P) {
+		android::sp<ISupplicantP2pIface> iface;
+		if (!hidl_manager ||
+		    hidl_manager->getP2pIfaceHidlObjectByIfname(
+			wpa_s->ifname, &iface)) {
+			return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
+				iface};
+		}
+		return {{SupplicantStatusCode::SUCCESS, ""}, iface};
+	} else {
+		android::sp<ISupplicantStaIface> iface;
+		if (!hidl_manager ||
+		    hidl_manager->getStaIfaceHidlObjectByIfname(
+			wpa_s->ifname, &iface)) {
+			return {{SupplicantStatusCode::FAILURE_UNKNOWN, ""},
+				iface};
+		}
+		return {{SupplicantStatusCode::SUCCESS, ""}, iface};
+	}
+}
+
+std::pair<SupplicantStatus, std::vector<ISupplicant::IfaceInfo>>
+Supplicant::listInterfacesInternal()
+{
+	std::vector<ISupplicant::IfaceInfo> ifaces;
+	for (struct wpa_supplicant* wpa_s = wpa_global_->ifaces; wpa_s;
+	     wpa_s = wpa_s->next) {
+		if (wpa_s->global->p2p_init_wpa_s == wpa_s) {
+			ifaces.emplace_back(ISupplicant::IfaceInfo{
+			    IfaceType::P2P, wpa_s->ifname});
+		} else {
+			ifaces.emplace_back(ISupplicant::IfaceInfo{
+			    IfaceType::STA, wpa_s->ifname});
+		}
+	}
+	return {{SupplicantStatusCode::SUCCESS, ""}, std::move(ifaces)};
+}
+
+SupplicantStatus Supplicant::registerCallbackInternal(
+    const sp<ISupplicantCallback>& callback)
+{
+	HidlManager* hidl_manager = HidlManager::getInstance();
+	if (!hidl_manager ||
+	    hidl_manager->addSupplicantCallbackHidlObject(callback)) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus Supplicant::setDebugParamsInternal(
+    ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys)
+{
+	if (wpa_supplicant_set_debug_params(
+		wpa_global_, static_cast<uint32_t>(level), show_timestamp,
+		show_keys)) {
+		return {SupplicantStatusCode::FAILURE_UNKNOWN, ""};
+	}
+	return {SupplicantStatusCode::SUCCESS, ""};
+}
+
+SupplicantStatus Supplicant::setConcurrencyPriorityInternal(IfaceType type)
+{
+	// TODO: Add implementation.
+	return SupplicantStatus{SupplicantStatusCode::SUCCESS, ""};
 }
 }  // namespace implementation
 }  // namespace V1_0
diff --git a/wpa_supplicant/hidl/supplicant.h b/wpa_supplicant/hidl/supplicant.h
index f4a77d9..1ad8402 100644
--- a/wpa_supplicant/hidl/supplicant.h
+++ b/wpa_supplicant/hidl/supplicant.h
@@ -39,6 +39,7 @@
 public:
 	Supplicant(struct wpa_global* global);
 	~Supplicant() override = default;
+	bool isValid();
 
 	// Hidl methods exposed.
 	Return<void> getInterface(
@@ -53,8 +54,21 @@
 	Return<ISupplicant::DebugLevel> getDebugLevel() override;
 	Return<bool> isDebugShowTimestampEnabled() override;
 	Return<bool> isDebugShowKeysEnabled() override;
+	Return<void> setConcurrencyPriority(
+	    IfaceType type, setConcurrencyPriority_cb _hidl_cb) override;
 
 private:
+	// Corresponding worker functions for the HIDL methods.
+	std::pair<SupplicantStatus, sp<ISupplicantIface>> getInterfaceInternal(
+	    const IfaceInfo& iface_info);
+	std::pair<SupplicantStatus, std::vector<ISupplicant::IfaceInfo>>
+	listInterfacesInternal();
+	SupplicantStatus registerCallbackInternal(
+	    const sp<ISupplicantCallback>& callback);
+	SupplicantStatus setDebugParamsInternal(
+	    ISupplicant::DebugLevel level, bool show_timestamp, bool show_keys);
+	SupplicantStatus setConcurrencyPriorityInternal(IfaceType type);
+
 	// Raw pointer to the global structure maintained by the core.
 	struct wpa_global* wpa_global_;
 	// Driver name to be used for creating interfaces.