Skip to content

Commit

Permalink
Merge branch 'fix/btc_config_lock_error_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
fix(bt/bluedroid): fixed btc_config_lock error (backport v5.1)

See merge request espressif/esp-idf!28070
  • Loading branch information
jack0c committed Dec 25, 2023
2 parents 0854554 + 83a99d9 commit df8cc9a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 29 deletions.
3 changes: 2 additions & 1 deletion components/bt/host/bluedroid/btc/core/btc_dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,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));
Expand All @@ -722,7 +723,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, &param);
Expand Down
52 changes: 26 additions & 26 deletions components/bt/host/bluedroid/btc/core/btc_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,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

/*******************************************************************************
Expand Down Expand Up @@ -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;
}

/*******************************************************************************
**
** 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)
/*******************************************************************************
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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)) {
Expand All @@ -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;
Expand Down

0 comments on commit df8cc9a

Please sign in to comment.