wifi: Split out initialize and start in WifiLegacyHal

We need to separate these because we need to invoke start() after every
firmware mode change (chip reconfigure).

While there,
1. Make InterfaceTool a member of the class.
2. Make the stop() symmetric with start(). i.e interface is set
down on stop immediately instead of waiting for the thread to stop.

Bug: 31997422
Test: Compiles
Change-Id: I202afcc70571188dc076a841249761bc97fcf817
This commit is contained in:
Roshan Pius
2016-11-18 14:07:54 -08:00
parent a26a6e0807
commit 97334114c6
2 changed files with 20 additions and 14 deletions

View File

@@ -18,10 +18,11 @@
#include <android-base/logging.h>
#include <cutils/properties.h>
#include <wifi_system/interface_tool.h>
#include "wifi_legacy_hal.h"
using android::wifi_system::InterfaceTool;
namespace android {
namespace hardware {
namespace wifi {
@@ -241,12 +242,7 @@ WifiLegacyHal::WifiLegacyHal()
wlan_interface_handle_(nullptr),
awaiting_event_loop_termination_(false) {}
wifi_error WifiLegacyHal::start() {
// Ensure that we're starting in a good state.
CHECK(!global_handle_ && !wlan_interface_handle_ &&
!awaiting_event_loop_termination_);
android::wifi_system::InterfaceTool if_tool;
wifi_error WifiLegacyHal::initialize() {
// TODO: Add back the HAL Tool if we need to. All we need from the HAL tool
// for now is this function call which we can directly call.
wifi_error status = init_wifi_vendor_hal_func_table(&global_func_table_);
@@ -254,13 +250,19 @@ wifi_error WifiLegacyHal::start() {
LOG(ERROR) << "Failed to initialize legacy hal function table";
return WIFI_ERROR_UNKNOWN;
}
if (!if_tool.SetWifiUpState(true)) {
return WIFI_SUCCESS;
}
wifi_error WifiLegacyHal::start() {
// Ensure that we're starting in a good state.
CHECK(global_func_table_.wifi_initialize && !global_handle_ &&
!wlan_interface_handle_ && !awaiting_event_loop_termination_);
if (!iface_tool_.SetWifiUpState(true)) {
LOG(ERROR) << "Failed to set WiFi interface up";
return WIFI_ERROR_UNKNOWN;
}
LOG(INFO) << "Starting legacy HAL";
status = global_func_table_.wifi_initialize(&global_handle_);
wifi_error status = global_func_table_.wifi_initialize(&global_handle_);
if (status != WIFI_SUCCESS || !global_handle_) {
LOG(ERROR) << "Failed to retrieve global handle";
return status;
@@ -280,10 +282,11 @@ wifi_error WifiLegacyHal::stop(
LOG(INFO) << "Stopping legacy HAL";
on_stop_complete_internal_callback = [&](wifi_handle handle) {
CHECK_EQ(global_handle_, handle) << "Handle mismatch";
on_stop_complete_user_callback();
// Invalidate all the internal pointers now that the HAL is
// stopped.
invalidate();
iface_tool_.SetWifiUpState(false);
on_stop_complete_user_callback();
};
awaiting_event_loop_termination_ = true;
global_func_table_.wifi_cleanup(global_handle_, onStopComplete);
@@ -974,8 +977,6 @@ void WifiLegacyHal::runEventLoop() {
}
LOG(VERBOSE) << "Legacy HAL event loop terminated";
awaiting_event_loop_termination_ = false;
android::wifi_system::InterfaceTool if_tool;
if_tool.SetWifiUpState(false);
}
std::pair<wifi_error, std::vector<wifi_cached_scan_results>>

View File

@@ -21,6 +21,8 @@
#include <thread>
#include <vector>
#include <wifi_system/interface_tool.h>
namespace android {
namespace hardware {
namespace wifi {
@@ -125,7 +127,9 @@ class WifiLegacyHal {
std::string getP2pIfaceName();
std::string getStaIfaceName();
// Initialize the legacy HAL and start the event looper thread.
// Initialize the legacy HAL function table.
wifi_error initialize();
// Start the legacy HAL and the event looper thread.
wifi_error start();
// Deinitialize the legacy HAL and stop the event looper thread.
wifi_error stop(const std::function<void()>& on_complete_callback);
@@ -245,6 +249,7 @@ class WifiLegacyHal {
wifi_interface_handle wlan_interface_handle_;
// Flag to indicate if we have initiated the cleanup of legacy HAL.
bool awaiting_event_loop_termination_;
wifi_system::InterfaceTool iface_tool_;
};
} // namespace legacy_hal