]> granicus.if.org Git - esp-idf/commitdiff
component/bt: Fix bug of remove bond device fail when BLE and BT are connectd at...
authorbaohongde <baohongde@espressif.com>
Mon, 16 Jul 2018 07:43:01 +0000 (15:43 +0800)
committerbaohongde <baohongde@espressif.com>
Mon, 16 Jul 2018 07:46:27 +0000 (15:46 +0800)
components/bt/bluedroid/bta/dm/bta_dm_act.c
components/bt/bluedroid/stack/btm/btm_dev.c
components/bt/bluedroid/stack/btm/include/btm_int.h
components/bt/bluedroid/stack/include/stack/btm_api.h

index 5b79e9b8a4039fcf88bcad26847de7bb8ec4205b..6ffeb9bbd4a44fbc33c5f609c92e71b8520a5102 100644 (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);
 #endif
 
-    BTM_SecDeleteDevice(bd_addr);
+    BTM_SecDeleteDevice(bd_addr, transport);
 
 #if (BLE_INCLUDED == TRUE && GATTC_INCLUDED == TRUE)
     /* 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 */
         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;
                 btm_remove_acl( p_dev->bd_addr, bta_dm_cb.device_list.peer_device[i].transport);
                 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 */
     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.");
         }
 #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 (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;
                 }
 
@@ -3347,7 +3348,7 @@ void bta_dm_acl_change(tBTA_DM_MSG *p_data)
             }
         }
         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)
             /* need to remove all pending background connection */
             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__);
         }
     } 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)
         /* need to remove all pending background connection */
         BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE);
index c7427863ea71baf4cbef4f04c762bd2be30d0b28..d8073e112e0e9b7dc94adc0b9f813fb7db02d7ac 100644 (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.
 **
 ** 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
 **
 *******************************************************************************/
-BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr)
+BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport)
 {
+
     tBTM_SEC_DEV_REC *p_dev_rec;
 
-    if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE) ||
-            BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_BR_EDR)) {
+    if (BTM_IsAclConnectionUp(bd_addr, transport)) {
         BTM_TRACE_WARNING("%s FAILED: Cannot Delete when connection is active\n", __func__);
         return FALSE;
     }
-
     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 */
         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
 **
 *******************************************************************************/
-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)
 {
-    p_dev_rec->bond_type = BOND_TYPE_UNKNOWN;
-    p_dev_rec->sec_flags = 0;
-
+    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->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);
+        /* 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;
 
-
+#if BLE_INCLUDED == TRUE
+        /* Clear out any saved BLE keys */
+        btm_sec_clear_ble_keys (p_dev_rec);
+#endif
+    }
 }
 
 /*******************************************************************************
index bde7af9a2e12d9af7b89d63756ad16e59fd72130..0af1006f8d1f42fae09996bcf0c3cadd0bd7537e 100644 (file)
@@ -491,10 +491,10 @@ typedef struct {
     bool skip_update_conn_param;        /* skip update connection paraams or not*/
 #endif
 #if (BLE_PRIVACY_SPT == TRUE)
-    tBLE_ADDR_TYPE      current_addr_type; /* current adv addr type*/  
+    tBLE_ADDR_TYPE      current_addr_type; /* current adv addr type*/
     BD_ADDR             current_addr;      /* current adv addr*/
     bool                current_addr_valid; /* current addr info is valid or not*/
-#endif   
+#endif
 } tBTM_SEC_BLE;
 
 
@@ -1062,7 +1062,7 @@ void btm_report_device_status (tBTM_DEV_STATUS status);
 BOOLEAN btm_dev_support_switch (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_or_alloc_dev (BD_ADDR bd_addr);
 tBTM_SEC_DEV_REC  *btm_find_dev_by_handle (UINT16 handle);
index 067878a8e13a8155d2c4fcd4781ad34f2a32862a..c483268aec12bac61c99551c8c2c16ddb8b1c1db 100644 (file)
@@ -3417,8 +3417,7 @@ BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class,
 **
 *******************************************************************************/
 //extern
-BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr);
-
+BOOLEAN BTM_SecDeleteDevice (BD_ADDR bd_addr, tBT_TRANSPORT transport);
 
 /*******************************************************************************
 **