wpa_supplicant: Add support for 2 iface types

Add support for 2 iface/network types in Hidl Manager:

Changes in the CL:
1. Added separate map of callbacks & objects for each Iface/Network
type.
2. Added templated functions in hidl_manager.cpp to deal with these
additional types.

Bug: 32553421
Bug: 31497295
Test: Compiles
Change-Id: Ic27cd02c391b6e85afe30e809f7d7126f0c0e1ee
diff --git a/wpa_supplicant/hidl/hidl_manager.cpp b/wpa_supplicant/hidl/hidl_manager.cpp
index 372b221..c5705d1 100644
--- a/wpa_supplicant/hidl/hidl_manager.cpp
+++ b/wpa_supplicant/hidl/hidl_manager.cpp
@@ -11,11 +11,282 @@
 
 #include "hidl_manager.h"
 
-extern "C" {
-#include "utils/common.h"
-#include "utils/includes.h"
+namespace {
+/**
+ * Check if the provided |wpa_supplicant| structure represents a P2P iface or
+ * not.
+ */
+constexpr bool isP2pIface(const struct wpa_supplicant *wpa_s)
+{
+	return (wpa_s->global->p2p_init_wpa_s == wpa_s);
 }
 
+/**
+ * Creates a unique key for the network using the provided |ifname| and
+ * |network_id| to be used in the internal map of |ISupplicantNetwork| objects.
+ * This is of the form |ifname|_|network_id|. For ex: "wlan0_1".
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param network_id ID of the corresponding network.
+ */
+const std::string getNetworkObjectMapKey(
+    const std::string &ifname, int network_id)
+{
+	return ifname + "_" + std::to_string(network_id);
+}
+
+/**
+ * Add callback to the corresponding list after linking to death on the
+ * corresponding hidl object reference.
+ */
+template <class CallbackType>
+int registerForDeathAndAddCallbackHidlObjectToList(
+    const android::sp<CallbackType> &callback,
+    const std::function<void(const android::sp<CallbackType> &)>
+	&on_hidl_died_fctor,
+    std::vector<android::sp<CallbackType>> &callback_list)
+{
+#if 0   // TODO(b/31632518): HIDL object death notifications.
+	auto death_notifier = new CallbackObjectDeathNotifier<CallbackType>(
+	    callback, on_hidl_died_fctor);
+	// Use the |callback.get()| as cookie so that we don't need to
+	// store a reference to this |CallbackObjectDeathNotifier| instance
+	// to use in |unlinkToDeath| later.
+	// NOTE: This may cause an immediate callback if the object is already
+	// dead, so add it to the list before we register for callback!
+	if (android::hardware::IInterface::asBinder(callback)->linkToDeath(
+		death_notifier, callback.get()) != android::OK) {
+		wpa_printf(
+		    MSG_ERROR,
+		    "Error registering for death notification for "
+		    "supplicant callback object");
+		callback_list.erase(
+		    std::remove(
+			callback_list.begin(), callback_list.end(), callback),
+		    callback_list.end());
+		return 1;
+	}
+#endif  // TODO(b/31632518): HIDL object death notifications.
+	callback_list.push_back(callback);
+	return 0;
+}
+
+template <class ObjectType>
+int addHidlObjectToMap(
+    const std::string &key, const android::sp<ObjectType> object,
+    std::map<const std::string, android::sp<ObjectType>> &object_map)
+{
+	// Return failure if we already have an object for that |key|.
+	if (object_map.find(key) != object_map.end())
+		return 1;
+	object_map[key] = object;
+	if (!object_map[key].get())
+		return 1;
+	return 0;
+}
+
+template <class ObjectType>
+int removeHidlObjectFromMap(
+    const std::string &key,
+    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())
+		return 1;
+	object_map.erase(key);
+	return 0;
+}
+
+template <class CallbackType>
+int addIfaceCallbackHidlObjectToMap(
+    const std::string &ifname, const android::sp<CallbackType> &callback,
+    const std::function<void(const android::sp<CallbackType> &)>
+	&on_hidl_died_fctor,
+    std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	if (ifname.empty())
+		return 1;
+
+	auto iface_callback_map_iter = callbacks_map.find(ifname);
+	if (iface_callback_map_iter == callbacks_map.end())
+		return 1;
+	auto &iface_callback_list = iface_callback_map_iter->second;
+
+	// Register for death notification before we add it to our list.
+	return registerForDeathAndAddCallbackHidlObjectToList<CallbackType>(
+	    callback, on_hidl_died_fctor, iface_callback_list);
+}
+
+template <class CallbackType>
+int addNetworkCallbackHidlObjectToMap(
+    const std::string &ifname, int network_id,
+    const android::sp<CallbackType> &callback,
+    const std::function<void(const android::sp<CallbackType> &)>
+	&on_hidl_died_fctor,
+    std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	if (ifname.empty() || network_id < 0)
+		return 1;
+
+	// Generate the key to be used to lookup the network.
+	const std::string network_key =
+	    getNetworkObjectMapKey(ifname, network_id);
+	auto network_callback_map_iter = callbacks_map.find(network_key);
+	if (network_callback_map_iter == callbacks_map.end())
+		return 1;
+	auto &network_callback_list = network_callback_map_iter->second;
+
+	// Register for death notification before we add it to our list.
+	return registerForDeathAndAddCallbackHidlObjectToList<CallbackType>(
+	    callback, on_hidl_died_fctor, network_callback_list);
+}
+
+template <class CallbackType>
+int removeAllIfaceCallbackHidlObjectsFromMap(
+    const std::string &ifname,
+    std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	auto iface_callback_map_iter = callbacks_map.find(ifname);
+	if (iface_callback_map_iter == callbacks_map.end())
+		return 1;
+#if 0   // TODO(b/31632518): HIDL object death notifications.
+	const auto &iface_callback_list = iface_callback_map_iter->second;
+	for (const auto &callback : iface_callback_list) {
+		if (android::hardware::IInterface::asBinder(callback)
+			->unlinkToDeath(nullptr, callback.get()) !=
+		    android::OK) {
+			wpa_printf(
+			    MSG_ERROR,
+			    "Error deregistering for death notification for "
+			    "iface callback object");
+		}
+	}
+#endif  // TODO(b/31632518): HIDL object death notifications.
+	callbacks_map.erase(iface_callback_map_iter);
+	return 0;
+}
+
+template <class CallbackType>
+int removeAllNetworkCallbackHidlObjectsFromMap(
+    const std::string &network_key,
+    std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	auto network_callback_map_iter = callbacks_map.find(network_key);
+	if (network_callback_map_iter == callbacks_map.end())
+		return 1;
+#if 0   // TODO(b/31632518): HIDL object death notifications.
+	const auto &network_callback_list = network_callback_map_iter->second;
+	for (const auto &callback : network_callback_list) {
+		if (android::hardware::IInterface::asBinder(callback)
+			->unlinkToDeath(nullptr, callback.get()) !=
+		    android::OK) {
+			wpa_printf(
+			    MSG_ERROR,
+			    "Error deregistering for death "
+			    "notification for "
+			    "network callback object");
+		}
+	}
+#endif  // TODO(b/31632518): HIDL object death notifications.
+	callbacks_map.erase(network_callback_map_iter);
+	return 0;
+}
+
+template <class CallbackType>
+void removeIfaceCallbackHidlObjectFromMap(
+    const std::string &ifname, const android::sp<CallbackType> &callback,
+    std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	if (ifname.empty())
+		return;
+
+	auto iface_callback_map_iter = callbacks_map.find(ifname);
+	if (iface_callback_map_iter == callbacks_map.end())
+		return;
+
+	auto &iface_callback_list = iface_callback_map_iter->second;
+	iface_callback_list.erase(
+	    std::remove(
+		iface_callback_list.begin(), iface_callback_list.end(),
+		callback),
+	    iface_callback_list.end());
+}
+
+template <class CallbackType>
+void removeNetworkCallbackHidlObjectFromMap(
+    const std::string &ifname, int network_id,
+    const android::sp<CallbackType> &callback,
+    std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	if (ifname.empty() || network_id < 0)
+		return;
+
+	// Generate the key to be used to lookup the network.
+	const std::string network_key =
+	    getNetworkObjectMapKey(ifname, network_id);
+
+	auto network_callback_map_iter = callbacks_map.find(network_key);
+	if (network_callback_map_iter == callbacks_map.end())
+		return;
+
+	auto &network_callback_list = network_callback_map_iter->second;
+	network_callback_list.erase(
+	    std::remove(
+		network_callback_list.begin(), network_callback_list.end(),
+		callback),
+	    network_callback_list.end());
+}
+
+template <class CallbackType>
+void callWithEachIfaceCallback(
+    const std::string &ifname,
+    const std::function<
+	android::hardware::Return<void>(android::sp<CallbackType>)> &method,
+    const std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	if (ifname.empty())
+		return;
+
+	auto iface_callback_map_iter = callbacks_map.find(ifname);
+	if (iface_callback_map_iter == callbacks_map.end())
+		return;
+	const auto &iface_callback_list = iface_callback_map_iter->second;
+	for (const auto &callback : iface_callback_list) {
+		method(callback);
+	}
+}
+
+template <class CallbackType>
+void callWithEachNetworkCallback(
+    const std::string &ifname, int network_id,
+    const std::function<
+	android::hardware::Return<void>(android::sp<CallbackType>)> &method,
+    const std::map<const std::string, std::vector<android::sp<CallbackType>>>
+	&callbacks_map)
+{
+	if (ifname.empty() || network_id < 0)
+		return;
+
+	// Generate the key to be used to lookup the network.
+	const std::string network_key =
+	    getNetworkObjectMapKey(ifname, network_id);
+	auto network_callback_map_iter = callbacks_map.find(network_key);
+	if (network_callback_map_iter == callbacks_map.end())
+		return;
+	const auto &network_callback_list = network_callback_map_iter->second;
+	for (const auto &callback : network_callback_list) {
+		method(callback);
+	}
+}
+}  // namespace
+
 namespace android {
 namespace hardware {
 namespace wifi {
@@ -66,17 +337,21 @@
 	// Using the corresponding ifname as key to our object map.
 	const std::string ifname(wpa_s->ifname);
 
-	// Return failure if we already have an object for that |ifname|.
-	if (iface_object_map_.find(ifname) != iface_object_map_.end())
-		return 1;
-
-	iface_object_map_[ifname] = new Iface(wpa_s->global, wpa_s->ifname);
-	if (!iface_object_map_[ifname].get())
-		return 1;
-
-	// Initialize the vector of callbacks for this object.
-	iface_callbacks_map_[ifname] =
-	    std::vector<android::sp<ISupplicantIfaceCallback>>();
+	if (isP2pIface(wpa_s)) {
+		if (addHidlObjectToMap<P2pIface>(
+			ifname, new P2pIface(wpa_s->global, wpa_s->ifname),
+			p2p_iface_object_map_))
+			return 1;
+		p2p_iface_callbacks_map_[ifname] =
+		    std::vector<android::sp<ISupplicantP2pIfaceCallback>>();
+	} else {
+		if (addHidlObjectToMap<StaIface>(
+			ifname, new StaIface(wpa_s->global, wpa_s->ifname),
+			sta_iface_object_map_))
+			return 1;
+		sta_iface_callbacks_map_[ifname] =
+		    std::vector<android::sp<ISupplicantStaIfaceCallback>>();
+	}
 
 	// Invoke the |onInterfaceCreated| method on all registered callbacks.
 	callWithEachSupplicantCallback(std::bind(
@@ -99,30 +374,21 @@
 
 	const std::string ifname(wpa_s->ifname);
 
-	if (iface_object_map_.find(ifname) == iface_object_map_.end())
-		return 1;
-
-	// Delete the corresponding iface object from our map.
-	iface_object_map_.erase(ifname);
-
-	// Delete all callbacks registered for this object.
-	auto iface_callback_map_iter = iface_callbacks_map_.find(ifname);
-	if (iface_callback_map_iter == iface_callbacks_map_.end())
-		return 1;
-	const auto &iface_callback_list = iface_callback_map_iter->second;
-#if 0   // TODO(b/31632518): HIDL object death notifications.
-	for (const auto &callback : iface_callback_list) {
-		if (android::hardware::IInterface::asBinder(callback)
-			->unlinkToDeath(nullptr, callback.get()) !=
-		    android::OK) {
-			wpa_printf(
-			    MSG_ERROR,
-			    "Error deregistering for death notification for "
-			    "iface callback object");
+	if (isP2pIface(wpa_s)) {
+		if (removeHidlObjectFromMap(ifname, p2p_iface_object_map_))
+			return 1;
+		if (removeAllIfaceCallbackHidlObjectsFromMap(
+			ifname, p2p_iface_callbacks_map_)) {
+			return 1;
+		}
+	} else {
+		if (removeHidlObjectFromMap(ifname, sta_iface_object_map_))
+			return 1;
+		if (removeAllIfaceCallbackHidlObjectsFromMap(
+			ifname, sta_iface_callbacks_map_)) {
+			return 1;
 		}
 	}
-#endif  // TODO(b/31632518): HIDL object death notifications.
-	iface_callbacks_map_.erase(iface_callback_map_iter);
 
 	// Invoke the |onInterfaceRemoved| method on all registered callbacks.
 	callWithEachSupplicantCallback(std::bind(
@@ -150,23 +416,37 @@
 	const std::string network_key =
 	    getNetworkObjectMapKey(wpa_s->ifname, ssid->id);
 
-	if (network_object_map_.find(network_key) != network_object_map_.end())
-		return 1;
-
-	network_object_map_[network_key] =
-	    new Network(wpa_s->global, wpa_s->ifname, ssid->id);
-	if (!network_object_map_[network_key].get())
-		return 1;
-
-	// Initialize the vector of callbacks for this object.
-	network_callbacks_map_[network_key] =
-	    std::vector<android::sp<ISupplicantNetworkCallback>>();
-
-	// Invoke the |onNetworkAdded| method on all registered callbacks.
-	callWithEachIfaceCallback(
-	    wpa_s->ifname, std::bind(
-			       &ISupplicantIfaceCallback::onNetworkAdded,
-			       std::placeholders::_1, ssid->id));
+	if (isP2pIface(wpa_s)) {
+		if (addHidlObjectToMap<P2pNetwork>(
+			network_key,
+			new P2pNetwork(wpa_s->global, wpa_s->ifname, ssid->id),
+			p2p_network_object_map_))
+			return 1;
+		p2p_network_callbacks_map_[network_key] =
+		    std::vector<android::sp<ISupplicantP2pNetworkCallback>>();
+		// Invoke the |onNetworkAdded| method on all registered
+		// callbacks.
+		callWithEachP2pIfaceCallback(
+		    wpa_s->ifname,
+		    std::bind(
+			&ISupplicantP2pIfaceCallback::onNetworkAdded,
+			std::placeholders::_1, ssid->id));
+	} else {
+		if (addHidlObjectToMap<StaNetwork>(
+			network_key,
+			new StaNetwork(wpa_s->global, wpa_s->ifname, ssid->id),
+			sta_network_object_map_))
+			return 1;
+		sta_network_callbacks_map_[network_key] =
+		    std::vector<android::sp<ISupplicantStaNetworkCallback>>();
+		// Invoke the |onNetworkAdded| method on all registered
+		// callbacks.
+		callWithEachStaIfaceCallback(
+		    wpa_s->ifname,
+		    std::bind(
+			&ISupplicantStaIfaceCallback::onNetworkAdded,
+			std::placeholders::_1, ssid->id));
+	}
 	return 0;
 }
 
@@ -189,38 +469,35 @@
 	const std::string network_key =
 	    getNetworkObjectMapKey(wpa_s->ifname, ssid->id);
 
-	if (network_object_map_.find(network_key) == network_object_map_.end())
-		return 1;
+	if (isP2pIface(wpa_s)) {
+		if (removeHidlObjectFromMap(network_key, p2p_iface_object_map_))
+			return 1;
+		if (removeAllNetworkCallbackHidlObjectsFromMap(
+			network_key, p2p_network_callbacks_map_))
+			return 1;
 
-	// Delete the corresponding network object from our map.
-	network_object_map_.erase(network_key);
+		// Invoke the |onNetworkRemoved| method on all registered
+		// callbacks.
+		callWithEachP2pIfaceCallback(
+		    wpa_s->ifname,
+		    std::bind(
+			&ISupplicantP2pIfaceCallback::onNetworkRemoved,
+			std::placeholders::_1, ssid->id));
+	} else {
+		if (removeHidlObjectFromMap(network_key, sta_iface_object_map_))
+			return 1;
+		if (removeAllNetworkCallbackHidlObjectsFromMap(
+			network_key, sta_network_callbacks_map_))
+			return 1;
 
-	// Delete all callbacks registered for this object.
-	auto network_callback_map_iter =
-	    network_callbacks_map_.find(network_key);
-	if (network_callback_map_iter == network_callbacks_map_.end())
-		return 1;
-	const auto &network_callback_list = network_callback_map_iter->second;
-#if 0   // TODO(b/31632518): HIDL object death notifications.
-	for (const auto &callback : network_callback_list) {
-		if (android::hardware::IInterface::asBinder(callback)
-			->unlinkToDeath(nullptr, callback.get()) !=
-		    android::OK) {
-			wpa_printf(
-			    MSG_ERROR,
-			    "Error deregistering for death "
-			    "notification for "
-			    "network callback object");
-		}
+		// Invoke the |onNetworkRemoved| method on all registered
+		// callbacks.
+		callWithEachStaIfaceCallback(
+		    wpa_s->ifname,
+		    std::bind(
+			&ISupplicantStaIfaceCallback::onNetworkRemoved,
+			std::placeholders::_1, ssid->id));
 	}
-#endif  // TODO(b/31632518): HIDL object death notifications.
-	network_callbacks_map_.erase(network_callback_map_iter);
-
-	// Invoke the |onNetworkRemoved| method on all registered callbacks.
-	callWithEachIfaceCallback(
-	    wpa_s->ifname, std::bind(
-			       &ISupplicantIfaceCallback::onNetworkRemoved,
-			       std::placeholders::_1, ssid->id));
 	return 0;
 }
 
@@ -236,12 +513,12 @@
 		return 1;
 
 	const std::string ifname(wpa_s->ifname);
-	if (iface_object_map_.find(ifname) == iface_object_map_.end())
+	if (sta_iface_object_map_.find(ifname) == sta_iface_object_map_.end())
 		return 1;
 
 	// Invoke the |onStateChanged| method on all registered callbacks.
-	ISupplicantIfaceCallback::State hidl_state =
-	    static_cast<ISupplicantIfaceCallback::State>(wpa_s->wpa_state);
+	ISupplicantStaIfaceCallback::State hidl_state =
+	    static_cast<ISupplicantStaIfaceCallback::State>(wpa_s->wpa_state);
 	hidl_array<uint8_t, 6> hidl_bssid;
 	os_memcpy(hidl_bssid.data(), wpa_s->bssid, ETH_ALEN);
 	uint32_t hidl_network_id = UINT32_MAX;
@@ -252,9 +529,9 @@
 		    wpa_s->current_ssid->ssid,
 		    wpa_s->current_ssid->ssid + wpa_s->current_ssid->ssid_len);
 	}
-	callWithEachIfaceCallback(
+	callWithEachStaIfaceCallback(
 	    wpa_s->ifname, std::bind(
-			       &ISupplicantIfaceCallback::onStateChanged,
+			       &ISupplicantStaIfaceCallback::onStateChanged,
 			       std::placeholders::_1, hidl_state, hidl_bssid,
 			       hidl_network_id, hidl_ssid));
 	return 0;
@@ -278,7 +555,8 @@
 
 	const std::string network_key =
 	    getNetworkObjectMapKey(wpa_s->ifname, ssid->id);
-	if (network_object_map_.find(network_key) == network_object_map_.end())
+	if (sta_network_object_map_.find(network_key) ==
+	    sta_network_object_map_.end())
 		return 1;
 
 	// TODO(b/31646740): Parse the param string to find the appropriate
@@ -287,7 +565,7 @@
 }
 
 /**
- * Retrieve the |ISupplicantIface| hidl object reference using the provided
+ * Retrieve the |ISupplicantP2pIface| hidl object reference using the provided
  * ifname.
  *
  * @param ifname Name of the corresponding interface.
@@ -295,14 +573,14 @@
  *
  * @return 0 on success, 1 on failure.
  */
-int HidlManager::getIfaceHidlObjectByIfname(
-    const std::string &ifname, android::sp<ISupplicantIface> *iface_object)
+int HidlManager::getP2pIfaceHidlObjectByIfname(
+    const std::string &ifname, android::sp<ISupplicantP2pIface> *iface_object)
 {
 	if (ifname.empty() || !iface_object)
 		return 1;
 
-	auto iface_object_iter = iface_object_map_.find(ifname);
-	if (iface_object_iter == iface_object_map_.end())
+	auto iface_object_iter = p2p_iface_object_map_.find(ifname);
+	if (iface_object_iter == p2p_iface_object_map_.end())
 		return 1;
 
 	*iface_object = iface_object_iter->second;
@@ -310,7 +588,30 @@
 }
 
 /**
- * Retrieve the |ISupplicantNetwork| hidl object reference using the provided
+ * Retrieve the |ISupplicantStaIface| hidl object reference using the provided
+ * ifname.
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param iface_object Hidl reference corresponding to the iface.
+ *
+ * @return 0 on success, 1 on failure.
+ */
+int HidlManager::getStaIfaceHidlObjectByIfname(
+    const std::string &ifname, android::sp<ISupplicantStaIface> *iface_object)
+{
+	if (ifname.empty() || !iface_object)
+		return 1;
+
+	auto iface_object_iter = sta_iface_object_map_.find(ifname);
+	if (iface_object_iter == sta_iface_object_map_.end())
+		return 1;
+
+	*iface_object = iface_object_iter->second;
+	return 0;
+}
+
+/**
+ * Retrieve the |ISupplicantP2pNetwork| hidl object reference using the provided
  * ifname and network_id.
  *
  * @param ifname Name of the corresponding interface.
@@ -319,9 +620,9 @@
  *
  * @return 0 on success, 1 on failure.
  */
-int HidlManager::getNetworkHidlObjectByIfnameAndNetworkId(
+int HidlManager::getP2pNetworkHidlObjectByIfnameAndNetworkId(
     const std::string &ifname, int network_id,
-    android::sp<ISupplicantNetwork> *network_object)
+    android::sp<ISupplicantP2pNetwork> *network_object)
 {
 	if (ifname.empty() || network_id < 0 || !network_object)
 		return 1;
@@ -330,8 +631,37 @@
 	const std::string network_key =
 	    getNetworkObjectMapKey(ifname, network_id);
 
-	auto network_object_iter = network_object_map_.find(network_key);
-	if (network_object_iter == network_object_map_.end())
+	auto network_object_iter = p2p_network_object_map_.find(network_key);
+	if (network_object_iter == p2p_network_object_map_.end())
+		return 1;
+
+	*network_object = network_object_iter->second;
+	return 0;
+}
+
+/**
+ * Retrieve the |ISupplicantStaNetwork| hidl object reference using the provided
+ * ifname and network_id.
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param network_id ID of the corresponding network.
+ * @param network_object Hidl reference corresponding to the network.
+ *
+ * @return 0 on success, 1 on failure.
+ */
+int HidlManager::getStaNetworkHidlObjectByIfnameAndNetworkId(
+    const std::string &ifname, int network_id,
+    android::sp<ISupplicantStaNetwork> *network_object)
+{
+	if (ifname.empty() || network_id < 0 || !network_object)
+		return 1;
+
+	// Generate the key to be used to lookup the network.
+	const std::string network_key =
+	    getNetworkObjectMapKey(ifname, network_id);
+
+	auto network_object_iter = sta_network_object_map_.find(network_key);
+	if (network_object_iter == sta_network_object_map_.end())
 		return 1;
 
 	*network_object = network_object_iter->second;
@@ -357,83 +687,97 @@
 	    ISupplicantCallback>(
 	    callback, on_hidl_died_fctor, supplicant_callbacks_);
 }
+
 /**
- * Add a new |ISupplicantIfaceCallback| hidl object reference to our
+ * Add a new iface callback hidl object reference to our
  * interface callback list.
  *
  * @param ifname Name of the corresponding interface.
- * @param callback Hidl reference of the |ISupplicantIfaceCallback| object.
+ * @param callback Hidl reference of the callback object.
  *
  * @return 0 on success, 1 on failure.
  */
-int HidlManager::addIfaceCallbackHidlObject(
+int HidlManager::addP2pIfaceCallbackHidlObject(
     const std::string &ifname,
-    const android::sp<ISupplicantIfaceCallback> &callback)
+    const android::sp<ISupplicantP2pIfaceCallback> &callback)
 {
-	if (ifname.empty())
-		return 1;
-
-	auto iface_callback_map_iter = iface_callbacks_map_.find(ifname);
-	if (iface_callback_map_iter == iface_callbacks_map_.end())
-		return 1;
-	auto &iface_callback_list = iface_callback_map_iter->second;
-
-	// Register for death notification before we add it to our list.
-	auto on_hidl_died_fctor = std::bind(
-	    &HidlManager::removeIfaceCallbackHidlObject, this, ifname,
-	    std::placeholders::_1);
-	return registerForDeathAndAddCallbackHidlObjectToList<
-	    ISupplicantIfaceCallback>(
-	    callback, on_hidl_died_fctor, iface_callback_list);
+	const std::function<void(
+	    const android::sp<ISupplicantP2pIfaceCallback> &)>
+	    on_hidl_died_fctor = std::bind(
+		&HidlManager::removeP2pIfaceCallbackHidlObject, this, ifname,
+		std::placeholders::_1);
+	return addIfaceCallbackHidlObjectToMap(
+	    ifname, callback, on_hidl_died_fctor, p2p_iface_callbacks_map_);
 }
 
 /**
- * Add a new |ISupplicantNetworkCallback| hidl object reference to our
- * network callback list.
+ * Add a new iface callback hidl object reference to our
+ * interface callback list.
  *
  * @param ifname Name of the corresponding interface.
- * @param network_id ID of the corresponding network.
- * @param callback Hidl reference of the |ISupplicantNetworkCallback| object.
+ * @param callback Hidl reference of the callback object.
  *
  * @return 0 on success, 1 on failure.
  */
-int HidlManager::addNetworkCallbackHidlObject(
-    const std::string &ifname, int network_id,
-    const android::sp<ISupplicantNetworkCallback> &callback)
+int HidlManager::addStaIfaceCallbackHidlObject(
+    const std::string &ifname,
+    const android::sp<ISupplicantStaIfaceCallback> &callback)
 {
-	if (ifname.empty() || network_id < 0)
-		return 1;
-
-	// Generate the key to be used to lookup the network.
-	const std::string network_key =
-	    getNetworkObjectMapKey(ifname, network_id);
-	auto network_callback_map_iter =
-	    network_callbacks_map_.find(network_key);
-	if (network_callback_map_iter == network_callbacks_map_.end())
-		return 1;
-	auto &network_callback_list = network_callback_map_iter->second;
-
-	// Register for death notification before we add it to our list.
-	auto on_hidl_died_fctor = std::bind(
-	    &HidlManager::removeNetworkCallbackHidlObject, this, ifname,
-	    network_id, std::placeholders::_1);
-	return registerForDeathAndAddCallbackHidlObjectToList<
-	    ISupplicantNetworkCallback>(
-	    callback, on_hidl_died_fctor, network_callback_list);
+	const std::function<void(
+	    const android::sp<ISupplicantStaIfaceCallback> &)>
+	    on_hidl_died_fctor = std::bind(
+		&HidlManager::removeStaIfaceCallbackHidlObject, this, ifname,
+		std::placeholders::_1);
+	return addIfaceCallbackHidlObjectToMap(
+	    ifname, callback, on_hidl_died_fctor, sta_iface_callbacks_map_);
 }
 
 /**
- * Creates a unique key for the network using the provided |ifname| and
- * |network_id| to be used in the internal map of |ISupplicantNetwork| objects.
- * This is of the form |ifname|_|network_id|. For ex: "wlan0_1".
+ * Add a new network callback hidl object reference to our network callback
+ * list.
  *
  * @param ifname Name of the corresponding interface.
  * @param network_id ID of the corresponding network.
+ * @param callback Hidl reference of the callback object.
+ *
+ * @return 0 on success, 1 on failure.
  */
-const std::string HidlManager::getNetworkObjectMapKey(
-    const std::string &ifname, int network_id)
+int HidlManager::addP2pNetworkCallbackHidlObject(
+    const std::string &ifname, int network_id,
+    const android::sp<ISupplicantP2pNetworkCallback> &callback)
 {
-	return ifname + "_" + std::to_string(network_id);
+	const std::function<void(
+	    const android::sp<ISupplicantP2pNetworkCallback> &)>
+	    on_hidl_died_fctor = std::bind(
+		&HidlManager::removeP2pNetworkCallbackHidlObject, this, ifname,
+		network_id, std::placeholders::_1);
+	return addNetworkCallbackHidlObjectToMap(
+	    ifname, network_id, callback, on_hidl_died_fctor,
+	    p2p_network_callbacks_map_);
+}
+
+/**
+ * Add a new network callback hidl object reference to our network callback
+ * list.
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param network_id ID of the corresponding network.
+ * @param callback Hidl reference of the callback object.
+ *
+ * @return 0 on success, 1 on failure.
+ */
+int HidlManager::addStaNetworkCallbackHidlObject(
+    const std::string &ifname, int network_id,
+    const android::sp<ISupplicantStaNetworkCallback> &callback)
+{
+	const std::function<void(
+	    const android::sp<ISupplicantStaNetworkCallback> &)>
+	    on_hidl_died_fctor = std::bind(
+		&HidlManager::removeStaNetworkCallbackHidlObject, this, ifname,
+		network_id, std::placeholders::_1);
+	return addNetworkCallbackHidlObjectToMap(
+	    ifname, network_id, callback, on_hidl_died_fctor,
+	    sta_network_callbacks_map_);
 }
 
 /**
@@ -453,101 +797,65 @@
 }
 
 /**
- * Removes the provided |ISupplicantIfaceCallback| hidl object reference from
+ * Removes the provided iface callback hidl object reference from
  * our interface callback list.
  *
  * @param ifname Name of the corresponding interface.
- * @param callback Hidl reference of the |ISupplicantIfaceCallback| object.
+ * @param callback Hidl reference of the callback object.
  */
-void HidlManager::removeIfaceCallbackHidlObject(
+void HidlManager::removeP2pIfaceCallbackHidlObject(
     const std::string &ifname,
-    const android::sp<ISupplicantIfaceCallback> &callback)
+    const android::sp<ISupplicantP2pIfaceCallback> &callback)
 {
-	if (ifname.empty())
-		return;
-
-	auto iface_callback_map_iter = iface_callbacks_map_.find(ifname);
-	if (iface_callback_map_iter == iface_callbacks_map_.end())
-		return;
-
-	auto &iface_callback_list = iface_callback_map_iter->second;
-	iface_callback_list.erase(
-	    std::remove(
-		iface_callback_list.begin(), iface_callback_list.end(),
-		callback),
-	    iface_callback_list.end());
+	return removeIfaceCallbackHidlObjectFromMap(
+	    ifname, callback, p2p_iface_callbacks_map_);
 }
 
 /**
- * Removes the provided |ISupplicantNetworkCallback| hidl object reference from
+ * Removes the provided iface callback hidl object reference from
+ * our interface callback list.
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param callback Hidl reference of the callback object.
+ */
+void HidlManager::removeStaIfaceCallbackHidlObject(
+    const std::string &ifname,
+    const android::sp<ISupplicantStaIfaceCallback> &callback)
+{
+	return removeIfaceCallbackHidlObjectFromMap(
+	    ifname, callback, sta_iface_callbacks_map_);
+}
+
+/**
+ * Removes the provided network callback hidl object reference from
  * our network callback list.
  *
  * @param ifname Name of the corresponding interface.
  * @param network_id ID of the corresponding network.
- * @param callback Hidl reference of the |ISupplicantNetworkCallback| object.
+ * @param callback Hidl reference of the callback object.
  */
-void HidlManager::removeNetworkCallbackHidlObject(
+void HidlManager::removeP2pNetworkCallbackHidlObject(
     const std::string &ifname, int network_id,
-    const android::sp<ISupplicantNetworkCallback> &callback)
+    const android::sp<ISupplicantP2pNetworkCallback> &callback)
 {
-	if (ifname.empty() || network_id < 0)
-		return;
-
-	// Generate the key to be used to lookup the network.
-	const std::string network_key =
-	    getNetworkObjectMapKey(ifname, network_id);
-
-	auto network_callback_map_iter =
-	    network_callbacks_map_.find(network_key);
-	if (network_callback_map_iter == network_callbacks_map_.end())
-		return;
-
-	auto &network_callback_list = network_callback_map_iter->second;
-	network_callback_list.erase(
-	    std::remove(
-		network_callback_list.begin(), network_callback_list.end(),
-		callback),
-	    network_callback_list.end());
+	return removeNetworkCallbackHidlObjectFromMap(
+	    ifname, network_id, callback, p2p_network_callbacks_map_);
 }
 
 /**
- * Add callback to the corresponding list after linking to death on the
- * corresponding hidl object reference.
+ * Removes the provided network callback hidl object reference from
+ * our network callback list.
  *
- * @param callback Hidl reference of the |ISupplicantNetworkCallback| object.
- *
- * @return 0 on success, 1 on failure.
+ * @param ifname Name of the corresponding interface.
+ * @param network_id ID of the corresponding network.
+ * @param callback Hidl reference of the callback object.
  */
-template <class CallbackType>
-int HidlManager::registerForDeathAndAddCallbackHidlObjectToList(
-    const android::sp<CallbackType> &callback,
-    const std::function<void(const android::sp<CallbackType> &)>
-	&on_hidl_died_fctor,
-    std::vector<android::sp<CallbackType>> &callback_list)
+void HidlManager::removeStaNetworkCallbackHidlObject(
+    const std::string &ifname, int network_id,
+    const android::sp<ISupplicantStaNetworkCallback> &callback)
 {
-	auto death_notifier = new CallbackObjectDeathNotifier<CallbackType>(
-	    callback, on_hidl_died_fctor);
-	// Use the |callback.get()| as cookie so that we don't need to
-	// store a reference to this |CallbackObjectDeathNotifier| instance
-	// to use in |unlinkToDeath| later.
-	// NOTE: This may cause an immediate callback if the object is already
-	// dead, so add it to the list before we register for callback!
-	callback_list.push_back(callback);
-#if 0   // TODO(b/31632518): HIDL object death notifications.
-	if (android::hardware::IInterface::asBinder(callback)->linkToDeath(
-		death_notifier, callback.get()) != android::OK) {
-		wpa_printf(
-		    MSG_ERROR,
-		    "Error registering for death notification for "
-		    "supplicant callback object");
-		callback_list.erase(
-		    std::remove(
-			callback_list.begin(), callback_list.end(), callback),
-		    callback_list.end());
-		return 1;
-	}
-#endif  // TODO(b/31632518): HIDL object death notifications.
-	return 0;
+	return removeNetworkCallbackHidlObjectFromMap(
+	    ifname, network_id, callback, sta_network_callbacks_map_);
 }
 
 /**
@@ -567,62 +875,75 @@
 
 /**
  * Helper fucntion to invoke the provided callback method on all the
- * registered |ISupplicantIfaceCallback| callback hidl objects for the specified
+ * registered iface callback hidl objects for the specified
  * |ifname|.
  *
  * @param ifname Name of the corresponding interface.
  * @param method Pointer to the required hidl method from
  * |ISupplicantIfaceCallback|.
  */
-void HidlManager::callWithEachIfaceCallback(
+void HidlManager::callWithEachP2pIfaceCallback(
     const std::string &ifname,
-    const std::function<Return<void>(android::sp<ISupplicantIfaceCallback>)>
+    const std::function<Return<void>(android::sp<ISupplicantP2pIfaceCallback>)>
 	&method)
 {
-	if (ifname.empty())
-		return;
+	callWithEachIfaceCallback(ifname, method, p2p_iface_callbacks_map_);
+}
 
-	auto iface_callback_map_iter = iface_callbacks_map_.find(ifname);
-	if (iface_callback_map_iter == iface_callbacks_map_.end())
-		return;
-	const auto &iface_callback_list = iface_callback_map_iter->second;
-	for (const auto &callback : iface_callback_list) {
-		method(callback);
-	}
+/**
+ * Helper fucntion to invoke the provided callback method on all the
+ * registered iface callback hidl objects for the specified
+ * |ifname|.
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param method Pointer to the required hidl method from
+ * |ISupplicantIfaceCallback|.
+ */
+void HidlManager::callWithEachStaIfaceCallback(
+    const std::string &ifname,
+    const std::function<Return<void>(android::sp<ISupplicantStaIfaceCallback>)>
+	&method)
+{
+	callWithEachIfaceCallback(ifname, method, sta_iface_callbacks_map_);
 }
 
 /**
  * Helper function to invoke the provided callback method on all the
- * registered |ISupplicantNetworkCallback| callback hidl objects for the
- * specified
+ * registered network callback hidl objects for the specified
  * |ifname| & |network_id|.
  *
  * @param ifname Name of the corresponding interface.
  * @param network_id ID of the corresponding network.
  * @param method Pointer to the required hidl method from
- * |ISupplicantNetworkCallback|.
+ * |ISupplicantP2pNetworkCallback| or |ISupplicantStaNetworkCallback| .
  */
-void HidlManager::callWithEachNetworkCallback(
+void HidlManager::callWithEachP2pNetworkCallback(
     const std::string &ifname, int network_id,
-    const std::function<Return<void>(android::sp<ISupplicantNetworkCallback>)>
-	&method)
+    const std::function<
+	Return<void>(android::sp<ISupplicantP2pNetworkCallback>)> &method)
 {
-	if (ifname.empty() || network_id < 0)
-		return;
-
-	// Generate the key to be used to lookup the network.
-	const std::string network_key =
-	    getNetworkObjectMapKey(ifname, network_id);
-	auto network_callback_map_iter =
-	    network_callbacks_map_.find(network_key);
-	if (network_callback_map_iter == network_callbacks_map_.end())
-		return;
-	const auto &network_callback_list = network_callback_map_iter->second;
-	for (const auto &callback : network_callback_list) {
-		method(callback);
-	}
+	callWithEachNetworkCallback(
+	    ifname, network_id, method, p2p_network_callbacks_map_);
 }
 
+/**
+ * Helper function to invoke the provided callback method on all the
+ * registered network callback hidl objects for the specified
+ * |ifname| & |network_id|.
+ *
+ * @param ifname Name of the corresponding interface.
+ * @param network_id ID of the corresponding network.
+ * @param method Pointer to the required hidl method from
+ * |ISupplicantP2pNetworkCallback| or |ISupplicantStaNetworkCallback| .
+ */
+void HidlManager::callWithEachStaNetworkCallback(
+    const std::string &ifname, int network_id,
+    const std::function<
+	Return<void>(android::sp<ISupplicantStaNetworkCallback>)> &method)
+{
+	callWithEachNetworkCallback(
+	    ifname, network_id, method, sta_network_callbacks_map_);
+}
 }  // namespace implementation
 }  // namespace V1_0
 }  // namespace wifi
diff --git a/wpa_supplicant/hidl/hidl_manager.h b/wpa_supplicant/hidl/hidl_manager.h
index c044fcf..0678b10 100644
--- a/wpa_supplicant/hidl/hidl_manager.h
+++ b/wpa_supplicant/hidl/hidl_manager.h
@@ -14,15 +14,23 @@
 #include <string>
 
 #include <android/hardware/wifi/supplicant/1.0/ISupplicantCallback.h>
-#include <android/hardware/wifi/supplicant/1.0/ISupplicantIfaceCallback.h>
-#include <android/hardware/wifi/supplicant/1.0/ISupplicantNetworkCallback.h>
+#include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.h>
+#include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetworkCallback.h>
+#include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.h>
+#include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h>
 
-#include "iface.h"
-#include "network.h"
+#include "p2p_iface.h"
+#include "p2p_network.h"
+#include "sta_iface.h"
+#include "sta_network.h"
 #include "supplicant.h"
 
-struct wpa_global;
-struct wpa_supplicant;
+extern "C" {
+#include "utils/common.h"
+#include "utils/includes.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
+}
 
 namespace android {
 namespace hardware {
@@ -57,28 +65,32 @@
 	    const char *param);
 
 	// Methods called from hidl objects.
-	int getIfaceHidlObjectByIfname(
+	int getP2pIfaceHidlObjectByIfname(
 	    const std::string &ifname,
-	    android::sp<
-		android::hardware::wifi::supplicant::V1_0::ISupplicantIface>
-		*iface_object);
-	int getNetworkHidlObjectByIfnameAndNetworkId(
+	    android::sp<ISupplicantP2pIface> *iface_object);
+	int getStaIfaceHidlObjectByIfname(
+	    const std::string &ifname,
+	    android::sp<ISupplicantStaIface> *iface_object);
+	int getP2pNetworkHidlObjectByIfnameAndNetworkId(
 	    const std::string &ifname, int network_id,
-	    android::sp<
-		android::hardware::wifi::supplicant::V1_0::ISupplicantNetwork>
-		*network_object);
+	    android::sp<ISupplicantP2pNetwork> *network_object);
+	int getStaNetworkHidlObjectByIfnameAndNetworkId(
+	    const std::string &ifname, int network_id,
+	    android::sp<ISupplicantStaNetwork> *network_object);
 	int addSupplicantCallbackHidlObject(
-	    const android::sp<
-		android::hardware::wifi::supplicant::V1_0::ISupplicantCallback>
-		&callback);
-	int addIfaceCallbackHidlObject(
+	    const android::sp<ISupplicantCallback> &callback);
+	int addP2pIfaceCallbackHidlObject(
 	    const std::string &ifname,
-	    const android::sp<android::hardware::wifi::supplicant::V1_0::
-				  ISupplicantIfaceCallback> &callback);
-	int addNetworkCallbackHidlObject(
+	    const android::sp<ISupplicantP2pIfaceCallback> &callback);
+	int addStaIfaceCallbackHidlObject(
+	    const std::string &ifname,
+	    const android::sp<ISupplicantStaIfaceCallback> &callback);
+	int addP2pNetworkCallbackHidlObject(
 	    const std::string &ifname, int network_id,
-	    const android::sp<android::hardware::wifi::supplicant::V1_0::
-				  ISupplicantNetworkCallback> &callback);
+	    const android::sp<ISupplicantP2pNetworkCallback> &callback);
+	int addStaNetworkCallbackHidlObject(
+	    const std::string &ifname, int network_id,
+	    const android::sp<ISupplicantStaNetworkCallback> &callback);
 
 private:
 	HidlManager() = default;
@@ -86,42 +98,40 @@
 	HidlManager(const HidlManager &) = default;
 	HidlManager &operator=(const HidlManager &) = default;
 
-	const std::string getNetworkObjectMapKey(
-	    const std::string &ifname, int network_id);
-
 	void removeSupplicantCallbackHidlObject(
-	    const android::sp<
-		android::hardware::wifi::supplicant::V1_0::ISupplicantCallback>
-		&callback);
-	void removeIfaceCallbackHidlObject(
+	    const android::sp<ISupplicantCallback> &callback);
+	void removeP2pIfaceCallbackHidlObject(
 	    const std::string &ifname,
-	    const android::sp<android::hardware::wifi::supplicant::V1_0::
-				  ISupplicantIfaceCallback> &callback);
-	void removeNetworkCallbackHidlObject(
+	    const android::sp<ISupplicantP2pIfaceCallback> &callback);
+	void removeStaIfaceCallbackHidlObject(
+	    const std::string &ifname,
+	    const android::sp<ISupplicantStaIfaceCallback> &callback);
+	void removeP2pNetworkCallbackHidlObject(
 	    const std::string &ifname, int network_id,
-	    const android::sp<android::hardware::wifi::supplicant::V1_0::
-				  ISupplicantNetworkCallback> &callback);
-	template <class CallbackType>
-	int registerForDeathAndAddCallbackHidlObjectToList(
-	    const android::sp<CallbackType> &callback,
-	    const std::function<void(const android::sp<CallbackType> &)>
-		&on_hidl_died_fctor,
-	    std::vector<android::sp<CallbackType>> &callback_list);
+	    const android::sp<ISupplicantP2pNetworkCallback> &callback);
+	void removeStaNetworkCallbackHidlObject(
+	    const std::string &ifname, int network_id,
+	    const android::sp<ISupplicantStaNetworkCallback> &callback);
 
 	void callWithEachSupplicantCallback(
 	    const std::function<android::hardware::Return<void>(
-		android::sp<android::hardware::wifi::supplicant::V1_0::
-				ISupplicantCallback>)> &method);
-	void callWithEachIfaceCallback(
+		android::sp<ISupplicantCallback>)> &method);
+	void callWithEachP2pIfaceCallback(
 	    const std::string &ifname,
 	    const std::function<android::hardware::Return<void>(
-		android::sp<android::hardware::wifi::supplicant::V1_0::
-				ISupplicantIfaceCallback>)> &method);
-	void callWithEachNetworkCallback(
+		android::sp<ISupplicantP2pIfaceCallback>)> &method);
+	void callWithEachStaIfaceCallback(
+	    const std::string &ifname,
+	    const std::function<android::hardware::Return<void>(
+		android::sp<ISupplicantStaIfaceCallback>)> &method);
+	void callWithEachP2pNetworkCallback(
 	    const std::string &ifname, int network_id,
 	    const std::function<android::hardware::Return<void>(
-		android::sp<android::hardware::wifi::supplicant::V1_0::
-				ISupplicantNetworkCallback>)> &method);
+		android::sp<ISupplicantP2pNetworkCallback>)> &method);
+	void callWithEachStaNetworkCallback(
+	    const std::string &ifname, int network_id,
+	    const std::function<android::hardware::Return<void>(
+		android::sp<ISupplicantStaNetworkCallback>)> &method);
 
 	// HIDL Service name.
 	static const char kServiceName[];
@@ -129,35 +139,57 @@
 	static HidlManager *instance_;
 	// The main hidl service object.
 	android::sp<Supplicant> supplicant_object_;
-	// Map of all the interface specific hidl objects controlled by
+	// Map of all the P2P interface specific hidl objects controlled by
 	// wpa_supplicant. This map is keyed in by the corresponding
 	// |ifname|.
-	std::map<const std::string, android::sp<Iface>> iface_object_map_;
-	// Map of all the network specific hidl objects controlled by
+	std::map<const std::string, android::sp<P2pIface>>
+	    p2p_iface_object_map_;
+	// Map of all the STA interface specific hidl objects controlled by
+	// wpa_supplicant. This map is keyed in by the corresponding
+	// |ifname|.
+	std::map<const std::string, android::sp<StaIface>>
+	    sta_iface_object_map_;
+	// Map of all the P2P network specific hidl objects controlled by
 	// wpa_supplicant. This map is keyed in by the corresponding
 	// |ifname| & |network_id|.
-	std::map<const std::string, android::sp<Network>> network_object_map_;
+	std::map<const std::string, android::sp<P2pNetwork>>
+	    p2p_network_object_map_;
+	// Map of all the STA network specific hidl objects controlled by
+	// wpa_supplicant. This map is keyed in by the corresponding
+	// |ifname| & |network_id|.
+	std::map<const std::string, android::sp<StaNetwork>>
+	    sta_network_object_map_;
 
 	// Callback registered for the main hidl service object.
-	std::vector<android::sp<
-	    android::hardware::wifi::supplicant::V1_0::ISupplicantCallback>>
-	    supplicant_callbacks_;
-	// Map of all the callbacks registered for interface specific
+	std::vector<android::sp<ISupplicantCallback>> supplicant_callbacks_;
+	// Map of all the callbacks registered for P2P interface specific
 	// hidl objects controlled by wpa_supplicant.  This map is keyed in by
 	// the corresponding |ifname|.
 	std::map<
 	    const std::string,
-	    std::vector<android::sp<android::hardware::wifi::supplicant::V1_0::
-					ISupplicantIfaceCallback>>>
-	    iface_callbacks_map_;
-	// Map of all the callbacks registered for network specific
+	    std::vector<android::sp<ISupplicantP2pIfaceCallback>>>
+	    p2p_iface_callbacks_map_;
+	// Map of all the callbacks registered for STA interface specific
+	// hidl objects controlled by wpa_supplicant.  This map is keyed in by
+	// the corresponding |ifname|.
+	std::map<
+	    const std::string,
+	    std::vector<android::sp<ISupplicantStaIfaceCallback>>>
+	    sta_iface_callbacks_map_;
+	// Map of all the callbacks registered for P2P network specific
 	// hidl objects controlled by wpa_supplicant.  This map is keyed in by
 	// the corresponding |ifname| & |network_id|.
 	std::map<
 	    const std::string,
-	    std::vector<android::sp<android::hardware::wifi::supplicant::V1_0::
-					ISupplicantNetworkCallback>>>
-	    network_callbacks_map_;
+	    std::vector<android::sp<ISupplicantP2pNetworkCallback>>>
+	    p2p_network_callbacks_map_;
+	// Map of all the callbacks registered for STA network specific
+	// hidl objects controlled by wpa_supplicant.  This map is keyed in by
+	// the corresponding |ifname| & |network_id|.
+	std::map<
+	    const std::string,
+	    std::vector<android::sp<ISupplicantStaNetworkCallback>>>
+	    sta_network_callbacks_map_;
 
 	/**
 	 * Helper class used to deregister the callback object reference from