From 430f838b455e1d9426835799a6df30131d8f5f3b Mon Sep 17 00:00:00 2001 From: Martin Brabham Date: Thu, 20 Aug 2020 22:08:22 -0700 Subject: [PATCH] BTM_API Shim: Add ShimBondListener Create a new class ShimBondListener that accepts the tBTM_APPL_INFO as a constructor argument. Bug: 159815595 Tag: #gd-refactor Test: cert/run --host SecurityTest Test: atest --host bluetooth_test_gd Test: Manual testing with hybrid stack Change-Id: Ifb524cd7af85dba5f5659112437cb5d6284bb8b6 --- main/shim/btm_api.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 8 deletions(-) diff --git a/main/shim/btm_api.cc b/main/shim/btm_api.cc index 437c0c575..637455bf9 100644 --- a/main/shim/btm_api.cc +++ b/main/shim/btm_api.cc @@ -24,6 +24,7 @@ #include "device/include/controller.h" #include "gd/common/callback.h" #include "gd/neighbor/name.h" +#include "gd/security/security_module.h" #include "main/shim/btm.h" #include "main/shim/btm_api.h" #include "main/shim/controller.h" @@ -230,6 +231,82 @@ void btm_api_process_extended_inquiry_result(RawAddress raw_address, } } +class ShimBondListener : public bluetooth::security::ISecurityManagerListener { + public: + static ShimBondListener* GetInstance() { + static ShimBondListener instance; + return &instance; + } + + ShimBondListener(const ShimBondListener&) = delete; + ShimBondListener& operator=(const ShimBondListener&) = delete; + + void SetBtaCallbacks(const tBTM_APPL_INFO* bta_callbacks) { + bta_callbacks_ = bta_callbacks; + if (bta_callbacks->p_pin_callback == nullptr) { + LOG_INFO("UNIMPLEMENTED %s pin_callback", __func__); + } + + if (bta_callbacks->p_link_key_callback == nullptr) { + LOG_INFO("UNIMPLEMENTED %s link_key_callback", __func__); + } + + if (bta_callbacks->p_auth_complete_callback == nullptr) { + LOG_INFO("UNIMPLEMENTED %s auth_complete_callback", __func__); + } + + if (bta_callbacks->p_bond_cancel_cmpl_callback == nullptr) { + LOG_INFO("UNIMPLEMENTED %s bond_cancel_complete_callback", __func__); + } + + if (bta_callbacks->p_le_callback == nullptr) { + LOG_INFO("UNIMPLEMENTED %s le_callback", __func__); + } + + if (bta_callbacks->p_le_key_callback == nullptr) { + LOG_INFO("UNIMPLEMENTED %s le_key_callback", __func__); + } + } + + void OnDeviceBonded(bluetooth::hci::AddressWithType device) override { + if (bta_callbacks_->p_sp_callback) { + // SP_CBACK (what events?) + // link key notification + // auth complete + } + } + + void OnDeviceUnbonded(bluetooth::hci::AddressWithType device) override { + if (bta_callbacks_->p_sp_callback) { + // SP_CBACK (what events?) + // link key notification + // auth complete + } + } + + void OnDeviceBondFailed(bluetooth::hci::AddressWithType device) override { + if (bta_callbacks_->p_sp_callback) { + // SP_CBACK (what events?) + // link key notification + // auth complete + } + } + + void OnEncryptionStateChanged( + bluetooth::hci::EncryptionChangeView encryption_change_view) override { + if (bta_callbacks_->p_sp_callback) { + // SP_CBACK (what events?) + // link key notification + // auth complete + } + } + + private: + ShimBondListener() : bta_callbacks_(nullptr) {} + ~ShimBondListener() {} + const tBTM_APPL_INFO* bta_callbacks_; +}; + tBTM_STATUS bluetooth::shim::BTM_StartInquiry(tBTM_INQ_RESULTS_CB* p_results_cb, tBTM_CMPL_CB* p_cmpl_cb) { CHECK(p_results_cb != nullptr); @@ -912,34 +989,40 @@ tBTM_STATUS bluetooth::shim::BTM_SecBond(const RawAddress& bd_addr, transport, device_type); } -bool bluetooth::shim::BTM_SecRegister(const tBTM_APPL_INFO* p_cb_info) { - CHECK(p_cb_info != nullptr); +bool bluetooth::shim::BTM_SecRegister(const tBTM_APPL_INFO* bta_callbacks) { + CHECK(bta_callbacks != nullptr); LOG_DEBUG("%s Registering security application", __func__); - if (p_cb_info->p_pin_callback == nullptr) { + if (bta_callbacks->p_pin_callback == nullptr) { LOG_INFO("UNIMPLEMENTED %s pin_callback", __func__); } - if (p_cb_info->p_link_key_callback == nullptr) { + if (bta_callbacks->p_link_key_callback == nullptr) { LOG_INFO("UNIMPLEMENTED %s link_key_callback", __func__); } - if (p_cb_info->p_auth_complete_callback == nullptr) { + if (bta_callbacks->p_auth_complete_callback == nullptr) { LOG_INFO("UNIMPLEMENTED %s auth_complete_callback", __func__); } - if (p_cb_info->p_bond_cancel_cmpl_callback == nullptr) { + if (bta_callbacks->p_bond_cancel_cmpl_callback == nullptr) { LOG_INFO("UNIMPLEMENTED %s bond_cancel_complete_callback", __func__); } - if (p_cb_info->p_le_callback == nullptr) { + if (bta_callbacks->p_le_callback == nullptr) { LOG_INFO("UNIMPLEMENTED %s le_callback", __func__); } - if (p_cb_info->p_le_key_callback == nullptr) { + if (bta_callbacks->p_le_key_callback == nullptr) { LOG_INFO("UNIMPLEMENTED %s le_key_callback", __func__); } + ShimBondListener::GetInstance()->SetBtaCallbacks(bta_callbacks); + + bluetooth::shim::GetSecurityModule() + ->GetSecurityManager() + ->RegisterCallbackListener(ShimBondListener::GetInstance(), + bluetooth::shim::GetGdShimHandler()); return true; } -- 2.11.0