From 511cc493e33959b3b5b9e11692e946a54e139de8 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 28 Oct 2016 09:54:26 -0700 Subject: [PATCH] wifi: Changes to WifiLegacy Hal Changes in the CL: a. Removed the usage of wifi_status_util in WifiLegacyHal. The |legacyErrorToString| log will be done in the HIDL object. This is to remove any reference of |WifiStatus| b. Moved the cleanup of function pointers to a separate helper function |invalidate|. c. Moved static constants out of WifiLegacyHal class. Bug: 32505551 Test: Compiles Change-Id: I9dc3900c40cf30de2c0a4376d4de2b08076e2b5f --- wifi/1.0/default/wifi.cpp | 6 ++++-- wifi/1.0/default/wifi_legacy_hal.cpp | 25 ++++++++++++++----------- wifi/1.0/default/wifi_legacy_hal.h | 3 +-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/wifi/1.0/default/wifi.cpp b/wifi/1.0/default/wifi.cpp index 73b921ada7..fd2cb9caeb 100644 --- a/wifi/1.0/default/wifi.cpp +++ b/wifi/1.0/default/wifi.cpp @@ -99,7 +99,8 @@ WifiStatus Wifi::startInternal() { 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 @@ WifiStatus Wifi::stopInternal() { }; 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 5bd2454a99..cb254c3e66 100644 --- a/wifi/1.0/default/wifi_legacy_hal.cpp +++ b/wifi/1.0/default/wifi_legacy_hal.cpp @@ -17,7 +17,6 @@ #include #include "wifi_legacy_hal.h" -#include "wifi_status_util.h" #include #include @@ -25,6 +24,8 @@ #include 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 hardware { 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 @@ wifi_error WifiLegacyHal::stop( 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 WifiLegacyHal::retrieveWlanInterfaceHandle() { 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 @@ wifi_error WifiLegacyHal::retrieveWlanInterfaceHandle() { 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 @@ void WifiLegacyHal::runEventLoop() { 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 21acb92621..d817184570 100644 --- a/wifi/1.0/default/wifi_legacy_hal.h +++ b/wifi/1.0/default/wifi_legacy_hal.h @@ -53,12 +53,11 @@ class WifiLegacyHal { std::pair> 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_;