component/bt: Fix bug of BT and BLE remove bond device

1. esp_ble_remove_bond_device will only remove BLE bond key and disconnect BLE device.
2. esp_bt_gap_remove_bond_device  will only remove BT bond key and disconnect BT device.
This commit is contained in:
baohongde 2018-06-22 11:54:40 +08:00
parent 9a55b42f08
commit 29b7d4e916
7 changed files with 37 additions and 51 deletions

View file

@ -698,7 +698,7 @@ void bta_dm_set_visibility(tBTA_DM_MSG *p_data)
** Description Removes device, Disconnects ACL link if required. ** Description Removes device, Disconnects ACL link if required.
**** ****
*******************************************************************************/ *******************************************************************************/
void bta_dm_process_remove_device(BD_ADDR bd_addr) static void bta_dm_process_remove_device(BD_ADDR bd_addr, tBT_TRANSPORT transport)
{ {
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* need to remove all pending background connection before unpair */ /* need to remove all pending background connection before unpair */
@ -711,13 +711,17 @@ void bta_dm_process_remove_device(BD_ADDR bd_addr)
/* remove all cached GATT information */ /* remove all cached GATT information */
BTA_GATTC_Refresh(bd_addr, false); BTA_GATTC_Refresh(bd_addr, false);
#endif #endif
if (bta_dm_cb.p_sec_cback) { if (bta_dm_cb.p_sec_cback) {
tBTA_DM_SEC sec_event; tBTA_DM_SEC sec_event;
bdcpy(sec_event.link_down.bd_addr, bd_addr); bdcpy(sec_event.link_down.bd_addr, bd_addr);
sec_event.link_down.status = HCI_SUCCESS; sec_event.link_down.status = HCI_SUCCESS;
if (transport == BT_TRANSPORT_LE){
bta_dm_cb.p_sec_cback(BTA_DM_BLE_DEV_UNPAIRED_EVT, &sec_event);
} else {
bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event); bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
} }
}
} }
/******************************************************************************* /*******************************************************************************
@ -734,15 +738,11 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
return; return;
} }
BD_ADDR other_address;
bdcpy(other_address, p_dev->bd_addr);
/* If ACL exists for the device in the remove_bond message*/ /* If ACL exists for the device in the remove_bond message*/
BOOLEAN continue_delete_dev = FALSE; BOOLEAN continue_delete_dev = FALSE;
UINT8 other_transport = BT_TRANSPORT_INVALID; UINT8 transport = p_dev->transport;
if (BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) || if (BTM_IsAclConnectionUp(p_dev->bd_addr, transport)) {
BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR)) {
APPL_TRACE_DEBUG("%s: ACL Up count %d", __func__, bta_dm_cb.device_list.count); APPL_TRACE_DEBUG("%s: ACL Up count %d", __func__, bta_dm_cb.device_list.count);
continue_delete_dev = FALSE; continue_delete_dev = FALSE;
@ -753,13 +753,6 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
btm_remove_acl( p_dev->bd_addr, bta_dm_cb.device_list.peer_device[i].transport); btm_remove_acl( p_dev->bd_addr, bta_dm_cb.device_list.peer_device[i].transport);
APPL_TRACE_DEBUG("%s:transport = %d", __func__, APPL_TRACE_DEBUG("%s:transport = %d", __func__,
bta_dm_cb.device_list.peer_device[i].transport); bta_dm_cb.device_list.peer_device[i].transport);
/* save the other transport to check if device is connected on other_transport */
if (bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_LE) {
other_transport = BT_TRANSPORT_BR_EDR;
} else {
other_transport = BT_TRANSPORT_LE;
}
break; break;
} }
} }
@ -767,35 +760,9 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
continue_delete_dev = TRUE; continue_delete_dev = TRUE;
} }
// If it is DUMO device and device is paired as different address, unpair that device
// if different address
BOOLEAN continue_delete_other_dev = FALSE;
if ((other_transport && (BTM_ReadConnectedTransportAddress(other_address, other_transport))) ||
(!other_transport && (BTM_ReadConnectedTransportAddress(other_address, BT_TRANSPORT_BR_EDR) ||
BTM_ReadConnectedTransportAddress(other_address, BT_TRANSPORT_LE)))) {
continue_delete_other_dev = FALSE;
/* Take the link down first, and mark the device for removal when disconnected */
for (int i = 0; i < bta_dm_cb.device_list.count; i++) {
if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, other_address)) {
bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
btm_remove_acl(other_address, bta_dm_cb.device_list.peer_device[i].transport);
break;
}
}
} else {
APPL_TRACE_DEBUG("%s: continue to delete the other dev ", __func__);
continue_delete_other_dev = TRUE;
}
/* Delete the device mentioned in the msg */ /* Delete the device mentioned in the msg */
if (continue_delete_dev) { if (continue_delete_dev) {
bta_dm_process_remove_device(p_dev->bd_addr); bta_dm_process_remove_device(p_dev->bd_addr, transport);
}
/* Delete the other paired device too */
BD_ADDR dummy_bda = {0};
if (continue_delete_other_dev && (bdcmp(other_address, dummy_bda) != 0)) {
bta_dm_process_remove_device(other_address);
} }
} }
@ -3351,10 +3318,14 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
if ( bta_dm_cb.p_sec_cback ) { if ( bta_dm_cb.p_sec_cback ) {
bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn); bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn);
if ( issue_unpair_cb ) { if ( issue_unpair_cb ) {
if (p_data->acl_change.transport == BT_TRANSPORT_LE) {
bta_dm_cb.p_sec_cback(BTA_DM_BLE_DEV_UNPAIRED_EVT, &conn);
} else {
bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn); bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn);
} }
} }
} }
}
bta_dm_adjust_roles(TRUE); bta_dm_adjust_roles(TRUE);
} }

View file

@ -569,7 +569,7 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
** Returns void ** Returns void
** **
*******************************************************************************/ *******************************************************************************/
tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr) tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport)
{ {
tBTA_DM_API_REMOVE_DEVICE *p_msg; tBTA_DM_API_REMOVE_DEVICE *p_msg;
@ -578,6 +578,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT; p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
bdcpy(p_msg->bd_addr, bd_addr); bdcpy(p_msg->bd_addr, bd_addr);
p_msg->transport = transport;
bta_sys_sendmsg(p_msg); bta_sys_sendmsg(p_msg);
} else { } else {
return BTA_FAILURE; return BTA_FAILURE;

View file

@ -391,6 +391,7 @@ typedef struct {
typedef struct { typedef struct {
BT_HDR hdr; BT_HDR hdr;
BD_ADDR bd_addr; BD_ADDR bd_addr;
UINT8 transport;
} tBTA_DM_API_REMOVE_DEVICE; } tBTA_DM_API_REMOVE_DEVICE;
/* data type for BTA_DM_API_EXECUTE_CBACK_EVT */ /* data type for BTA_DM_API_EXECUTE_CBACK_EVT */

View file

@ -631,10 +631,11 @@ typedef UINT8 tBTA_SIG_STRENGTH_MASK;
#define BTA_DM_SP_RMT_OOB_EXT_EVT 23 /* Simple Pairing Remote OOB Extended Data request. */ #define BTA_DM_SP_RMT_OOB_EXT_EVT 23 /* Simple Pairing Remote OOB Extended Data request. */
#define BTA_DM_BLE_AUTH_CMPL_EVT 24 /* BLE Auth complete */ #define BTA_DM_BLE_AUTH_CMPL_EVT 24 /* BLE Auth complete */
// btla-specific -- // btla-specific --
#define BTA_DM_DEV_UNPAIRED_EVT 25 #define BTA_DM_DEV_UNPAIRED_EVT 25 /* BT unpair event */
#define BTA_DM_HW_ERROR_EVT 26 /* BT Chip H/W error */ #define BTA_DM_HW_ERROR_EVT 26 /* BT Chip H/W error */
#define BTA_DM_LE_FEATURES_READ 27 /* Cotroller specific LE features are read */ #define BTA_DM_LE_FEATURES_READ 27 /* Cotroller specific LE features are read */
#define BTA_DM_ENER_INFO_READ 28 /* Energy info read */ #define BTA_DM_ENER_INFO_READ 28 /* Energy info read */
#define BTA_DM_BLE_DEV_UNPAIRED_EVT 29 /* BLE unpair event */
typedef UINT8 tBTA_DM_SEC_EVT; typedef UINT8 tBTA_DM_SEC_EVT;
/* Structure associated with BTA_DM_ENABLE_EVT */ /* Structure associated with BTA_DM_ENABLE_EVT */
@ -1632,7 +1633,7 @@ extern void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class,
** BTA_FAIL if operation failed. ** BTA_FAIL if operation failed.
** **
*******************************************************************************/ *******************************************************************************/
extern tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr); extern tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport);
/******************************************************************************* /*******************************************************************************
** **

View file

@ -495,10 +495,23 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
case BTA_DM_DEV_UNPAIRED_EVT: { case BTA_DM_DEV_UNPAIRED_EVT: {
#if (SMP_INCLUDED == TRUE) #if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bd_addr; bt_bdaddr_t bd_addr;
rsp_app = true;
BTC_TRACE_DEBUG("BTA_DM_DEV_UNPAIRED_EVT"); BTC_TRACE_DEBUG("BTA_DM_DEV_UNPAIRED_EVT");
memcpy(bd_addr.address, p_data->link_down.bd_addr, sizeof(BD_ADDR)); memcpy(bd_addr.address, p_data->link_down.bd_addr, sizeof(BD_ADDR));
btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN); btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
if (p_data->link_down.status == HCI_SUCCESS) {
//remove the bonded key in the config and nvs flash.
btc_storage_remove_bonded_device(&bd_addr);
}
#endif /* #if (SMP_INCLUDED == TRUE) */
break;
}
case BTA_DM_BLE_DEV_UNPAIRED_EVT: {
#if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bd_addr;
rsp_app = true;
BTC_TRACE_DEBUG("BTA_DM_BLE_DEV_UNPAIRED_EVT");
memcpy(bd_addr.address, p_data->link_down.bd_addr, sizeof(BD_ADDR));
btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
param.remove_bond_dev_cmpl.status = ESP_BT_STATUS_FAIL; param.remove_bond_dev_cmpl.status = ESP_BT_STATUS_FAIL;
if (p_data->link_down.status == HCI_SUCCESS) { if (p_data->link_down.status == HCI_SUCCESS) {

View file

@ -1108,7 +1108,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
case BTC_GAP_BLE_REMOVE_BOND_DEV_EVT: { case BTC_GAP_BLE_REMOVE_BOND_DEV_EVT: {
BD_ADDR bd_addr; BD_ADDR bd_addr;
memcpy(bd_addr, arg->remove_bond_device.bd_addr, sizeof(BD_ADDR)); memcpy(bd_addr, arg->remove_bond_device.bd_addr, sizeof(BD_ADDR));
BTA_DmRemoveDevice(bd_addr); BTA_DmRemoveDevice(bd_addr, BT_TRANSPORT_LE);
break; break;
} }
#endif ///SMP_INCLUDED == TRUE #endif ///SMP_INCLUDED == TRUE

View file

@ -639,8 +639,7 @@ esp_err_t btc_gap_bt_remove_bond_device(btc_gap_bt_args_t *arg)
{ {
BD_ADDR bd_addr; BD_ADDR bd_addr;
memcpy(bd_addr, arg->rm_bond_device.bda.address, sizeof(BD_ADDR)); memcpy(bd_addr, arg->rm_bond_device.bda.address, sizeof(BD_ADDR));
if(BTA_DmRemoveDevice(bd_addr) == BTA_SUCCESS){ if(BTA_DmRemoveDevice(bd_addr, BT_TRANSPORT_BR_EDR) == BTA_SUCCESS){
btc_storage_remove_bonded_device(&(arg->rm_bond_device.bda));
return ESP_BT_STATUS_SUCCESS; return ESP_BT_STATUS_SUCCESS;
} }
return ESP_BT_STATUS_FAIL; return ESP_BT_STATUS_FAIL;