Return an interface object from addUsdInterface in
the Mainline Supplicant implementation.

Bug: 365585450
Test: m
Change-Id: I2da4ab0344b096f4d7203d5ba4de07a847b95987
diff --git a/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp b/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp
index dd2babe..b557dca 100644
--- a/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp
+++ b/wpa_supplicant/aidl/mainline/mainline_supplicant.cpp
@@ -18,7 +18,8 @@
     wpa_global_ = global;
 }
 
-ndk::ScopedAStatus MainlineSupplicant::addUsdInterface(const std::string& ifaceName) {
+ndk::ScopedAStatus MainlineSupplicant::addUsdInterface(const std::string& ifaceName,
+        std::shared_ptr<IUsdInterface>* _aidl_return) {
     if (ifaceName.empty()) {
         wpa_printf(MSG_ERROR, "Empty iface name provided");
         return createStatus(SupplicantStatusCode::FAILURE_ARGS_INVALID);
@@ -26,6 +27,8 @@
 
     if (active_usd_ifaces_.find(ifaceName) != active_usd_ifaces_.end()) {
         wpa_printf(MSG_INFO, "Interface %s already exists", ifaceName.c_str());
+        std::shared_ptr<IUsdInterface> usdIface = active_usd_ifaces_[ifaceName];
+        _aidl_return = &usdIface;
         return ndk::ScopedAStatus::ok();
     }
 
@@ -46,8 +49,12 @@
         return createStatus(SupplicantStatusCode::FAILURE_UNKNOWN);
     }
 
+    std::shared_ptr<IUsdInterface> usdIface =
+        ndk::SharedRefBase::make<UsdIface>(wpa_global_, ifaceName);
+    active_usd_ifaces_[ifaceName] = usdIface;
+    _aidl_return = &usdIface;
+
     wpa_printf(MSG_INFO, "Interface %s was added successfully", ifaceName.c_str());
-    active_usd_ifaces_.insert(ifaceName);
     return ndk::ScopedAStatus::ok();
 }
 
diff --git a/wpa_supplicant/aidl/mainline/mainline_supplicant.h b/wpa_supplicant/aidl/mainline/mainline_supplicant.h
index 38a355f..d37d099 100644
--- a/wpa_supplicant/aidl/mainline/mainline_supplicant.h
+++ b/wpa_supplicant/aidl/mainline/mainline_supplicant.h
@@ -9,9 +9,12 @@
 #ifndef MAINLINE_SUPPLICANT_IMPL_H
 #define MAINLINE_SUPPLICANT_IMPL_H
 
-#include <set>
+#include <map>
+
+#include "usd_iface.h"
 
 #include <aidl/android/system/wifi/mainline_supplicant/BnMainlineSupplicant.h>
+#include <aidl/android/system/wifi/mainline_supplicant/IUsdInterface.h>
 #include <aidl/android/system/wifi/mainline_supplicant/SupplicantStatusCode.h>
 
 extern "C"
@@ -24,20 +27,22 @@
 }
 
 using ::aidl::android::system::wifi::mainline_supplicant::BnMainlineSupplicant;
+using ::aidl::android::system::wifi::mainline_supplicant::IUsdInterface;
 using ::aidl::android::system::wifi::mainline_supplicant::SupplicantStatusCode;
 
 class MainlineSupplicant : public BnMainlineSupplicant {
     public:
         MainlineSupplicant(struct wpa_global* global);
-        ndk::ScopedAStatus addUsdInterface(const std::string& ifaceName);
+        ndk::ScopedAStatus addUsdInterface(const std::string& ifaceName,
+            std::shared_ptr<IUsdInterface>* _aidl_return);
         ndk::ScopedAStatus removeUsdInterface(const std::string& ifaceName);
         ndk::ScopedAStatus terminate();
 
     private:
         // Raw pointer to the global structure maintained by the core
         struct wpa_global* wpa_global_;
-        // Names of all active USD interfaces
-        std::set<std::string> active_usd_ifaces_;
+        // Map containing all active USD interfaces, mapped by iface name -> object
+        std::map<std::string, std::shared_ptr<IUsdInterface>> active_usd_ifaces_;
 };
 
 #endif  // MAINLINE_SUPPLICANT_IMPL_H