From ff9910468f9dbea848d96ab2f1f44047a9ba148c Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Mon, 31 Aug 2020 21:21:35 -0700 Subject: [PATCH] Replace tBTM_SEC_BLE::identity addr/type Replace with address_with_type Towards readable code Bug: 163134718 Tag: #refactor Test: compile & verify basic functions working Change-Id: I627c2ce248a394368b47efc077c7b69844b3299e --- stack/acl/btm_acl.cc | 9 +++++---- stack/btm/btm_ble.cc | 6 ++++-- stack/btm/btm_ble_addr.cc | 13 ++++++------ stack/btm/btm_ble_bgconn.cc | 14 +++++++------ stack/btm/btm_ble_gap.cc | 8 ++++---- stack/btm/btm_ble_privacy.cc | 41 +++++++++++++++++++++----------------- stack/btm/security_device_record.h | 4 ++-- 7 files changed, 53 insertions(+), 42 deletions(-) diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index ed0d61237..746e1e755 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -254,8 +254,8 @@ bool btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC* p_dev_rec, break; case tBTM_SEC_BLE::BTM_BLE_ADDR_STATIC: - conn_addr = p_dev_rec->ble.identity_addr; - *p_addr_type = p_dev_rec->ble.identity_addr_type; + conn_addr = p_dev_rec->ble.identity_address_with_type.bda; + *p_addr_type = p_dev_rec->ble.identity_address_with_type.type; break; default: @@ -2435,8 +2435,9 @@ bool acl_refresh_remote_address(const tBTM_SEC_DEV_REC* p_sec_rec, if (rra_type == tBTM_SEC_BLE::BTM_BLE_ADDR_PSEUDO) { /* use identity address, resolvable_private_addr is empty */ if (rpa.IsEmpty()) { - p_acl->active_remote_addr_type = p_sec_rec->ble.identity_addr_type; - p_acl->active_remote_addr = p_sec_rec->ble.identity_addr; + p_acl->active_remote_addr_type = + p_sec_rec->ble.identity_address_with_type.type; + p_acl->active_remote_addr = p_sec_rec->ble.identity_address_with_type.bda; } else { p_acl->active_remote_addr_type = BLE_ADDR_RANDOM; p_acl->active_remote_addr = rpa; diff --git a/stack/btm/btm_ble.cc b/stack/btm/btm_ble.cc index eb256aaa5..b4eddb186 100644 --- a/stack/btm/btm_ble.cc +++ b/stack/btm/btm_ble.cc @@ -1178,8 +1178,10 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type, case BTM_LE_KEY_PID: p_rec->ble.keys.irk = p_keys->pid_key.irk; - p_rec->ble.identity_addr = p_keys->pid_key.identity_addr; - p_rec->ble.identity_addr_type = p_keys->pid_key.identity_addr_type; + p_rec->ble.identity_address_with_type.bda = + p_keys->pid_key.identity_addr; + p_rec->ble.identity_address_with_type.type = + p_keys->pid_key.identity_addr_type; p_rec->ble.key_type |= BTM_LE_KEY_PID; BTM_TRACE_DEBUG( "%s: BTM_LE_KEY_PID key_type=0x%x save peer IRK, change bd_addr=%s " diff --git a/stack/btm/btm_ble_addr.cc b/stack/btm/btm_ble_addr.cc index f171ba3f9..b8174b38f 100644 --- a/stack/btm/btm_ble_addr.cc +++ b/stack/btm/btm_ble_addr.cc @@ -227,12 +227,13 @@ tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(const RawAddress& bd_addr, node = list_next(node)) { tBTM_SEC_DEV_REC* p_dev_rec = static_cast(list_node(node)); - if (p_dev_rec->ble.identity_addr == bd_addr) { - if ((p_dev_rec->ble.identity_addr_type & (~BLE_ADDR_TYPE_ID_BIT)) != - (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) + if (p_dev_rec->ble.identity_address_with_type.bda == bd_addr) { + if ((p_dev_rec->ble.identity_address_with_type.type & + (~BLE_ADDR_TYPE_ID_BIT)) != (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) BTM_TRACE_WARNING( "%s find pseudo->random match with diff addr type: %d vs %d", - __func__, p_dev_rec->ble.identity_addr_type, addr_type); + __func__, p_dev_rec->ble.identity_address_with_type.type, + addr_type); /* found the match */ return p_dev_rec; @@ -294,8 +295,8 @@ bool btm_random_pseudo_to_identity_addr(RawAddress* random_pseudo, if (p_dev_rec != NULL) { if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { - *p_identity_addr_type = p_dev_rec->ble.identity_addr_type; - *random_pseudo = p_dev_rec->ble.identity_addr; + *p_identity_addr_type = p_dev_rec->ble.identity_address_with_type.type; + *random_pseudo = p_dev_rec->ble.identity_address_with_type.bda; if (controller_get_interface()->supports_ble_privacy()) *p_identity_addr_type |= BLE_ADDR_TYPE_ID_BIT; return true; diff --git a/stack/btm/btm_ble_bgconn.cc b/stack/btm/btm_ble_bgconn.cc index 7d6198da7..cdb9e4127 100644 --- a/stack/btm/btm_ble_bgconn.cc +++ b/stack/btm/btm_ble_bgconn.cc @@ -179,7 +179,7 @@ bool BTM_BackgroundConnectAddressKnown(const RawAddress& address) { return true; // bonded device with identity address known - if (!p_dev_rec->ble.identity_addr.IsEmpty()) { + if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) { return true; } @@ -205,9 +205,10 @@ bool btm_add_dev_to_controller(bool to_add, const RawAddress& bd_addr) { if (p_dev_rec != NULL && p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) { if (to_add) { - if (!p_dev_rec->ble.identity_addr.IsEmpty()) { - background_connection_add(p_dev_rec->ble.identity_addr_type, - p_dev_rec->ble.identity_addr); + if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) { + background_connection_add( + p_dev_rec->ble.identity_address_with_type.type, + p_dev_rec->ble.identity_address_with_type.bda); } else { background_connection_add(p_dev_rec->ble.ble_addr_type, bd_addr); @@ -219,8 +220,9 @@ bool btm_add_dev_to_controller(bool to_add, const RawAddress& bd_addr) { p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT; } else { - if (!p_dev_rec->ble.identity_addr.IsEmpty()) { - background_connection_remove(p_dev_rec->ble.identity_addr); + if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) { + background_connection_remove( + p_dev_rec->ble.identity_address_with_type.bda); } else { background_connection_remove(bd_addr); diff --git a/stack/btm/btm_ble_gap.cc b/stack/btm/btm_ble_gap.cc index cce44820b..ad3001c86 100644 --- a/stack/btm/btm_ble_gap.cc +++ b/stack/btm/btm_ble_gap.cc @@ -692,8 +692,8 @@ static uint8_t btm_set_conn_mode_adv_init_addr( if ((p_dev_rec = btm_find_or_alloc_dev(p_cb->direct_bda.bda)) != NULL && p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { btm_ble_enable_resolving_list(BTM_BLE_RL_ADV); - p_peer_addr_ptr = p_dev_rec->ble.identity_addr; - *p_peer_addr_type = p_dev_rec->ble.identity_addr_type; + p_peer_addr_ptr = p_dev_rec->ble.identity_address_with_type.bda; + *p_peer_addr_type = p_dev_rec->ble.identity_address_with_type.type; *p_own_addr_type = BLE_ADDR_RANDOM_ID; return evt_type; } @@ -721,8 +721,8 @@ static uint8_t btm_set_conn_mode_adv_init_addr( * peer */ tBTM_SEC_DEV_REC* p_dev_rec = static_cast(list_node(n)); - p_peer_addr_ptr = p_dev_rec->ble.identity_addr; - *p_peer_addr_type = p_dev_rec->ble.identity_addr_type; + p_peer_addr_ptr = p_dev_rec->ble.identity_address_with_type.bda; + *p_peer_addr_type = p_dev_rec->ble.identity_address_with_type.type; *p_own_addr_type = BLE_ADDR_RANDOM_ID; } else { diff --git a/stack/btm/btm_ble_privacy.cc b/stack/btm/btm_ble_privacy.cc index 827eeeafd..928701dc4 100644 --- a/stack/btm/btm_ble_privacy.cc +++ b/stack/btm/btm_ble_privacy.cc @@ -417,15 +417,16 @@ tBTM_STATUS btm_ble_remove_resolving_list_entry(tBTM_SEC_DEV_REC* p_dev_rec) { return BTM_WRONG_MODE; if (controller_get_interface()->supports_ble_privacy()) { - btsnd_hcic_ble_rm_device_resolving_list(p_dev_rec->ble.identity_addr_type, - p_dev_rec->ble.identity_addr); + btsnd_hcic_ble_rm_device_resolving_list( + p_dev_rec->ble.identity_address_with_type.type, + p_dev_rec->ble.identity_address_with_type.bda); } else { uint8_t param[20] = {0}; uint8_t* p = param; UINT8_TO_STREAM(p, BTM_BLE_META_REMOVE_IRK_ENTRY); - UINT8_TO_STREAM(p, p_dev_rec->ble.identity_addr_type); - BDADDR_TO_STREAM(p, p_dev_rec->ble.identity_addr); + UINT8_TO_STREAM(p, p_dev_rec->ble.identity_address_with_type.type); + BDADDR_TO_STREAM(p, p_dev_rec->ble.identity_address_with_type.bda); BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_META_REMOVE_IRK_LEN, param, @@ -479,8 +480,9 @@ bool btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC* p_dev_rec) { } if (controller_get_interface()->supports_ble_privacy()) { - btsnd_hcic_ble_read_resolvable_addr_peer(p_dev_rec->ble.identity_addr_type, - p_dev_rec->ble.identity_addr); + btsnd_hcic_ble_read_resolvable_addr_peer( + p_dev_rec->ble.identity_address_with_type.type, + p_dev_rec->ble.identity_address_with_type.bda); } else { uint8_t param[20] = {0}; uint8_t* p = param; @@ -730,23 +732,26 @@ bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) { const Octet16& peer_irk = p_dev_rec->ble.keys.irk; const Octet16& local_irk = btm_cb.devcb.id_keys.irk; - if (p_dev_rec->ble.identity_addr.IsEmpty()) { - p_dev_rec->ble.identity_addr = p_dev_rec->bd_addr; - p_dev_rec->ble.identity_addr_type = p_dev_rec->ble.ble_addr_type; + if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) { + p_dev_rec->ble.identity_address_with_type.bda = p_dev_rec->bd_addr; + p_dev_rec->ble.identity_address_with_type.type = + p_dev_rec->ble.ble_addr_type; } - BTM_TRACE_DEBUG("%s: adding device %s to controller resolving list", - __func__, p_dev_rec->ble.identity_addr.ToString().c_str()); + BTM_TRACE_DEBUG( + "%s: adding device %s to controller resolving list", __func__, + p_dev_rec->ble.identity_address_with_type.bda.ToString().c_str()); // use identical IRK for now - btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.identity_addr_type, - p_dev_rec->ble.identity_addr, - peer_irk, local_irk); + btsnd_hcic_ble_add_device_resolving_list( + p_dev_rec->ble.identity_address_with_type.type, + p_dev_rec->ble.identity_address_with_type.bda, peer_irk, local_irk); if (controller_get_interface()->supports_ble_set_privacy_mode()) { BTM_TRACE_DEBUG("%s: adding device privacy mode", __func__); - btsnd_hcic_ble_set_privacy_mode(p_dev_rec->ble.identity_addr_type, - p_dev_rec->ble.identity_addr, 0x01); + btsnd_hcic_ble_set_privacy_mode( + p_dev_rec->ble.identity_address_with_type.type, + p_dev_rec->ble.identity_address_with_type.bda, 0x01); } } else { uint8_t param[40] = {0}; @@ -754,8 +759,8 @@ bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) { UINT8_TO_STREAM(p, BTM_BLE_META_ADD_IRK_ENTRY); ARRAY_TO_STREAM(p, p_dev_rec->ble.keys.irk, OCTET16_LEN); - UINT8_TO_STREAM(p, p_dev_rec->ble.identity_addr_type); - BDADDR_TO_STREAM(p, p_dev_rec->ble.identity_addr); + UINT8_TO_STREAM(p, p_dev_rec->ble.identity_address_with_type.type); + BDADDR_TO_STREAM(p, p_dev_rec->ble.identity_address_with_type.bda); BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_META_ADD_IRK_LEN, param, btm_ble_resolving_list_vsc_op_cmpl); diff --git a/stack/btm/security_device_record.h b/stack/btm/security_device_record.h index 36e3f10f4..6ce736e91 100644 --- a/stack/btm/security_device_record.h +++ b/stack/btm/security_device_record.h @@ -329,8 +329,8 @@ typedef struct { RawAddress pseudo_addr; /* LE pseudo address of the device if different from device address */ tBLE_ADDR_TYPE ble_addr_type; /* LE device type: public or random address */ - tBLE_ADDR_TYPE identity_addr_type; /* identity address type */ - RawAddress identity_addr; /* identity address */ + + tBLE_BD_ADDR identity_address_with_type; #define BTM_WHITE_LIST_BIT 0x01 #define BTM_RESOLVING_LIST_BIT 0x02 -- 2.11.0