From bd9f7462c81bf4626e6c9cf44a804c58120201db Mon Sep 17 00:00:00 2001 From: Martin Brabham <optedoblivion@google.com> Date: Mon, 7 Mar 2022 18:03:37 +0000 Subject: [PATCH] Floss: LeRand BTA + BTM Shim API Shuffle the api call and the callback data through. Bug: 219982690 Bug: 219983139 Test: mma -j $(nproc) Test: ./build.py Tag: #floss Change-Id: I9b26e6463fb9ebf4bbe38778708db1294e022050 --- system/bta/dm/bta_dm_act.cc | 18 ++++++++++++++++-- system/bta/dm/bta_dm_api.cc | 14 ++++++++++++++ system/bta/dm/bta_dm_int.h | 1 + system/bta/include/bta_api.h | 13 +++++++++++++ system/main/shim/btm_api.cc | 5 +++++ system/main/shim/btm_api.h | 15 +++++++++++++++ system/test/mock/mock_main_shim_btm_api.cc | 5 +++++ 7 files changed, 69 insertions(+), 2 deletions(-) diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc index 6203c3bbc2b..2ddf9c608b7 100644 --- a/system/bta/dm/bta_dm_act.cc +++ b/system/bta/dm/bta_dm_act.cc @@ -4007,9 +4007,9 @@ void bta_dm_proc_open_evt(tBTA_GATTC_OPEN* p_data) { /******************************************************************************* * - * Function bta_dm_proc_open_evt + * Function bta_dm_clear_event_filter * - * Description process BTA_GATTC_OPEN_EVT in DM. + * Description clears out the event filter. * * Parameters: * @@ -4055,6 +4055,20 @@ void bta_dm_disconnect_all_acls(void) { bluetooth::shim::BTM_DisconnectAllAcls(); } +/******************************************************************************* + * + * Function bta_dm_le_rand + * + * Description Generates a random number from the controller. + * + * Parameters: |cb| Callback to receive the random number. + * + ******************************************************************************/ +void bta_dm_le_rand(LeRandCallback cb) { + VLOG(1) << "bta_dm_le_rand in bta_dm_act"; + bluetooth::shim::BTM_LeRand(cb); +} + /******************************************************************************* * * Function bta_dm_gattc_callback diff --git a/system/bta/dm/bta_dm_api.cc b/system/bta/dm/bta_dm_api.cc index 5e1a8787f78..8ff1257d23a 100644 --- a/system/bta/dm/bta_dm_api.cc +++ b/system/bta/dm/bta_dm_api.cc @@ -684,3 +684,17 @@ void BTA_DmClearEventFilter(void) { APPL_TRACE_API("BTA_DmClearEventFilter"); do_in_main_thread(FROM_HERE, base::Bind(bta_dm_clear_event_filter)); } + +/******************************************************************************* + * + * Function BTA_DmLeRand + * + * Description This function clears the event filter + * + * Returns cb: callback to receive the resulting random number + * + ******************************************************************************/ +void BTA_DmLeRand(LeRandCallback cb) { + APPL_TRACE_API("BTA_DmLeRand"); + do_in_main_thread(FROM_HERE, base::Bind(bta_dm_le_rand, cb)); +} diff --git a/system/bta/dm/bta_dm_int.h b/system/bta/dm/bta_dm_int.h index b428a1c714c..6e69e3a1555 100644 --- a/system/bta/dm/bta_dm_int.h +++ b/system/bta/dm/bta_dm_int.h @@ -548,6 +548,7 @@ extern void bta_dm_clear_event_filter(void); extern void bta_dm_clear_event_mask(void); extern void bta_dm_clear_filter_accept_list(void); extern void bta_dm_disconnect_all_acls(void); +extern void bta_dm_le_rand(LeRandCallback cb); uint8_t bta_dm_search_get_state(); void bta_dm_search_set_state(uint8_t state); diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h index b98c8e4b5aa..a73d4912c29 100644 --- a/system/bta/include/bta_api.h +++ b/system/bta/include/bta_api.h @@ -30,6 +30,7 @@ #include <cstdint> #include <vector> +#include "base/callback.h" #include "bt_target.h" // Must be first to define build configuration #include "osi/include/log.h" #include "stack/include/bt_octets.h" @@ -1205,4 +1206,16 @@ extern void BTA_VendorInit(void); ******************************************************************************/ extern void BTA_DmClearEventFilter(void); +using LeRandCallback = base::Callback<void(uint64_t)>; +/******************************************************************************* + * + * Function BTA_DmLeRand + * + * Description This function clears the event filter + * + * Returns cb: callback to receive the resulting random number + * + ******************************************************************************/ +extern void BTA_DmLeRand(LeRandCallback cb); + #endif /* BTA_API_H */ diff --git a/system/main/shim/btm_api.cc b/system/main/shim/btm_api.cc index 5d513af2aa0..48550641a92 100644 --- a/system/main/shim/btm_api.cc +++ b/system/main/shim/btm_api.cc @@ -1353,3 +1353,8 @@ tBTM_STATUS bluetooth::shim::BTM_DisconnectAllAcls() { } return BTM_SUCCESS; } + +tBTM_STATUS bluetooth::shim::BTM_LeRand(LeRandCallback cb) { + controller_get_interface()->le_rand(cb); + return BTM_SUCCESS; +} diff --git a/system/main/shim/btm_api.h b/system/main/shim/btm_api.h index e8fd228edaa..bd55da0ac2f 100644 --- a/system/main/shim/btm_api.h +++ b/system/main/shim/btm_api.h @@ -16,6 +16,7 @@ #pragma once +#include "base/callback.h" #include "device/include/esco_parameters.h" #include "stack/btm/btm_sec.h" #include "stack/btm/neighbor_inquiry.h" @@ -1854,6 +1855,20 @@ tBTM_STATUS BTM_ClearFilterAcceptList(void); ******************************************************************************/ tBTM_STATUS BTM_DisconnectAllAcls(void); +/******************************************************************************* + * + * Function BTM_LeRand + * + * Description Retrieves a random number from the controller + * + * Parameters cb - The callback to receive the random number + * + * Returns Return btm status + * + ******************************************************************************/ +using LeRandCallback = base::Callback<void(uint64_t)>; +tBTM_STATUS BTM_LeRand(LeRandCallback); + /** * Send remote name request to GD shim Name module */ diff --git a/system/test/mock/mock_main_shim_btm_api.cc b/system/test/mock/mock_main_shim_btm_api.cc index 92f5d7759fb..54efb90ec73 100644 --- a/system/test/mock/mock_main_shim_btm_api.cc +++ b/system/test/mock/mock_main_shim_btm_api.cc @@ -444,3 +444,8 @@ tBTM_STATUS bluetooth::shim::BTM_DisconnectAllAcls() { mock_function_count_map[__func__]++; return BTM_SUCCESS; } + +tBTM_STATUS bluetooth::shim::BTM_LeRand(LeRandCallback cb) { + mock_function_count_map[__func__]++; + return BTM_SUCCESS; +} -- GitLab