Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9cf44590 authored by Isaac Chiou's avatar Isaac Chiou
Browse files

Add HAL APIs for WiFi CHRE NAN RTT

1. Add new APIs to enable/disable CHRE NAN RTT
2. Add a new API to register callback.
   This callback should report events from WLAN driver for CHRE.

Test: New APIs work fine
Bug: 206614765
Change-Id: I8c8ab002064a9556be2e7d3972703bb3255a3a41
parent 16a78e63
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <set>

#include <hidl/HidlSupport.h>
#include <hidl/HidlTransportSupport.h>

namespace {
// Type of callback invoked by the death handler.
@@ -68,10 +69,12 @@ class HidlCallbackHandler {
        // (callback proxy's raw pointer) to track the death of individual
        // clients.
        uint64_t cookie = reinterpret_cast<uint64_t>(cb.get());
        if (cb_set_.find(cb) != cb_set_.end()) {
            LOG(WARNING) << "Duplicate death notification registration";
        for (const auto& s : cb_set_) {
            if (interfacesEqual(cb, s)) {
                LOG(ERROR) << "Duplicate death notification registration";
                return true;
            }
        }
        if (!cb->linkToDeath(death_handler_, cookie)) {
            LOG(ERROR) << "Failed to register death notification";
            return false;
+34 −0
Original line number Diff line number Diff line
@@ -357,6 +357,15 @@ void onAsyncTwtEventDeviceNotify(TwtDeviceNotify* event) {
    }
}

// Callback to report current CHRE NAN state
std::function<void(chre_nan_rtt_state)> on_chre_nan_rtt_internal_callback;
void onAsyncChreNanRttState(chre_nan_rtt_state state) {
    const auto lock = hidl_sync_util::acquireGlobalLock();
    if (on_chre_nan_rtt_internal_callback) {
        on_chre_nan_rtt_internal_callback(state);
    }
}

// End of the free-standing "C" style callbacks.

WifiLegacyHal::WifiLegacyHal(const std::weak_ptr<wifi_system::InterfaceTool> iface_tool,
@@ -1551,6 +1560,30 @@ WifiLegacyHal::getSupportedRadioCombinationsMatrix() {
    return {status, radio_combination_matrix_ptr};
}

wifi_error WifiLegacyHal::chreNanRttRequest(const std::string& iface_name, bool enable) {
    if (enable)
        return global_func_table_.wifi_nan_rtt_chre_enable_request(0, getIfaceHandle(iface_name),
                                                                   NULL);
    else
        return global_func_table_.wifi_nan_rtt_chre_disable_request(0, getIfaceHandle(iface_name));
}

wifi_error WifiLegacyHal::chreRegisterHandler(const std::string& iface_name,
                                              const ChreCallbackHandlers& handler) {
    if (on_chre_nan_rtt_internal_callback) {
        return WIFI_ERROR_NOT_AVAILABLE;
    }

    on_chre_nan_rtt_internal_callback = handler.on_wifi_chre_nan_rtt_state;

    wifi_error status = global_func_table_.wifi_chre_register_handler(getIfaceHandle(iface_name),
                                                                      {onAsyncChreNanRttState});
    if (status != WIFI_SUCCESS) {
        on_chre_nan_rtt_internal_callback = nullptr;
    }
    return status;
}

void WifiLegacyHal::invalidate() {
    global_handle_ = nullptr;
    iface_name_to_handle_.clear();
@@ -1586,6 +1619,7 @@ void WifiLegacyHal::invalidate() {
    on_twt_event_teardown_completion_callback = nullptr;
    on_twt_event_info_frame_received_callback = nullptr;
    on_twt_event_device_notify_callback = nullptr;
    on_chre_nan_rtt_internal_callback = nullptr;
}

}  // namespace legacy_hal
+13 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ namespace implementation {
namespace legacy_hal {
// Import all the types defined inside the legacy HAL header files into this
// namespace.
using ::chre_nan_rtt_state;
using ::frame_info;
using ::frame_type;
using ::FRAME_TYPE_80211_MGMT;
@@ -458,6 +459,12 @@ struct TwtCallbackHandlers {
    std::function<void(const TwtDeviceNotify&)> on_device_notify;
};

// CHRE response and event callbacks struct.
struct ChreCallbackHandlers {
    // Callback for CHRE NAN RTT
    std::function<void(chre_nan_rtt_state)> on_wifi_chre_nan_rtt_state;
};

/**
 * Class that encapsulates all legacy HAL interactions.
 * This class manages the lifetime of the event loop thread used by legacy HAL.
@@ -670,6 +677,12 @@ class WifiLegacyHal {

    std::pair<wifi_error, wifi_radio_combination_matrix*> getSupportedRadioCombinationsMatrix();

    // CHRE NAN RTT function
    wifi_error chreNanRttRequest(const std::string& iface_name, bool enable);

    wifi_error chreRegisterHandler(const std::string& iface_name,
                                   const ChreCallbackHandlers& handler);

  private:
    // Retrieve interface handles for all the available interfaces.
    wifi_error retrieveIfaceHandles();
+3 −0
Original line number Diff line number Diff line
@@ -163,6 +163,9 @@ bool initHalFuncTableWithStubs(wifi_hal_fn* hal_fn) {
    populateStubFor(&hal_fn->wifi_trigger_subsystem_restart);
    populateStubFor(&hal_fn->wifi_set_indoor_state);
    populateStubFor(&hal_fn->wifi_get_supported_radio_combinations_matrix);
    populateStubFor(&hal_fn->wifi_nan_rtt_chre_enable_request);
    populateStubFor(&hal_fn->wifi_nan_rtt_chre_disable_request);
    populateStubFor(&hal_fn->wifi_chre_register_handler);
    return true;
}
}  // namespace legacy_hal