From 8e08097151c3401809e5f4658f0663f8726bc5b6 Mon Sep 17 00:00:00 2001 From: Yulong Date: Tue, 10 Oct 2017 02:29:54 -0400 Subject: [PATCH 1/3] component/bt: Fixed the bug when remove the bonded device with not exist address will not return error. --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 916547fd0..0f1b7568e 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -646,8 +646,12 @@ void bta_dm_process_remove_device(BD_ADDR bd_addr) if (bta_dm_cb.p_sec_cback) { tBTA_DM_SEC sec_event; bdcpy(sec_event.link_down.bd_addr, bd_addr); - /* No connection, set status to success (acl disc code not valid) */ - sec_event.link_down.status = HCI_SUCCESS; + if (btm_find_dev(bd_addr) != NULL) { + /* No connection, set status to success (acl disc code not valid) */ + sec_event.link_down.status = HCI_SUCCESS; + } else { + sec_event.link_down.status = HCI_ERR_ILLEGAL_COMMAND; + } bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event); } } From 25e8c09b6d0c9a324c046ea00b4fbc71baaf53a9 Mon Sep 17 00:00:00 2001 From: Yulong Date: Tue, 10 Oct 2017 04:02:05 -0400 Subject: [PATCH 2/3] component/bt: Change the param.remove_bond_dev_cmpl.status value. --- components/bt/bluedroid/bta/dm/bta_dm_act.c | 7 +------ components/bt/bluedroid/btc/core/btc_dm.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 0f1b7568e..366ae9336 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -646,12 +646,7 @@ void bta_dm_process_remove_device(BD_ADDR bd_addr) if (bta_dm_cb.p_sec_cback) { tBTA_DM_SEC sec_event; bdcpy(sec_event.link_down.bd_addr, bd_addr); - if (btm_find_dev(bd_addr) != NULL) { - /* No connection, set status to success (acl disc code not valid) */ - sec_event.link_down.status = HCI_SUCCESS; - } else { - sec_event.link_down.status = HCI_ERR_ILLEGAL_COMMAND; - } + sec_event.link_down.status = HCI_SUCCESS; bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event); } } diff --git a/components/bt/bluedroid/btc/core/btc_dm.c b/components/bt/bluedroid/btc/core/btc_dm.c index a0bc44ec3..b81d5bc7b 100644 --- a/components/bt/bluedroid/btc/core/btc_dm.c +++ b/components/bt/bluedroid/btc/core/btc_dm.c @@ -467,12 +467,15 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg) LOG_ERROR("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); - //remove the bonded key in the config and nvs flash. - btc_storage_remove_ble_dev_type(&bd_addr, false); - btc_storage_remove_remote_addr_type(&bd_addr, false); - btc_storage_remove_ble_bonding_keys(&bd_addr); + param.remove_bond_dev_cmpl.status = ESP_BT_STATUS_FAIL; + + if (p_data->link_down.status == HCI_SUCCESS) { + //remove the bonded key in the config and nvs flash. + btc_storage_remove_ble_dev_type(&bd_addr, false); + btc_storage_remove_remote_addr_type(&bd_addr, false); + param.remove_bond_dev_cmpl.status = btc_storage_remove_ble_bonding_keys(&bd_addr); + } ble_msg.act = ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT; - param.remove_bond_dev_cmpl.status = (p_data->link_down.status == HCI_SUCCESS) ? ESP_BT_STATUS_SUCCESS : ESP_BT_STATUS_FAIL; memcpy(param.remove_bond_dev_cmpl.bd_addr, p_data->link_down.bd_addr, sizeof(BD_ADDR)); #endif /* #if (SMP_INCLUDED == TRUE) */ break; From fc359e4491daefb24039c4ac4724a088bbcc7b08 Mon Sep 17 00:00:00 2001 From: Yulong Date: Tue, 10 Oct 2017 04:19:11 -0400 Subject: [PATCH 3/3] component/bt: Change the _btc_storage_remove_ble_bonding_keys function ret default vaule from 1 to 0. --- components/bt/bluedroid/btc/core/btc_ble_storage.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/bt/bluedroid/btc/core/btc_ble_storage.c b/components/bt/bluedroid/btc/core/btc_ble_storage.c index 538e97835..3e7238cc4 100644 --- a/components/bt/bluedroid/btc/core/btc_ble_storage.c +++ b/components/bt/bluedroid/btc/core/btc_ble_storage.c @@ -184,29 +184,29 @@ bt_status_t btc_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr, *******************************************************************************/ static bt_status_t _btc_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr) { - int ret = 1; + int ret = 0; bdstr_t bdstr; bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr)); BTIF_TRACE_DEBUG(" %s in bd addr:%s",__FUNCTION__, bdstr); if (btc_config_exist(bdstr, BTC_BLE_STORAGE_ADDR_TYPE_STR)) { - ret &= btc_config_remove(bdstr, BTC_BLE_STORAGE_ADDR_TYPE_STR); + ret |= btc_config_remove(bdstr, BTC_BLE_STORAGE_ADDR_TYPE_STR); } if (btc_config_exist(bdstr, BTC_BLE_STORAGE_LE_KEY_PENC_STR)) { - ret &= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_PENC_STR); + ret |= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_PENC_STR); } if (btc_config_exist(bdstr, BTC_BLE_STORAGE_LE_KEY_PID_STR)) { - ret &= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_PID_STR); + ret |= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_PID_STR); } if (btc_config_exist(bdstr, BTC_BLE_STORAGE_LE_KEY_PCSRK_STR)) { - ret &= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_PCSRK_STR); + ret |= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_PCSRK_STR); } if (btc_config_exist(bdstr, BTC_BLE_STORAGE_LE_KEY_LENC_STR)) { - ret &= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_LENC_STR); + ret |= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_LENC_STR); } if (btc_config_exist(bdstr, BTC_BLE_STORAGE_LE_KEY_LCSRK_STR)) { - ret &= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_LCSRK_STR); + ret |= btc_config_remove(bdstr, BTC_BLE_STORAGE_LE_KEY_LCSRK_STR); } //here don't remove section, because config_save will check it _btc_storage_save();