kopia lustrzana https://github.com/espressif/esp-idf
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.pull/2140/head
rodzic
9a55b42f08
commit
29b7d4e916
|
@ -698,7 +698,7 @@ void bta_dm_set_visibility(tBTA_DM_MSG *p_data)
|
|||
** 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)
|
||||
/* need to remove all pending background connection before unpair */
|
||||
|
@ -711,12 +711,16 @@ void bta_dm_process_remove_device(BD_ADDR bd_addr)
|
|||
/* remove all cached GATT information */
|
||||
BTA_GATTC_Refresh(bd_addr, false);
|
||||
#endif
|
||||
|
||||
if (bta_dm_cb.p_sec_cback) {
|
||||
tBTA_DM_SEC sec_event;
|
||||
bdcpy(sec_event.link_down.bd_addr, bd_addr);
|
||||
sec_event.link_down.status = HCI_SUCCESS;
|
||||
bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -734,15 +738,11 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
|
|||
return;
|
||||
}
|
||||
|
||||
BD_ADDR other_address;
|
||||
bdcpy(other_address, p_dev->bd_addr);
|
||||
|
||||
/* If ACL exists for the device in the remove_bond message*/
|
||||
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) ||
|
||||
BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR)) {
|
||||
if (BTM_IsAclConnectionUp(p_dev->bd_addr, transport)) {
|
||||
APPL_TRACE_DEBUG("%s: ACL Up count %d", __func__, bta_dm_cb.device_list.count);
|
||||
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);
|
||||
APPL_TRACE_DEBUG("%s:transport = %d", __func__,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -767,35 +760,9 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
|
|||
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 */
|
||||
if (continue_delete_dev) {
|
||||
bta_dm_process_remove_device(p_dev->bd_addr);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
bta_dm_process_remove_device(p_dev->bd_addr, transport);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3351,7 +3318,11 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
|
|||
if ( bta_dm_cb.p_sec_cback ) {
|
||||
bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn);
|
||||
if ( issue_unpair_cb ) {
|
||||
bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -569,7 +569,7 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
|
|||
** 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;
|
||||
|
||||
|
@ -578,6 +578,7 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
|
|||
|
||||
p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
|
||||
bdcpy(p_msg->bd_addr, bd_addr);
|
||||
p_msg->transport = transport;
|
||||
bta_sys_sendmsg(p_msg);
|
||||
} else {
|
||||
return BTA_FAILURE;
|
||||
|
|
|
@ -391,6 +391,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
BT_HDR hdr;
|
||||
BD_ADDR bd_addr;
|
||||
UINT8 transport;
|
||||
} tBTA_DM_API_REMOVE_DEVICE;
|
||||
|
||||
/* data type for BTA_DM_API_EXECUTE_CBACK_EVT */
|
||||
|
|
|
@ -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_BLE_AUTH_CMPL_EVT 24 /* BLE Auth complete */
|
||||
// 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_LE_FEATURES_READ 27 /* Cotroller specific LE features are 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;
|
||||
|
||||
/* 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.
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr);
|
||||
extern tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr, tBT_TRANSPORT transport);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
|
|
@ -495,10 +495,23 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
|
|||
case BTA_DM_DEV_UNPAIRED_EVT: {
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
bt_bdaddr_t bd_addr;
|
||||
rsp_app = true;
|
||||
BTC_TRACE_DEBUG("BTA_DM_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);
|
||||
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;
|
||||
|
||||
if (p_data->link_down.status == HCI_SUCCESS) {
|
||||
|
|
|
@ -1108,7 +1108,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
|||
case BTC_GAP_BLE_REMOVE_BOND_DEV_EVT: {
|
||||
BD_ADDR 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;
|
||||
}
|
||||
#endif ///SMP_INCLUDED == TRUE
|
||||
|
|
|
@ -639,8 +639,7 @@ esp_err_t btc_gap_bt_remove_bond_device(btc_gap_bt_args_t *arg)
|
|||
{
|
||||
BD_ADDR bd_addr;
|
||||
memcpy(bd_addr, arg->rm_bond_device.bda.address, sizeof(BD_ADDR));
|
||||
if(BTA_DmRemoveDevice(bd_addr) == BTA_SUCCESS){
|
||||
btc_storage_remove_bonded_device(&(arg->rm_bond_device.bda));
|
||||
if(BTA_DmRemoveDevice(bd_addr, BT_TRANSPORT_BR_EDR) == BTA_SUCCESS){
|
||||
return ESP_BT_STATUS_SUCCESS;
|
||||
}
|
||||
return ESP_BT_STATUS_FAIL;
|
||||
|
|
Ładowanie…
Reference in New Issue