fix(ble/bluedroid): Fixed reconnection failed with extend adv
(cherry picked from commit ec4052c1c7125ab1bc4223bc507e6e778d37728c) Co-authored-by: zhiweijian <zhiweijian@espressif.com>
This commit is contained in:
@@ -377,6 +377,9 @@ BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason)
|
||||
#endif ///BLE_INCLUDED == TRUE
|
||||
status = FALSE;
|
||||
} else {
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
tL2C_LINK_STATE link_state_temp = p_lcb->link_state;
|
||||
#endif // (BLE_INCLUDED == TRUE)
|
||||
/* There can be a case when we rejected PIN code authentication */
|
||||
/* otherwise save a new reason */
|
||||
if (btm_cb.acl_disc_reason != HCI_ERR_HOST_REJECT_SECURITY) {
|
||||
@@ -471,46 +474,54 @@ BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason)
|
||||
|
||||
p_lcb->p_pending_ccb = NULL;
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
if(reason == HCI_ERR_CONN_FAILED_ESTABLISHMENT && p_lcb->transport == BT_TRANSPORT_LE) {
|
||||
#if (GATTC_CONNECT_RETRY_EN == TRUE)
|
||||
if(p_lcb->link_role == HCI_ROLE_MASTER && p_lcb->retry_create_con < GATTC_CONNECT_RETRY_COUNT) {
|
||||
L2CAP_TRACE_DEBUG("master retry connect, retry count %d reason 0x%x\n", p_lcb->retry_create_con, reason);
|
||||
p_lcb->retry_create_con ++;
|
||||
// create connection retry
|
||||
if (l2cu_create_conn(p_lcb, BT_TRANSPORT_LE)) {
|
||||
btm_acl_removed (p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
|
||||
lcb_is_free = FALSE; /* still using this lcb */
|
||||
} else {
|
||||
L2CAP_TRACE_ERROR("master retry connect failed");
|
||||
}
|
||||
}
|
||||
#endif // (GATTC_CONNECT_RETRY_EN == TRUE)
|
||||
if(p_lcb->transport == BT_TRANSPORT_LE) {
|
||||
// for legacy adv, adv restart in gatt_le_connect_cback->gatt_cleanup_upon_disc->BTM_Recovery_Pre_State
|
||||
if (reason == HCI_ERR_CONN_FAILED_ESTABLISHMENT) {
|
||||
|
||||
#if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
#if (BLE_50_EXTEND_ADV_EN == TRUE)
|
||||
if(btm_ble_inter_get() && p_lcb->link_role == HCI_ROLE_SLAVE) {
|
||||
p_lcb->retry_create_con ++;
|
||||
L2CAP_TRACE_DEBUG("slave restart extend adv, retry count %d reason 0x%x\n", p_lcb->retry_create_con, reason);
|
||||
tBTM_STATUS start_adv_status = BTM_BleStartExtAdvRestart(handle);
|
||||
if (start_adv_status != BTM_SUCCESS) {
|
||||
L2CAP_TRACE_ERROR("slave restart extend adv failed (err 0x%x)", start_adv_status);
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
#if (BLE_42_ADV_EN == TRUE)
|
||||
if(!btm_ble_inter_get() && p_lcb->link_role == HCI_ROLE_SLAVE) {
|
||||
L2CAP_TRACE_DEBUG("slave resatrt adv, retry count %d reason 0x%x\n", p_lcb->retry_create_con, reason);
|
||||
tBTM_STATUS start_adv_status = btm_ble_start_adv();
|
||||
if (start_adv_status != BTM_SUCCESS) {
|
||||
L2CAP_TRACE_ERROR("slave resatrt adv failed (err 0x%x)", start_adv_status);
|
||||
}
|
||||
}
|
||||
#endif // #if (BLE_42_ADV_EN == TRUE)
|
||||
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
}
|
||||
#endif // #if (BLE_50_EXTEND_ADV_EN == TRUE)
|
||||
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
// try to reconnect for master
|
||||
if ((reason == HCI_ERR_CONN_FAILED_ESTABLISHMENT) || (link_state_temp == LST_CONNECTING)) {
|
||||
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
#if (BLE_42_ADV_EN == TRUE)
|
||||
if(!btm_ble_inter_get() && p_lcb->link_role == HCI_ROLE_SLAVE) {
|
||||
p_lcb->retry_create_con ++;
|
||||
L2CAP_TRACE_DEBUG("slave resatrt adv, retry count %d reason 0x%x\n", p_lcb->retry_create_con, reason);
|
||||
tBTM_STATUS start_adv_status = btm_ble_start_adv();
|
||||
if (start_adv_status != BTM_SUCCESS) {
|
||||
L2CAP_TRACE_ERROR("slave resatrt adv failed (err 0x%x)", start_adv_status);
|
||||
#if (GATTC_CONNECT_RETRY_EN == TRUE)
|
||||
if(p_lcb->link_role == HCI_ROLE_MASTER && p_lcb->retry_create_con < GATTC_CONNECT_RETRY_COUNT) {
|
||||
L2CAP_TRACE_DEBUG("master retry connect, retry count %d reason 0x%x\n", p_lcb->retry_create_con, reason);
|
||||
p_lcb->retry_create_con ++;
|
||||
// create connection retry
|
||||
if (l2cu_create_conn(p_lcb, BT_TRANSPORT_LE)) {
|
||||
btm_acl_removed (p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
|
||||
lcb_is_free = FALSE; /* still using this lcb */
|
||||
} else {
|
||||
L2CAP_TRACE_ERROR("master retry connect failed");
|
||||
}
|
||||
}
|
||||
#endif // (GATTC_CONNECT_RETRY_EN == TRUE)
|
||||
}
|
||||
#endif // #if (BLE_42_ADV_EN == TRUE)
|
||||
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
// try to restart extended adv for slave
|
||||
if ((reason == HCI_ERR_CONN_FAILED_ESTABLISHMENT) || (link_state_temp == LST_DISCONNECTED)) {
|
||||
#if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
#if (BLE_50_EXTEND_ADV_EN == TRUE)
|
||||
if(btm_ble_inter_get() && p_lcb->link_role == HCI_ROLE_SLAVE) {
|
||||
L2CAP_TRACE_DEBUG("slave restart extend adv, retry count %d reason 0x%x\n", p_lcb->retry_create_con, reason);
|
||||
tBTM_STATUS start_adv_status = BTM_BleStartExtAdvRestart(handle);
|
||||
if (start_adv_status != BTM_SUCCESS) {
|
||||
L2CAP_TRACE_ERROR("slave restart extend adv failed (err 0x%x)", start_adv_status);
|
||||
}
|
||||
}
|
||||
#endif // #if (BLE_50_EXTEND_ADV_EN == TRUE)
|
||||
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user