diff options
-rw-r--r-- | system/audio_hal_interface/fuzzer/Android.bp | 1 | ||||
-rw-r--r-- | system/stack/btm/btm_sec.cc | 4 | ||||
-rw-r--r-- | system/stack/include/bt_dev_class.h | 4 | ||||
-rw-r--r-- | system/stack/include/bt_name.h | 4 | ||||
-rw-r--r-- | system/stack/test/btm/stack_btm_test.cc | 47 |
5 files changed, 58 insertions, 2 deletions
diff --git a/system/audio_hal_interface/fuzzer/Android.bp b/system/audio_hal_interface/fuzzer/Android.bp index 46a5d5090c..f3ec5a7bad 100644 --- a/system/audio_hal_interface/fuzzer/Android.bp +++ b/system/audio_hal_interface/fuzzer/Android.bp @@ -45,6 +45,7 @@ cc_defaults { "android.hardware.bluetooth.audio@2.1", "android.hardware.bluetooth.audio@2.2", "android.system.suspend.control-V1-ndk", + "android.system.suspend-V1-ndk", ], static_libs: [ "libbte", diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc index d77feb1060..5f42e61317 100644 --- a/system/stack/btm/btm_sec.cc +++ b/system/stack/btm/btm_sec.cc @@ -2259,13 +2259,13 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, "status:%s name:%s", btm_pair_state_descr(btm_cb.pairing_state), hci_status_code_text(status).c_str(), p_bd_name); - DEV_CLASS dev_class = {0, 0, 0}; /* Notify all clients waiting for name to be resolved even if not found so * clients can continue */ for (i = 0; i < BTM_SEC_MAX_RMT_NAME_CALLBACKS; i++) { if (btm_cb.p_rmt_name_callback[i] && p_bd_addr) - (*btm_cb.p_rmt_name_callback[i])(*p_bd_addr, dev_class, (uint8_t*)""); + (*btm_cb.p_rmt_name_callback[i])(*p_bd_addr, (uint8_t*)kDevClassEmpty, + (uint8_t*)kBtmBdNameEmpty); } return; diff --git a/system/stack/include/bt_dev_class.h b/system/stack/include/bt_dev_class.h index a736d54839..a141c26863 100644 --- a/system/stack/include/bt_dev_class.h +++ b/system/stack/include/bt_dev_class.h @@ -25,6 +25,10 @@ #define DEV_CLASS_LEN 3 typedef uint8_t DEV_CLASS[DEV_CLASS_LEN]; /* Device class */ +#ifdef __cplusplus +inline constexpr DEV_CLASS kDevClassEmpty = {}; +#endif // __cplusplus + #define DEVCLASS_TO_STREAM(p, a) \ { \ int ijk; \ diff --git a/system/stack/include/bt_name.h b/system/stack/include/bt_name.h index eb8ce25fc2..6fcf8f9c9e 100644 --- a/system/stack/include/bt_name.h +++ b/system/stack/include/bt_name.h @@ -42,3 +42,7 @@ typedef uint8_t BD_NAME[BD_NAME_LEN + 1]; /* Device name */ typedef uint8_t tBTM_BD_NAME[BTM_MAX_REM_BD_NAME_LEN + 1]; typedef uint8_t tBTM_LOC_BD_NAME[BTM_MAX_LOC_BD_NAME_LEN + 1]; + +#ifdef __cplusplus +inline constexpr tBTM_BD_NAME kBtmBdNameEmpty = {}; +#endif diff --git a/system/stack/test/btm/stack_btm_test.cc b/system/stack/test/btm/stack_btm_test.cc index 283ecbde2c..e1e4edf62d 100644 --- a/system/stack/test/btm/stack_btm_test.cc +++ b/system/stack/test/btm/stack_btm_test.cc @@ -30,8 +30,10 @@ #include "internal_include/stack_config.h" #include "osi/include/allocator.h" #include "osi/include/osi.h" +#include "stack/btm/btm_dev.h" #include "stack/btm/btm_int_types.h" #include "stack/btm/btm_sco.h" +#include "stack/btm/btm_sec.h" #include "stack/include/acl_api.h" #include "stack/include/acl_hci_link_interface.h" #include "stack/include/btm_client_interface.h" @@ -40,6 +42,9 @@ #include "test/mock/mock_stack_hcic_hcicmds.h" #include "types/raw_address.h" +using testing::Each; +using testing::Eq; + namespace mock = test::mock::stack_hcic_hcicmds; extern tBTM_CB btm_cb; @@ -206,3 +211,45 @@ TEST(ScoTest, make_sco_packet) { } } // namespace + +void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, + const uint8_t* p_bd_name, + tHCI_STATUS status); + +struct { + RawAddress bd_addr; + DEV_CLASS dc; + tBTM_BD_NAME bd_name; +} btm_test; + +TEST(SecTest, btm_sec_rmt_name_request_complete) { + bluetooth::common::InitFlags::SetAllForTesting(); + btm_cb.Init(0); + + ASSERT_TRUE(BTM_SecAddRmtNameNotifyCallback( + [](const RawAddress& bd_addr, DEV_CLASS dc, tBTM_BD_NAME bd_name) { + btm_test.bd_addr = bd_addr; + memcpy(btm_test.dc, dc, DEV_CLASS_LEN); + memcpy(btm_test.bd_name, bd_name, BTM_MAX_REM_BD_NAME_LEN); + })); + + RawAddress bd_addr = RawAddress({0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6}); + const uint8_t* p_bd_name = (const uint8_t*)"MyTestName"; + + btm_test = {}; + btm_sec_rmt_name_request_complete(&bd_addr, p_bd_name, HCI_SUCCESS); + + ASSERT_THAT(btm_test.bd_name, Each(Eq(0))); + ASSERT_THAT(btm_test.dc, Each(Eq(0))); + ASSERT_EQ(bd_addr, btm_test.bd_addr); + + btm_test = {}; + ASSERT_TRUE(btm_find_or_alloc_dev(bd_addr) != nullptr); + btm_sec_rmt_name_request_complete(&bd_addr, p_bd_name, HCI_SUCCESS); + + ASSERT_STREQ((const char*)p_bd_name, (const char*)btm_test.bd_name); + ASSERT_THAT(btm_test.dc, Each(Eq(0))); + ASSERT_EQ(bd_addr, btm_test.bd_addr); + + btm_cb.Free(); +} |