wifi(implementation): Use real iface names

Currently the HAL shim uses fake names to ensure that each type of
IWifiIface has a unique name. This is not a true reflection of the
network interfaces exposed by the wifi driver. So, change the HIDL shim
to use the corresponding interfaces names.

IWifiStaIface, IWifiApIface & IWifiNanIface all use the same "wlan0"
network interface.
IWifiP2pIface uses the "p2p0" network interface.

In the future, we'll be extending this to create a second IWifiStaIface
or IWifiApIface using "wlan1" network interface.

IWifiRttController does not need to be associated with an iface object.
So, it will just default to using "wlan0" always.
TODO(b/34702983): Need to deprecate the bound iface from the HIDL interface.

Bug: 65671875
Test: Device boots up and connects to wifi networks.
Test: Will send for regression tests.
Change-Id: I33fef1332f2fe2da3f48ee87ef06660844699253
diff --git a/wifi/1.2/default/wifi_chip.cpp b/wifi/1.2/default/wifi_chip.cpp
index 63d17a2..07da1dd 100644
--- a/wifi/1.2/default/wifi_chip.cpp
+++ b/wifi/1.2/default/wifi_chip.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <android-base/logging.h>
+#include <cutils/properties.h>
 
 #include "hidl_return_util.h"
 #include "hidl_struct_util.h"
@@ -41,6 +42,27 @@
     iface.clear();
   }
 }
+
+std::string getWlan0IfaceName() {
+  std::array<char, PROPERTY_VALUE_MAX> buffer;
+  property_get("wifi.interface", buffer.data(), "wlan0");
+  return buffer.data();
+}
+
+/** Not used yet.
+std::string getWlan1IfaceName() {
+  std::array<char, PROPERTY_VALUE_MAX> buffer;
+  property_get("wifi.concurrent.interface", buffer.data(), "wlan1");
+  return buffer.data();
+}
+*/
+
+std::string getP2pIfaceName() {
+  std::array<char, PROPERTY_VALUE_MAX> buffer;
+  property_get("wifi.direct.interface", buffer.data(), "p2p0");
+  return buffer.data();
+}
+
 }  // namepsace
 
 namespace android {
@@ -539,7 +561,7 @@
   if (current_mode_id_ != kApChipModeId || ap_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
   }
-  std::string ifname = legacy_hal_.lock()->getApIfaceName();
+  std::string ifname = getWlan0IfaceName();
   ap_iface_ = new WifiApIface(ifname, legacy_hal_);
   for (const auto& callback : event_cb_handler_.getCallbacks()) {
     if (!callback->onIfaceAdded(IfaceType::AP, ifname).isOk()) {
@@ -554,20 +576,19 @@
   if (!ap_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
   }
-  return {createWifiStatus(WifiStatusCode::SUCCESS),
-          {legacy_hal_.lock()->getApIfaceName()}};
+  return {createWifiStatus(WifiStatusCode::SUCCESS), {getWlan0IfaceName()}};
 }
 
 std::pair<WifiStatus, sp<IWifiApIface>> WifiChip::getApIfaceInternal(
     const std::string& ifname) {
-  if (!ap_iface_.get() || (ifname != legacy_hal_.lock()->getApIfaceName())) {
+  if (!ap_iface_.get() || (ifname != getWlan0IfaceName())) {
     return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
   }
   return {createWifiStatus(WifiStatusCode::SUCCESS), ap_iface_};
 }
 
 WifiStatus WifiChip::removeApIfaceInternal(const std::string& ifname) {
-  if (!ap_iface_.get() || (ifname != legacy_hal_.lock()->getApIfaceName())) {
+  if (!ap_iface_.get() || (ifname != getWlan0IfaceName())) {
     return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
   }
   invalidateAndClear(ap_iface_);
@@ -586,7 +607,7 @@
         p2p_iface_.get()) {
       return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
     }
-    std::string ifname = legacy_hal_.lock()->getNanIfaceName();
+    std::string ifname = getWlan0IfaceName();
     nan_iface_ = new WifiNanIface(ifname, legacy_hal_);
     for (const auto& callback : event_cb_handler_.getCallbacks()) {
       if (!callback->onIfaceAdded(IfaceType::NAN, ifname).isOk()) {
@@ -604,20 +625,19 @@
   if (!nan_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
   }
-  return {createWifiStatus(WifiStatusCode::SUCCESS),
-          {legacy_hal_.lock()->getNanIfaceName()}};
+  return {createWifiStatus(WifiStatusCode::SUCCESS), {getWlan0IfaceName()}};
 }
 
 std::pair<WifiStatus, sp<IWifiNanIface>> WifiChip::getNanIfaceInternal(
     const std::string& ifname) {
-  if (!nan_iface_.get() || (ifname != legacy_hal_.lock()->getNanIfaceName())) {
+  if (!nan_iface_.get() || (ifname != getWlan0IfaceName())) {
     return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
   }
   return {createWifiStatus(WifiStatusCode::SUCCESS), nan_iface_};
 }
 
 WifiStatus WifiChip::removeNanIfaceInternal(const std::string& ifname) {
-  if (!nan_iface_.get() || (ifname != legacy_hal_.lock()->getNanIfaceName())) {
+  if (!nan_iface_.get() || (ifname != getWlan0IfaceName())) {
     return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
   }
   invalidateAndClear(nan_iface_);
@@ -635,7 +655,7 @@
       nan_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
   }
-  std::string ifname = legacy_hal_.lock()->getP2pIfaceName();
+  std::string ifname = getP2pIfaceName();
   p2p_iface_ = new WifiP2pIface(ifname, legacy_hal_);
   for (const auto& callback : event_cb_handler_.getCallbacks()) {
     if (!callback->onIfaceAdded(IfaceType::P2P, ifname).isOk()) {
@@ -650,20 +670,19 @@
   if (!p2p_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
   }
-  return {createWifiStatus(WifiStatusCode::SUCCESS),
-          {legacy_hal_.lock()->getP2pIfaceName()}};
+  return {createWifiStatus(WifiStatusCode::SUCCESS), {getP2pIfaceName()}};
 }
 
 std::pair<WifiStatus, sp<IWifiP2pIface>> WifiChip::getP2pIfaceInternal(
     const std::string& ifname) {
-  if (!p2p_iface_.get() || (ifname != legacy_hal_.lock()->getP2pIfaceName())) {
+  if (!p2p_iface_.get() || (ifname != getP2pIfaceName())) {
     return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
   }
   return {createWifiStatus(WifiStatusCode::SUCCESS), p2p_iface_};
 }
 
 WifiStatus WifiChip::removeP2pIfaceInternal(const std::string& ifname) {
-  if (!p2p_iface_.get() || (ifname != legacy_hal_.lock()->getP2pIfaceName())) {
+  if (!p2p_iface_.get() || (ifname != getP2pIfaceName())) {
     return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
   }
   invalidateAndClear(p2p_iface_);
@@ -679,7 +698,7 @@
   if (current_mode_id_ != kStaChipModeId || sta_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::ERROR_NOT_AVAILABLE), {}};
   }
-  std::string ifname = legacy_hal_.lock()->getStaIfaceName();
+  std::string ifname = getWlan0IfaceName();
   sta_iface_ = new WifiStaIface(ifname, legacy_hal_);
   for (const auto& callback : event_cb_handler_.getCallbacks()) {
     if (!callback->onIfaceAdded(IfaceType::STA, ifname).isOk()) {
@@ -694,20 +713,19 @@
   if (!sta_iface_.get()) {
     return {createWifiStatus(WifiStatusCode::SUCCESS), {}};
   }
-  return {createWifiStatus(WifiStatusCode::SUCCESS),
-          {legacy_hal_.lock()->getStaIfaceName()}};
+  return {createWifiStatus(WifiStatusCode::SUCCESS), {getWlan0IfaceName()}};
 }
 
 std::pair<WifiStatus, sp<IWifiStaIface>> WifiChip::getStaIfaceInternal(
     const std::string& ifname) {
-  if (!sta_iface_.get() || (ifname != legacy_hal_.lock()->getStaIfaceName())) {
+  if (!sta_iface_.get() || (ifname != getWlan0IfaceName())) {
     return {createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS), nullptr};
   }
   return {createWifiStatus(WifiStatusCode::SUCCESS), sta_iface_};
 }
 
 WifiStatus WifiChip::removeStaIfaceInternal(const std::string& ifname) {
-  if (!sta_iface_.get() || (ifname != legacy_hal_.lock()->getStaIfaceName())) {
+  if (!sta_iface_.get() || (ifname != getWlan0IfaceName())) {
     return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
   }
   invalidateAndClear(sta_iface_);
@@ -721,7 +739,8 @@
 
 std::pair<WifiStatus, sp<IWifiRttController>>
 WifiChip::createRttControllerInternal(const sp<IWifiIface>& bound_iface) {
-  sp<WifiRttController> rtt = new WifiRttController(bound_iface, legacy_hal_);
+  sp<WifiRttController> rtt =
+      new WifiRttController(getWlan0IfaceName(), bound_iface, legacy_hal_);
   rtt_controllers_.emplace_back(rtt);
   return {createWifiStatus(WifiStatusCode::SUCCESS), rtt};
 }
diff --git a/wifi/1.2/default/wifi_legacy_hal.cpp b/wifi/1.2/default/wifi_legacy_hal.cpp
index 54d9ca0..d0d285b 100644
--- a/wifi/1.2/default/wifi_legacy_hal.cpp
+++ b/wifi/1.2/default/wifi_legacy_hal.cpp
@@ -18,7 +18,6 @@
 #include <chrono>
 
 #include <android-base/logging.h>
-#include <cutils/properties.h>
 
 #include "hidl_sync_util.h"
 #include "wifi_legacy_hal.h"
@@ -404,30 +403,6 @@
   return WIFI_SUCCESS;
 }
 
-std::string WifiLegacyHal::getApIfaceName() {
-  // Fake name. This interface does not exist in legacy HAL
-  // API's.
-  return "ap0";
-}
-
-std::string WifiLegacyHal::getNanIfaceName() {
-  // Fake name. This interface does not exist in legacy HAL
-  // API's.
-  return "nan0";
-}
-
-std::string WifiLegacyHal::getP2pIfaceName() {
-  std::array<char, PROPERTY_VALUE_MAX> buffer;
-  property_get("wifi.direct.interface", buffer.data(), "p2p0");
-  return buffer.data();
-}
-
-std::string WifiLegacyHal::getStaIfaceName() {
-  std::array<char, PROPERTY_VALUE_MAX> buffer;
-  property_get("wifi.interface", buffer.data(), "wlan0");
-  return buffer.data();
-}
-
 std::pair<wifi_error, std::string> WifiLegacyHal::getDriverVersion() {
   std::array<char, kMaxVersionStringLength> buffer;
   buffer.fill(0);
diff --git a/wifi/1.2/default/wifi_legacy_hal.h b/wifi/1.2/default/wifi_legacy_hal.h
index d7be1ee..d68ff55 100644
--- a/wifi/1.2/default/wifi_legacy_hal.h
+++ b/wifi/1.2/default/wifi_legacy_hal.h
@@ -140,11 +140,6 @@
 class WifiLegacyHal {
  public:
   WifiLegacyHal();
-  // Names to use for the different types of iface.
-  std::string getApIfaceName();
-  std::string getNanIfaceName();
-  std::string getP2pIfaceName();
-  std::string getStaIfaceName();
 
   // Initialize the legacy HAL function table.
   wifi_error initialize();
diff --git a/wifi/1.2/default/wifi_rtt_controller.cpp b/wifi/1.2/default/wifi_rtt_controller.cpp
index 2fab06c..8c3bbe2 100644
--- a/wifi/1.2/default/wifi_rtt_controller.cpp
+++ b/wifi/1.2/default/wifi_rtt_controller.cpp
@@ -29,9 +29,11 @@
 using hidl_return_util::validateAndCall;
 
 WifiRttController::WifiRttController(
+    const std::string& iface_name,
     const sp<IWifiIface>& bound_iface,
     const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal)
-    : bound_iface_(bound_iface), legacy_hal_(legacy_hal), is_valid_(true) {}
+    : ifname_(iface_name), bound_iface_(bound_iface), legacy_hal_(legacy_hal),
+      is_valid_(true) {}
 
 void WifiRttController::invalidate() {
   legacy_hal_.reset();
diff --git a/wifi/1.2/default/wifi_rtt_controller.h b/wifi/1.2/default/wifi_rtt_controller.h
index f1a55da..6611e56 100644
--- a/wifi/1.2/default/wifi_rtt_controller.h
+++ b/wifi/1.2/default/wifi_rtt_controller.h
@@ -35,8 +35,9 @@
  */
 class WifiRttController : public V1_0::IWifiRttController {
  public:
-  WifiRttController(const sp<IWifiIface>& bound_iface,
-                    const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal);
+  WifiRttController(
+      const std::string& iface_name, const sp<IWifiIface>& bound_iface,
+      const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal);
   // Refer to |WifiChip::invalidate()|.
   void invalidate();
   bool isValid();
@@ -88,6 +89,7 @@
                                      const RttResponder& info);
   WifiStatus disableResponderInternal(uint32_t cmd_id);
 
+  std::string ifname_;
   sp<IWifiIface> bound_iface_;
   std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
   std::vector<sp<IWifiRttControllerEventCallback>> event_callbacks_;