From b697f4d0c214436b7dec61df3af85fa8c6ca849c Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 29 Oct 2020 21:43:55 -0700 Subject: [PATCH] Introduce btm_get_dev_class Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I437df6b65af6b6220edce1a9d46af375f94e65a3 --- stack/acl/btm_acl.cc | 23 ++++++++--------------- stack/btm/btm_sec.cc | 7 +++++++ stack/btm/btm_sec.h | 5 ++++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 8f5e96998..e8ebe7840 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -1321,9 +1321,8 @@ void btm_process_clk_off_comp_evt(uint16_t hci_handle, uint16_t clock_offset) { void btm_blacklist_role_change_device(const RawAddress& bd_addr, uint8_t hci_status) { tACL_CONN* p = internal_.btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR); - tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); - if (!p || !p_dev_rec) { + if (!p) { LOG_WARN("Unable to find active acl"); return; } @@ -1335,10 +1334,10 @@ void btm_blacklist_role_change_device(const RawAddress& bd_addr, /* check for carkits */ const uint32_t cod_audio_device = (BTM_COD_SERVICE_AUDIO | BTM_COD_MAJOR_AUDIO) << 8; + const uint8_t* dev_class = btm_get_dev_class(bd_addr); + if (dev_class == nullptr) return; const uint32_t cod = - ((p_dev_rec->dev_class[0] << 16) | (p_dev_rec->dev_class[1] << 8) | - p_dev_rec->dev_class[2]) & - 0xffffff; + ((dev_class[0] << 16) | (dev_class[1] << 8) | dev_class[2]) & 0xffffff; if ((hci_status != HCI_SUCCESS) && (p->is_switch_role_switching_or_in_progress()) && ((cod & cod_audio_device) == cod_audio_device) && @@ -2167,7 +2166,6 @@ void btm_cont_rswitch_from_handle(uint16_t hci_handle) { * ******************************************************************************/ void btm_acl_resubmit_page(void) { - tBTM_SEC_DEV_REC* p_dev_rec; BT_HDR* p_buf; uint8_t* pp; /* If there were other page request schedule can start the next one */ @@ -2180,10 +2178,8 @@ void btm_acl_resubmit_page(void) { RawAddress bda; STREAM_TO_BDADDR(bda, pp); - p_dev_rec = btm_find_or_alloc_dev(bda); - - btm_cb.connecting_bda = p_dev_rec->bd_addr; - memcpy(btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); + btm_cb.connecting_bda = bda; + memcpy(btm_cb.connecting_dc, btm_get_dev_class(bda), DEV_CLASS_LEN); btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p_buf); } else { @@ -2216,16 +2212,13 @@ void btm_acl_reset_paging(void) { * ******************************************************************************/ void btm_acl_paging(BT_HDR* p, const RawAddress& bda) { - tBTM_SEC_DEV_REC* p_dev_rec; - if (!BTM_IsAclConnectionUp(bda, BT_TRANSPORT_BR_EDR)) { VLOG(1) << "connecting_bda: " << btm_cb.connecting_bda; if (btm_cb.paging && bda == btm_cb.connecting_bda) { fixed_queue_enqueue(btm_cb.page_queue, p); } else { - p_dev_rec = btm_find_or_alloc_dev(bda); - btm_cb.connecting_bda = p_dev_rec->bd_addr; - memcpy(btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN); + btm_cb.connecting_bda = bda; + memcpy(btm_cb.connecting_dc, btm_get_dev_class(bda), DEV_CLASS_LEN); btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc index fb8db9e64..0a4c58a75 100644 --- a/stack/btm/btm_sec.cc +++ b/stack/btm/btm_sec.cc @@ -4826,3 +4826,10 @@ void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); } } + +// Return DEV_CLASS (uint8_t[3]) of bda +const uint8_t* btm_get_dev_class(const RawAddress& bda) { + tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda); + if (p_dev_rec == nullptr) return nullptr; + return p_dev_rec->dev_class; +} diff --git a/stack/btm/btm_sec.h b/stack/btm/btm_sec.h index 0e655815d..5ad562199 100644 --- a/stack/btm/btm_sec.h +++ b/stack/btm/btm_sec.h @@ -777,4 +777,7 @@ bool btm_sec_is_a_bonded_dev(const RawAddress& bda); ******************************************************************************/ void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, bool sc_supported, - bool hci_role_switch_supported); \ No newline at end of file + bool hci_role_switch_supported); + +// Return DEV_CLASS (uint8_t[3]) of bda +const uint8_t* btm_get_dev_class(const RawAddress& bda); -- 2.11.0