From 265b54a01504a1543adbc595768ff1a083e01600 Mon Sep 17 00:00:00 2001 From: gongyantao Date: Fri, 15 Dec 2023 10:58:22 +0800 Subject: [PATCH] fix(bt/bluedroid): fixed btc_config_lock error --- .../bt/host/bluedroid/btc/core/btc_dm.c | 3 +- .../bt/host/bluedroid/btc/core/btc_storage.c | 52 +++++++++---------- .../btc/profile/std/gatt/btc_gattc.c | 3 +- .../btc/profile/std/gatt/btc_gatts.c | 3 +- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/components/bt/host/bluedroid/btc/core/btc_dm.c b/components/bt/host/bluedroid/btc/core/btc_dm.c index c712efe423..ce31b4e2f6 100644 --- a/components/bt/host/bluedroid/btc/core/btc_dm.c +++ b/components/bt/host/bluedroid/btc/core/btc_dm.c @@ -720,6 +720,7 @@ static void btc_dm_acl_link_stat(tBTA_DM_ACL_LINK_STAT *p_acl_link_stat) } } +#if (SMP_INCLUDED == TRUE) if (p_acl_link_stat->event == BTA_ACL_LINK_STAT_CONN_CMPL && p_acl_link_stat->link_act.conn_cmpl.status == HCI_SUCCESS) { memcpy(bt_addr.address, p_acl_link_stat->link_act.conn_cmpl.bd_addr, sizeof(bt_addr.address)); @@ -730,7 +731,7 @@ static void btc_dm_acl_link_stat(tBTA_DM_ACL_LINK_STAT *p_acl_link_stat) bt_addr.address[4], bt_addr.address[5]); } } - +#endif ///SMP_INCLUDED == TRUE esp_bt_gap_cb_t cb = (esp_bt_gap_cb_t)btc_profile_cb_get(BTC_PID_GAP_BT); if (cb) { cb(event, ¶m); diff --git a/components/bt/host/bluedroid/btc/core/btc_storage.c b/components/bt/host/bluedroid/btc/core/btc_storage.c index 16fc2a2f47..1aa0a3eb19 100644 --- a/components/bt/host/bluedroid/btc/core/btc_storage.c +++ b/components/bt/host/bluedroid/btc/core/btc_storage.c @@ -204,6 +204,32 @@ bt_status_t btc_storage_load_bonded_devices(void) BTC_TRACE_DEBUG("Storage load rslt %d\n", status); return status; } + +/******************************************************************************* +** +** Function btc_storage_update_active_device +** +** Description BTC storage API - Once an ACL link is established and remote +** bd_addr is already stored in NVRAM, update the config and update +** the remote device to be the newest active device, The updates will +** not be stored into NVRAM immediately. +** +** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise +** +*******************************************************************************/ +bool btc_storage_update_active_device(bt_bdaddr_t *remote_bd_addr) +{ + bdstr_t bdstr; + bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr)); + bool ret = false; + BTC_TRACE_DEBUG("Update active device: Remote device:%s\n", bdstr); + + btc_config_lock(); + ret = btc_config_update_newest_section(bdstr); + btc_config_unlock(); + + return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; +} #endif ///SMP_INCLUDED == TRUE /******************************************************************************* @@ -316,32 +342,6 @@ bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int *d return BT_STATUS_SUCCESS; } -/******************************************************************************* -** -** Function btc_storage_update_active_device -** -** Description BTC storage API - Once an ACL link is established and remote -** bd_addr is already stored in NVRAM, update the config and update -** the remote device to be the newest active device, The updates will -** not be stored into NVRAM immediately. -** -** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise -** -*******************************************************************************/ -bool btc_storage_update_active_device(bt_bdaddr_t *remote_bd_addr) -{ - bdstr_t bdstr; - bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr)); - bool ret = false; - BTC_TRACE_DEBUG("Update active device: Remote device:%s\n", bdstr); - - btc_config_lock(); - ret = btc_config_update_newest_section(bdstr); - btc_config_unlock(); - - return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; -} - #if (defined BTC_HH_INCLUDED && BTC_HH_INCLUDED == TRUE) /******************************************************************************* * diff --git a/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c b/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c index c5eaa826a7..4744707c81 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c +++ b/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c @@ -926,6 +926,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg) } case BTA_GATTC_CONNECT_EVT: { tBTA_GATTC_CONNECT *connect = &arg->connect; +#if (SMP_INCLUDED == TRUE) bt_bdaddr_t bt_addr; memcpy(bt_addr.address, connect->remote_bda, sizeof(bt_addr.address)); @@ -935,7 +936,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg) bt_addr.address[2], bt_addr.address[3], bt_addr.address[4], bt_addr.address[5]); } - +#endif ///SMP_INCLUDED == TRUE gattc_if = connect->client_if; param.connect.conn_id = BTC_GATT_GET_CONN_ID(connect->conn_id); param.connect.link_role = connect->link_role; diff --git a/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c b/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c index ba3256d1e7..532078cdeb 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c +++ b/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gatts.c @@ -901,6 +901,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) btc_gatts_cb_to_app(ESP_GATTS_STOP_EVT, gatts_if, ¶m); break; case BTA_GATTS_CONNECT_EVT: { +#if (SMP_INCLUDED == TRUE) bt_bdaddr_t bt_addr; memcpy(bt_addr.address, p_data->conn.remote_bda, sizeof(bt_addr.address)); if (btc_storage_update_active_device(&bt_addr)) { @@ -909,7 +910,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg) bt_addr.address[2], bt_addr.address[3], bt_addr.address[4], bt_addr.address[5]); } - +#endif ///SMP_INCLUDED == TRUE gatts_if = p_data->conn.server_if; param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id); param.connect.link_role = p_data->conn.link_role;