Merge branch 'fix/btc_config_lock_error_v5.2' into 'release/v5.2'

fix(bt/bluedroid): fixed btc_config_lock error (backport v5.2)

See merge request espressif/esp-idf!28069
This commit is contained in:
Jiang Jiang Jian
2023-12-25 20:34:34 +08:00
5 changed files with 34 additions and 31 deletions

View File

@@ -264,13 +264,13 @@ bool config_update_newest_section(config_t *config, const char *section)
return false; return false;
} }
section_t *first_sec = list_node(first_node); section_t *first_sec = list_node(first_node);
if (!strcmp(first_sec->name, section)) { if (strcmp(first_sec->name, section) == 0) {
return true; return true;
} }
for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) { for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) {
section_t *sec = list_node(node); section_t *sec = list_node(node);
if (!strcmp(sec->name, section)) { if (strcmp(sec->name, section) == 0) {
list_delete(config->sections, sec); list_delete(config->sections, sec);
list_prepend(config->sections, sec); list_prepend(config->sections, sec);
return true; return true;

View File

@@ -706,6 +706,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 && if (p_acl_link_stat->event == BTA_ACL_LINK_STAT_CONN_CMPL &&
p_acl_link_stat->link_act.conn_cmpl.status == HCI_SUCCESS) { 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)); memcpy(bt_addr.address, p_acl_link_stat->link_act.conn_cmpl.bd_addr, sizeof(bt_addr.address));
@@ -716,7 +717,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]); 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); esp_bt_gap_cb_t cb = (esp_bt_gap_cb_t)btc_profile_cb_get(BTC_PID_GAP_BT);
if (cb) { if (cb) {
cb(event, &param); cb(event, &param);

View File

@@ -196,6 +196,32 @@ bt_status_t btc_storage_load_bonded_devices(void)
BTC_TRACE_DEBUG("Storage load rslt %d\n", status); BTC_TRACE_DEBUG("Storage load rslt %d\n", status);
return 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 #endif ///SMP_INCLUDED == TRUE
/******************************************************************************* /*******************************************************************************
@@ -308,32 +334,6 @@ bt_status_t btc_storage_get_bonded_bt_devices_list(bt_bdaddr_t *bond_dev, int *d
return BT_STATUS_SUCCESS; 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) #if (defined BTC_HH_INCLUDED && BTC_HH_INCLUDED == TRUE)
/******************************************************************************* /*******************************************************************************
* *

View File

@@ -926,6 +926,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
} }
case BTA_GATTC_CONNECT_EVT: { case BTA_GATTC_CONNECT_EVT: {
tBTA_GATTC_CONNECT *connect = &arg->connect; tBTA_GATTC_CONNECT *connect = &arg->connect;
#if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bt_addr; bt_bdaddr_t bt_addr;
memcpy(bt_addr.address, connect->remote_bda, sizeof(bt_addr.address)); 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[2], bt_addr.address[3],
bt_addr.address[4], bt_addr.address[5]); bt_addr.address[4], bt_addr.address[5]);
} }
#endif ///SMP_INCLUDED == TRUE
gattc_if = connect->client_if; gattc_if = connect->client_if;
param.connect.conn_id = BTC_GATT_GET_CONN_ID(connect->conn_id); param.connect.conn_id = BTC_GATT_GET_CONN_ID(connect->conn_id);
param.connect.link_role = connect->link_role; param.connect.link_role = connect->link_role;

View File

@@ -901,6 +901,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
btc_gatts_cb_to_app(ESP_GATTS_STOP_EVT, gatts_if, &param); btc_gatts_cb_to_app(ESP_GATTS_STOP_EVT, gatts_if, &param);
break; break;
case BTA_GATTS_CONNECT_EVT: { case BTA_GATTS_CONNECT_EVT: {
#if (SMP_INCLUDED == TRUE)
bt_bdaddr_t bt_addr; bt_bdaddr_t bt_addr;
memcpy(bt_addr.address, p_data->conn.remote_bda, sizeof(bt_addr.address)); memcpy(bt_addr.address, p_data->conn.remote_bda, sizeof(bt_addr.address));
if (btc_storage_update_active_device(&bt_addr)) { 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[2], bt_addr.address[3],
bt_addr.address[4], bt_addr.address[5]); bt_addr.address[4], bt_addr.address[5]);
} }
#endif ///SMP_INCLUDED == TRUE
gatts_if = p_data->conn.server_if; gatts_if = p_data->conn.server_if;
param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id); param.connect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
param.connect.link_role = p_data->conn.link_role; param.connect.link_role = p_data->conn.link_role;