wifi: Changes to WifiLegacy Hal am: 511cc493e3 am: d09ad0c3d6 am: 02c759f15b
am: 7c3e764fc7

Change-Id: Iec82f13bd0b1e542e962bac8e1a4dfcb670b2593
diff --git a/wifi/1.0/default/wifi.cpp b/wifi/1.0/default/wifi.cpp
index 73b921a..fd2cb9c 100644
--- a/wifi/1.0/default/wifi.cpp
+++ b/wifi/1.0/default/wifi.cpp
@@ -99,7 +99,8 @@
   LOG(INFO) << "Starting HAL";
   wifi_error legacy_status = legacy_hal_->start();
   if (legacy_status != WIFI_SUCCESS) {
-    LOG(ERROR) << "Failed to start Wifi HAL";
+    LOG(ERROR) << "Failed to start Wifi HAL: "
+               << legacyErrorToString(legacy_status);
     return createWifiStatusFromLegacyError(legacy_status,
                                            "Failed to start HAL");
   }
@@ -139,7 +140,8 @@
   };
   wifi_error legacy_status = legacy_hal_->stop(on_complete_callback_);
   if (legacy_status != WIFI_SUCCESS) {
-    LOG(ERROR) << "Failed to stop Wifi HAL";
+    LOG(ERROR) << "Failed to stop Wifi HAL: "
+               << legacyErrorToString(legacy_status);
     WifiStatus wifi_status =
         createWifiStatusFromLegacyError(legacy_status, "Failed to stop HAL");
     for (const auto& callback : event_callbacks_) {
diff --git a/wifi/1.0/default/wifi_legacy_hal.cpp b/wifi/1.0/default/wifi_legacy_hal.cpp
index 5bd2454..cb254c3 100644
--- a/wifi/1.0/default/wifi_legacy_hal.cpp
+++ b/wifi/1.0/default/wifi_legacy_hal.cpp
@@ -17,7 +17,6 @@
 #include <array>
 
 #include "wifi_legacy_hal.h"
-#include "wifi_status_util.h"
 
 #include <android-base/logging.h>
 #include <cutils/properties.h>
@@ -25,6 +24,8 @@
 #include <wifi_system/interface_tool.h>
 
 namespace {
+static constexpr uint32_t kMaxVersionStringLength = 256;
+
 // Legacy HAL functions accept "C" style function pointers, so use global
 // functions to pass to the legacy HAL function and store the corresponding
 // std::function methods to be invoked.
@@ -58,9 +59,6 @@
 namespace wifi {
 namespace V1_0 {
 namespace implementation {
-
-const uint32_t WifiLegacyHal::kMaxVersionStringLength = 256;
-
 WifiLegacyHal::WifiLegacyHal()
     : global_handle_(nullptr),
       wlan_interface_handle_(nullptr),
@@ -104,9 +102,9 @@
   on_stop_complete_internal_callback = [&](wifi_handle handle) {
     CHECK_EQ(global_handle_, handle) << "Handle mismatch";
     on_stop_complete_user_callback();
-    global_handle_ = nullptr;
-    wlan_interface_handle_ = nullptr;
-    on_stop_complete_internal_callback = nullptr;
+    // Invalidate all the internal pointers now that the HAL is
+    // stopped.
+    invalidate();
   };
   awaiting_event_loop_termination_ = true;
   global_func_table_.wifi_cleanup(global_handle_, onStopComplete);
@@ -191,8 +189,7 @@
   wifi_error status = global_func_table_.wifi_get_ifaces(
       global_handle_, &num_iface_handles, &iface_handles);
   if (status != WIFI_SUCCESS) {
-    LOG(ERROR) << "Failed to enumerate interface handles: "
-               << legacyErrorToString(status);
+    LOG(ERROR) << "Failed to enumerate interface handles";
     return status;
   }
   for (int i = 0; i < num_iface_handles; ++i) {
@@ -201,8 +198,7 @@
     status = global_func_table_.wifi_get_iface_name(
         iface_handles[i], current_ifname.data(), current_ifname.size());
     if (status != WIFI_SUCCESS) {
-      LOG(WARNING) << "Failed to get interface handle name: "
-                   << legacyErrorToString(status);
+      LOG(WARNING) << "Failed to get interface handle name";
       continue;
     }
     if (ifname_to_find == current_ifname.data()) {
@@ -225,6 +221,13 @@
   if_tool.SetWifiUpState(false);
 }
 
+void WifiLegacyHal::invalidate() {
+  global_handle_ = nullptr;
+  wlan_interface_handle_ = nullptr;
+  on_stop_complete_internal_callback = nullptr;
+  on_driver_memory_dump_internal_callback = nullptr;
+  on_firmware_memory_dump_internal_callback = nullptr;
+}
 }  // namespace implementation
 }  // namespace V1_0
 }  // namespace wifi
diff --git a/wifi/1.0/default/wifi_legacy_hal.h b/wifi/1.0/default/wifi_legacy_hal.h
index 21acb92..d817184 100644
--- a/wifi/1.0/default/wifi_legacy_hal.h
+++ b/wifi/1.0/default/wifi_legacy_hal.h
@@ -53,12 +53,11 @@
   std::pair<wifi_error, std::vector<uint8_t>> requestFirmwareMemoryDump();
 
  private:
-  static const uint32_t kMaxVersionStringLength;
-
   // Retrieve the interface handle to be used for the "wlan" interface.
   wifi_error retrieveWlanInterfaceHandle();
   // Run the legacy HAL event loop thread.
   void runEventLoop();
+  void invalidate();
 
   // Event loop thread used by legacy HAL.
   std::thread event_loop_thread_;