Merge branch 'bugfix/btdm_bt_remove_device_fail_when_ble_connected' into 'master'

component/bt: Fix bug of remove bond device fail when BLE and BT are connectd at the same time

See merge request idf/esp-idf!2767
This commit is contained in:
Jiang Jiang Jian 2018-07-20 10:46:31 +08:00
commit e4fb359c34
4 changed files with 40 additions and 23 deletions

View file

@ -705,7 +705,7 @@ static void bta_dm_process_remove_device(BD_ADDR bd_addr, tBT_TRANSPORT transpor
BTA_GATTC_CancelOpen(0, bd_addr, FALSE); BTA_GATTC_CancelOpen(0, bd_addr, FALSE);
#endif #endif
BTM_SecDeleteDevice(bd_addr); BTM_SecDeleteDevice(bd_addr, transport);
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* remove all cached GATT information */ /* remove all cached GATT information */
@ -748,7 +748,8 @@ void bta_dm_remove_device(tBTA_DM_MSG *p_data)
/* Take the link down first, and mark the device for removal when disconnected */ /* 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++) { for (int i = 0; i < bta_dm_cb.device_list.count; i++) {
if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr)) { if (!bdcmp(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr)
&& bta_dm_cb.device_list.peer_device[i].transport == transport) {
bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING; bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING;
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__,
@ -853,7 +854,7 @@ void bta_dm_close_acl(tBTA_DM_MSG *p_data)
} }
/* if to remove the device from security database ? do it now */ /* if to remove the device from security database ? do it now */
else if (p_remove_acl->remove_dev) { else if (p_remove_acl->remove_dev) {
if (!BTM_SecDeleteDevice(p_remove_acl->bd_addr)) { if (!BTM_SecDeleteDevice(p_remove_acl->bd_addr, p_remove_acl->transport)) {
APPL_TRACE_ERROR("delete device from security database failed."); APPL_TRACE_ERROR("delete device from security database failed.");
} }
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
@ -3299,7 +3300,7 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
} }
if ( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING ) { if ( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING ) {
if (BTM_SecDeleteDevice(bta_dm_cb.device_list.peer_device[i].peer_bdaddr)) { if (BTM_SecDeleteDevice(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, bta_dm_cb.device_list.peer_device[i].transport)) {
issue_unpair_cb = TRUE; issue_unpair_cb = TRUE;
} }
@ -3347,7 +3348,7 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
} }
} }
if (conn.link_down.is_removed) { if (conn.link_down.is_removed) {
BTM_SecDeleteDevice(p_bda); BTM_SecDeleteDevice(p_bda, p_data->acl_change.transport);
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* need to remove all pending background connection */ /* need to remove all pending background connection */
BTA_GATTC_CancelOpen(0, p_bda, FALSE); BTA_GATTC_CancelOpen(0, p_bda, FALSE);
@ -3525,7 +3526,7 @@ static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr)
APPL_TRACE_ERROR(" %s Device does not exist in DB", __FUNCTION__); APPL_TRACE_ERROR(" %s Device does not exist in DB", __FUNCTION__);
} }
} else { } else {
BTM_SecDeleteDevice (remote_bd_addr); BTM_SecDeleteDevice (remote_bd_addr, bta_dm_cb.device_list.peer_device[index].transport);
#if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE) #if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
/* need to remove all pending background connection */ /* need to remove all pending background connection */
BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE); BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE);

View file

@ -172,22 +172,23 @@ BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
** Description Free resources associated with the device. ** Description Free resources associated with the device.
** **
** Parameters: bd_addr - BD address of the peer ** Parameters: bd_addr - BD address of the peer
** transport - BT_TRANSPORT_BR_EDR or BT_TRANSPORT_LE
** **
** Returns TRUE if removed OK, FALSE if not found or ACL link is active ** Returns TRUE if removed OK, FALSE if not found or ACL link is active
** **
*******************************************************************************/ *******************************************************************************/
BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr) BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport)
{ {
tBTM_SEC_DEV_REC *p_dev_rec; tBTM_SEC_DEV_REC *p_dev_rec;
if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) || if (BTM_IsAclConnectionUp(bd_addr, transport)) {
BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) {
BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active\n", __func__); BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active\n", __func__);
return FALSE; return FALSE;
} }
if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL) { if ((p_dev_rec = btm_find_dev(bd_addr)) != NULL) {
btm_sec_free_dev(p_dev_rec); btm_sec_free_dev(p_dev_rec, transport);
/* Tell controller to get rid of the link key, if it has one stored */ /* Tell controller to get rid of the link key, if it has one stored */
BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL); BTM_DeleteStoredLinkKey (p_dev_rec->bd_addr, NULL);
} }
@ -340,17 +341,33 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
** Description Mark device record as not used ** Description Mark device record as not used
** **
*******************************************************************************/ *******************************************************************************/
void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec) void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec, tBT_TRANSPORT transport)
{ {
if (transport == BT_TRANSPORT_BR_EDR) {
memset(p_dev_rec->link_key, 0, LINK_KEY_LEN);
p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
| BTM_SEC_ENCRYPTED | BTM_SEC_NAME_KNOWN
| BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LINK_KEY_AUTHED
| BTM_SEC_ROLE_SWITCHED | BTM_SEC_16_DIGIT_PIN_AUTHED);
} else if (transport == BT_TRANSPORT_LE) {
p_dev_rec->bond_type = BOND_TYPE_UNKNOWN; p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
p_dev_rec->sec_flags &= ~(BTM_SEC_LE_AUTHENTICATED | BTM_SEC_LE_ENCRYPTED
| BTM_SEC_LE_NAME_KNOWN | BTM_SEC_LE_LINK_KEY_KNOWN
| BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_ROLE_SWITCHED);
#if BLE_INCLUDED == TRUE
/* Clear out any saved BLE keys */
btm_sec_clear_ble_keys (p_dev_rec);
#endif
} else {
p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
memset(p_dev_rec->link_key, 0, LINK_KEY_LEN);
p_dev_rec->sec_flags = 0; p_dev_rec->sec_flags = 0;
#if BLE_INCLUDED == TRUE #if BLE_INCLUDED == TRUE
/* Clear out any saved BLE keys */ /* Clear out any saved BLE keys */
btm_sec_clear_ble_keys (p_dev_rec); btm_sec_clear_ble_keys (p_dev_rec);
#endif #endif
}
} }
/******************************************************************************* /*******************************************************************************

View file

@ -1062,7 +1062,7 @@ void btm_report_device_status (tBTM_DEV_STATUS status);
BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr); BOOLEAN btm_dev_support_switch (BD_ADDR bd_addr);
tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr); tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr);
void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec); void btm_sec_free_dev (tBTM_SEC_DEV_REC *p_dev_rec, tBT_TRANSPORT transport);
tBTM_SEC_DEV_REC *btm_find_dev (BD_ADDR bd_addr); tBTM_SEC_DEV_REC *btm_find_dev (BD_ADDR bd_addr);
tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr); tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr);
tBTM_SEC_DEV_REC *btm_find_dev_by_handle (UINT16 handle); tBTM_SEC_DEV_REC *btm_find_dev_by_handle (UINT16 handle);

View file

@ -3417,8 +3417,7 @@ BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class,
** **
*******************************************************************************/ *******************************************************************************/
//extern //extern
BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr); BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport);
/******************************************************************************* /*******************************************************************************
** **