Merge branch 'bugfix/fix_some_ble_bug_v5.1' into 'release/v5.1'

Fixed some BLE bugs (backport v5.1)

See merge request espressif/esp-idf!23699
This commit is contained in:
Jiang Jiang Jian 2023-05-18 20:08:25 +08:00
commit 7fcba0fbf8
7 changed files with 75 additions and 20 deletions

@ -1 +1 @@
Subproject commit a17e093350f31d09b8bcbfaad40b5b35535ea97b
Subproject commit d7513ebe88d7d207f6c062ce9381d347a0a70918

View File

@ -5102,7 +5102,7 @@ void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data)
*******************************************************************************/
void bta_dm_ble_disconnect (tBTA_DM_MSG *p_data)
{
L2CA_RemoveFixedChnl(L2CAP_ATT_CID, p_data->ble_disconnect.remote_bda);
L2CA_BleDisconnect(p_data->ble_disconnect.remote_bda);
}
/*******************************************************************************

View File

@ -389,7 +389,7 @@ void bta_dm_co_ble_set_init_key_req(UINT8 init_key)
{
#if (SMP_INCLUDED == TRUE)
init_key &= 0x0f; // 4~7bit reservd, only used the 0~3bit
bte_appl_cfg.ble_init_key &= init_key;
bte_appl_cfg.ble_init_key = init_key;
#endif ///SMP_INCLUDED == TRUE
}
@ -397,7 +397,7 @@ void bta_dm_co_ble_set_rsp_key_req(UINT8 rsp_key)
{
#if (SMP_INCLUDED == TRUE)
rsp_key &= 0x0f; // 4~7bit reservd, only used the 0~3bit
bte_appl_cfg.ble_resp_key &= rsp_key;
bte_appl_cfg.ble_resp_key = rsp_key;
#endif ///SMP_INCLUDED == TRUE
}

View File

@ -302,21 +302,19 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr)
BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK;
if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
&& memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0
&& memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0){
// set random address
if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)",
__func__, btm_ble_hci_status_to_str(err), err);
if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK) {
invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK;
if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) == 0
|| memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) == 0) {
status = BTM_ILLEGAL_VALUE;
} else {
// set random address success, update address infor
if(extend_adv_cb.inst[instance].configured && extend_adv_cb.inst[instance].connetable) {
BTM_BleSetStaticAddr(rand_addr);
BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr);
}
goto end;
}
} else if ((rand_addr[0] | BT_NON_RPA_MASK) == BT_NON_RPA_MASK) {
invalid_rand_addr_a[0] = invalid_rand_addr_a[0] & BT_NON_RPA_MASK;
if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) == 0
|| memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) == 0) {
status = BTM_ILLEGAL_VALUE;
goto end;
}
} else {
BTM_TRACE_ERROR("%s invalid random address", __func__);
@ -324,6 +322,19 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr)
goto end;
}
// set random address
if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)",
__func__, btm_ble_hci_status_to_str(err), err);
status = BTM_ILLEGAL_VALUE;
} else {
// set random address success, update address infor
if(extend_adv_cb.inst[instance].configured && extend_adv_cb.inst[instance].connetable) {
BTM_BleSetStaticAddr(rand_addr);
BTM_UpdateAddrInfor(BLE_ADDR_RANDOM, rand_addr);
}
}
end:
cb_params.status = status;

View File

@ -2237,9 +2237,10 @@ UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst,
#if BTM_MAX_LOC_BD_NAME_LEN > 0
if (len > MIN_ADV_LENGTH && data_mask & BTM_BLE_AD_BIT_DEV_NAME) {
if (strlen(btm_cb.cfg.bd_name) > (UINT16)(len - MIN_ADV_LENGTH)) {
*p++ = len - MIN_ADV_LENGTH + 1;
cp_len = (UINT16)(len - MIN_ADV_LENGTH);
*p++ = cp_len + 1;
*p++ = BTM_BLE_AD_TYPE_NAME_SHORT;
ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, len - MIN_ADV_LENGTH);
ARRAY_TO_STREAM(p, btm_cb.cfg.bd_name, cp_len);
} else {
cp_len = (UINT16)strlen(btm_cb.cfg.bd_name);
*p++ = cp_len + 1;

View File

@ -1215,6 +1215,19 @@ extern BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable);
**
*******************************************************************************/
extern UINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr);
/*******************************************************************************
**
** Function L2CA_BleDisconnect
**
** Description This function use to disconnect LE connection.
**
** Parameters BD Address of remote
**
** Returns TRUE if disconnect successfully.
**
*******************************************************************************/
extern BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda);
#endif /* (BLE_INCLUDED == TRUE) */
/*******************************************************************************

View File

@ -1949,6 +1949,36 @@ BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda)
return (TRUE);
}
#if BLE_INCLUDED == TRUE
BOOLEAN L2CA_BleDisconnect (BD_ADDR rem_bda)
{
tL2C_LCB *p_lcb;
tGATT_TCB *p_tcb;
p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE);
if (p_lcb == NULL) {
return FALSE;
}
if (p_lcb->link_state != LST_CONNECTED) {
return FALSE;
}
p_lcb->disc_reason = HCI_ERR_CONN_CAUSE_LOCAL_HOST;
p_lcb->link_state = LST_DISCONNECTING;
btsnd_hcic_disconnect (p_lcb->handle, HCI_ERR_PEER_USER);
p_tcb = gatt_find_tcb_by_addr(rem_bda, BT_TRANSPORT_LE);
if (p_tcb == NULL) {
return FALSE;
}
gatt_set_ch_state(p_tcb, GATT_CH_CLOSING);
return TRUE;
}
#endif
/*******************************************************************************
**
** Function L2CA_SetFixedChannelTout