Add an explicit TWT register events call

Bug: 297481123
Test: m
Change-Id: Ib1644e391df30fa4b846b7e37d3aed6b15a85e67
This commit is contained in:
Mahesh KKV 2024-02-05 12:00:23 -08:00
parent 21999ff48c
commit 6e37b45fd1
5 changed files with 172 additions and 143 deletions

View file

@ -1867,9 +1867,8 @@ std::pair<wifi_twt_capabilities, wifi_error> WifiLegacyHal::twtGetCapabilities(
return {capabs, status};
}
wifi_error WifiLegacyHal::twtSessionSetup(
const std::string& ifaceName, uint32_t cmdId, const wifi_twt_request& request,
const on_twt_failure& on_twt_failure_user_callback,
wifi_error WifiLegacyHal::twtRegisterEvents(
const std::string& ifaceName, const on_twt_failure& on_twt_failure_user_callback,
const on_twt_session_create& on_twt_session_create_user_callback,
const on_twt_session_update& on_twt_session_update_user_callback,
const on_twt_session_teardown& on_twt_session_teardown_user_callback,
@ -1921,13 +1920,18 @@ wifi_error WifiLegacyHal::twtSessionSetup(
on_twt_session_resume_user_callback(id, session_id);
};
return global_func_table_.wifi_twt_session_setup(
cmdId, getIfaceHandle(ifaceName), request,
return global_func_table_.wifi_twt_register_events(
getIfaceHandle(ifaceName),
{onAsyncTwtError, onAsyncTwtSessionCreate, onAsyncTwtSessionUpdate,
onAsyncTwtSessionTeardown, onAsyncTwtSessionStats, onAsyncTwtSessionSuspend,
onAsyncTwtSessionResume});
}
wifi_error WifiLegacyHal::twtSessionSetup(const std::string& ifaceName, uint32_t cmdId,
const wifi_twt_request& request) {
return global_func_table_.wifi_twt_session_setup(cmdId, getIfaceHandle(ifaceName), request);
}
wifi_error WifiLegacyHal::twtSessionUpdate(const std::string& ifaceName, uint32_t cmdId,
uint32_t sessionId, const wifi_twt_request& request) {
return global_func_table_.wifi_twt_session_update(cmdId, getIfaceHandle(ifaceName), sessionId,

View file

@ -780,15 +780,16 @@ class WifiLegacyHal {
// TWT functions
std::pair<wifi_twt_capabilities, wifi_error> twtGetCapabilities(const std::string& ifaceName);
wifi_error twtRegisterEvents(
const std::string& ifaceName, const on_twt_failure& on_twt_failure_user_callback,
const on_twt_session_create& on_twt_session_create_user_callback,
const on_twt_session_update& on_twt_session_update_user_callback,
const on_twt_session_teardown& on_twt_session_teardown_user_callback,
const on_twt_session_stats& on_twt_session_stats_user_callback,
const on_twt_session_suspend& on_twt_session_suspend_user_callback,
const on_twt_session_resume& on_twt_session_resume_user_callback);
wifi_error twtSessionSetup(const std::string& ifaceName, uint32_t cmdId,
const wifi_twt_request& request,
const on_twt_failure& on_twt_failure_user_callback,
const on_twt_session_create& on_twt_session_create_user_callback,
const on_twt_session_update& on_twt_session_update_user_callback,
const on_twt_session_teardown& on_twt_session_teardown_user_callback,
const on_twt_session_stats& on_twt_session_stats_user_callback,
const on_twt_session_suspend& on_twt_session_suspend_user_callback,
const on_twt_session_resume& on_twt_session_resume_user_callback);
const wifi_twt_request& request);
wifi_error twtSessionUpdate(const std::string& ifaceName, uint32_t cmdId, uint32_t sessionId,
const wifi_twt_request& request);
wifi_error twtSessionSuspend(const std::string& ifaceName, uint32_t cmdId, uint32_t sessionId);
@ -797,7 +798,7 @@ class WifiLegacyHal {
wifi_error twtSessionGetStats(const std::string& ifaceName, uint32_t cmdId, uint32_t sessionId);
// Note: Following TWT functions are deprecated
// Deprecated
// Deprecated by twtRegisterEvegnts
wifi_error twtRegisterHandler(const std::string& iface_name,
const TwtCallbackHandlers& handler);
// Deprecated by twtGetCapabilities

View file

@ -182,6 +182,7 @@ bool initHalFuncTableWithStubs(wifi_hal_fn* hal_fn) {
populateStubFor(&hal_fn->wifi_get_rtt_capabilities_v3);
populateStubFor(&hal_fn->wifi_rtt_range_request_v3);
populateStubFor(&hal_fn->wifi_twt_get_capabilities);
populateStubFor(&hal_fn->wifi_twt_register_events);
populateStubFor(&hal_fn->wifi_twt_session_setup);
populateStubFor(&hal_fn->wifi_twt_session_update);
populateStubFor(&hal_fn->wifi_twt_session_suspend);

View file

@ -31,7 +31,11 @@ using aidl_return_util::validateAndCall;
WifiStaIface::WifiStaIface(const std::string& ifname,
const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util)
: ifname_(ifname), legacy_hal_(legacy_hal), iface_util_(iface_util), is_valid_(true) {
: ifname_(ifname),
legacy_hal_(legacy_hal),
iface_util_(iface_util),
is_valid_(true),
is_twt_registered_(false) {
// Turn on DFS channel usage for STA iface.
legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->setDfsFlag(ifname_, true);
if (legacy_status != legacy_hal::WIFI_SUCCESS) {
@ -266,11 +270,150 @@ std::pair<std::string, ndk::ScopedAStatus> WifiStaIface::getNameInternal() {
return {ifname_, ndk::ScopedAStatus::ok()};
}
ndk::ScopedAStatus WifiStaIface::registerTwtEventCallbackInternal() {
std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
// onTwtFailure callback
const auto& on_twt_failure = [weak_ptr_this](legacy_hal::wifi_request_id id,
legacy_hal::wifi_twt_error_code error_code) {
const auto shared_ptr_this = weak_ptr_this.lock();
IWifiStaIfaceEventCallback::TwtErrorCode aidl_error_code =
aidl_struct_util::convertLegacyHalTwtErrorCodeToAidl(error_code);
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtFailure(id, aidl_error_code).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtFailure callback";
}
}
};
// onTwtSessionCreate callback
const auto& on_twt_session_create = [weak_ptr_this](legacy_hal::wifi_request_id id,
legacy_hal::wifi_twt_session twt_session) {
const auto shared_ptr_this = weak_ptr_this.lock();
TwtSession aidl_twt_session;
if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
return;
}
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionCreate(id, aidl_twt_session).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionCreate callback";
}
}
};
// onTwtSessionUpdate callback
const auto& on_twt_session_update = [weak_ptr_this](legacy_hal::wifi_request_id id,
legacy_hal::wifi_twt_session twt_session) {
const auto shared_ptr_this = weak_ptr_this.lock();
TwtSession aidl_twt_session;
if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
return;
}
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionUpdate(id, aidl_twt_session).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionUpdate callback";
}
}
};
// onTwtSessionTeardown callback
const auto& on_twt_session_teardown =
[weak_ptr_this](legacy_hal::wifi_request_id id, int session_id,
legacy_hal::wifi_twt_teardown_reason_code reason_code) {
const auto shared_ptr_this = weak_ptr_this.lock();
IWifiStaIfaceEventCallback::TwtTeardownReasonCode aidl_reason_code =
aidl_struct_util::convertLegacyHalTwtReasonCodeToAidl(reason_code);
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionTeardown(id, session_id, aidl_reason_code).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionTeardown callback";
}
}
};
// onTwtSessionStats callback
const auto& on_twt_session_stats = [weak_ptr_this](legacy_hal::wifi_request_id id,
int session_id,
legacy_hal::wifi_twt_session_stats stats) {
const auto shared_ptr_this = weak_ptr_this.lock();
TwtSessionStats aidl_session_stats;
if (!aidl_struct_util::convertLegacyHalTwtSessionStatsToAidl(stats, &aidl_session_stats)) {
LOG(ERROR) << "convertLegacyHalTwtSessionStatsToAidl failed";
return;
}
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionStats(id, session_id, aidl_session_stats).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionStats callback";
}
}
};
// onTwtSessionSuspend callback
const auto& on_twt_session_suspend = [weak_ptr_this](legacy_hal::wifi_request_id id,
int session_id) {
const auto shared_ptr_this = weak_ptr_this.lock();
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionSuspend(id, session_id).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionSuspend callback";
}
}
};
// onTwtSessionResume callback
const auto& on_twt_session_resume = [weak_ptr_this](legacy_hal::wifi_request_id id,
int session_id) {
const auto shared_ptr_this = weak_ptr_this.lock();
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionResume(id, session_id).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionResume callback";
}
}
};
legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->twtRegisterEvents(
ifname_, on_twt_failure, on_twt_session_create, on_twt_session_update,
on_twt_session_teardown, on_twt_session_stats, on_twt_session_suspend,
on_twt_session_resume);
if (legacy_status == legacy_hal::WIFI_ERROR_NOT_SUPPORTED) {
LOG(INFO) << "twtRegisterEvents is not supported" << legacy_status;
} else if (legacy_status != legacy_hal::WIFI_SUCCESS) {
LOG(ERROR) << "twtRegisterEvents failed - %d" << legacy_status;
}
return createWifiStatusFromLegacyError(legacy_status);
}
ndk::ScopedAStatus WifiStaIface::registerEventCallbackInternal(
const std::shared_ptr<IWifiStaIfaceEventCallback>& callback) {
if (!event_cb_handler_.addCallback(callback)) {
return createWifiStatus(WifiStatusCode::ERROR_UNKNOWN);
}
is_twt_registered_ = registerTwtEventCallbackInternal().isOk();
return ndk::ScopedAStatus::ok();
}
@ -617,138 +760,16 @@ std::pair<TwtCapabilities, ndk::ScopedAStatus> WifiStaIface::twtGetCapabilitiesI
ndk::ScopedAStatus WifiStaIface::twtSessionSetupInternal(int32_t cmdId,
const TwtRequest& aidlTwtRequest) {
if (!is_twt_registered_) {
LOG(INFO) << "twtSessionSetup is not supported as twtRegisterEvents failed";
return createWifiStatus(WifiStatusCode::ERROR_NOT_SUPPORTED);
}
legacy_hal::wifi_twt_request legacyHalTwtRequest;
if (!aidl_struct_util::convertAidlTwtRequestToLegacy(aidlTwtRequest, &legacyHalTwtRequest)) {
return createWifiStatus(WifiStatusCode::ERROR_INVALID_ARGS);
}
std::weak_ptr<WifiStaIface> weak_ptr_this = weak_ptr_this_;
// onTwtFailure callback
const auto& on_twt_failure = [weak_ptr_this](legacy_hal::wifi_request_id id,
legacy_hal::wifi_twt_error_code error_code) {
const auto shared_ptr_this = weak_ptr_this.lock();
IWifiStaIfaceEventCallback::TwtErrorCode aidl_error_code =
aidl_struct_util::convertLegacyHalTwtErrorCodeToAidl(error_code);
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtFailure(id, aidl_error_code).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtFailure callback";
}
}
};
// onTwtSessionCreate callback
const auto& on_twt_session_create = [weak_ptr_this](legacy_hal::wifi_request_id id,
legacy_hal::wifi_twt_session twt_session) {
const auto shared_ptr_this = weak_ptr_this.lock();
TwtSession aidl_twt_session;
if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
return;
}
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionCreate(id, aidl_twt_session).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionCreate callback";
}
}
};
// onTwtSessionUpdate callback
const auto& on_twt_session_update = [weak_ptr_this](legacy_hal::wifi_request_id id,
legacy_hal::wifi_twt_session twt_session) {
const auto shared_ptr_this = weak_ptr_this.lock();
TwtSession aidl_twt_session;
if (!aidl_struct_util::convertLegacyHalTwtSessionToAidl(twt_session, &aidl_twt_session)) {
LOG(ERROR) << "convertLegacyHalTwtSessionToAidl failed";
return;
}
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionUpdate(id, aidl_twt_session).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionUpdate callback";
}
}
};
// onTwtSessionTeardown callback
const auto& on_twt_session_teardown =
[weak_ptr_this](legacy_hal::wifi_request_id id, int session_id,
legacy_hal::wifi_twt_teardown_reason_code reason_code) {
const auto shared_ptr_this = weak_ptr_this.lock();
IWifiStaIfaceEventCallback::TwtTeardownReasonCode aidl_reason_code =
aidl_struct_util::convertLegacyHalTwtReasonCodeToAidl(reason_code);
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionTeardown(id, session_id, aidl_reason_code).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionTeardown callback";
}
}
};
// onTwtSessionStats callback
const auto& on_twt_session_stats = [weak_ptr_this](legacy_hal::wifi_request_id id,
int session_id,
legacy_hal::wifi_twt_session_stats stats) {
const auto shared_ptr_this = weak_ptr_this.lock();
TwtSessionStats aidl_session_stats;
if (!aidl_struct_util::convertLegacyHalTwtSessionStatsToAidl(stats, &aidl_session_stats)) {
LOG(ERROR) << "convertLegacyHalTwtSessionStatsToAidl failed";
return;
}
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionStats(id, session_id, aidl_session_stats).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionStats callback";
}
}
};
// onTwtSessionSuspend callback
const auto& on_twt_session_suspend = [weak_ptr_this](legacy_hal::wifi_request_id id,
int session_id) {
const auto shared_ptr_this = weak_ptr_this.lock();
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionSuspend(id, session_id).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionSuspend callback";
}
}
};
// onTwtSessionResume callback
const auto& on_twt_session_resume = [weak_ptr_this](legacy_hal::wifi_request_id id,
int session_id) {
const auto shared_ptr_this = weak_ptr_this.lock();
if (!shared_ptr_this.get() || !shared_ptr_this->isValid()) {
LOG(ERROR) << "Callback invoked on an invalid object";
return;
}
for (const auto& callback : shared_ptr_this->getEventCallbacks()) {
if (!callback->onTwtSessionResume(id, session_id).isOk()) {
LOG(ERROR) << "Failed to invoke onTwtSessionResume callback";
}
}
};
legacy_hal::wifi_error legacy_status = legacy_hal_.lock()->twtSessionSetup(
ifname_, cmdId, legacyHalTwtRequest, on_twt_failure, on_twt_session_create,
on_twt_session_update, on_twt_session_teardown, on_twt_session_stats,
on_twt_session_suspend, on_twt_session_resume);
legacy_hal::wifi_error legacy_status =
legacy_hal_.lock()->twtSessionSetup(ifname_, cmdId, legacyHalTwtRequest);
return createWifiStatusFromLegacyError(legacy_status);
}

View file

@ -103,6 +103,7 @@ class WifiStaIface : public BnWifiStaIface {
private:
// Corresponding worker functions for the AIDL methods.
std::pair<std::string, ndk::ScopedAStatus> getNameInternal();
ndk::ScopedAStatus registerTwtEventCallbackInternal();
ndk::ScopedAStatus registerEventCallbackInternal(
const std::shared_ptr<IWifiStaIfaceEventCallback>& callback);
std::pair<int32_t, ndk::ScopedAStatus> getFeatureSetInternal();
@ -157,6 +158,7 @@ class WifiStaIface : public BnWifiStaIface {
std::weak_ptr<WifiStaIface> weak_ptr_this_;
bool is_valid_;
aidl_callback_util::AidlCallbackHandler<IWifiStaIfaceEventCallback> event_cb_handler_;
bool is_twt_registered_;
DISALLOW_COPY_AND_ASSIGN(WifiStaIface);
};