components/bt/host/bluedroid/stack/btm/btm_sec.c
/*******************************************************************************
 * disconnect the ACL link, if it's not done yet.
*******************************************************************************/
disconnect the ACL link, if it's not done yet.
disconnect the ACL link if it ' s not done yet .
static tBTM_STATUS btm_sec_send_hci_disconnect (tBTM_SEC_DEV_REC *p_dev_rec, UINT8 reason, UINT16 conn_handle)
{
    UINT8       old_state = p_dev_rec->sec_state;
    tBTM_STATUS status = BTM_CMD_STARTED;
    BTM_TRACE_EVENT ("btm_sec_send_hci_disconnect:  handle:0x%x, reason=0x%x\n",
                     conn_handle, reason);
    switch (old_state) {
    case BTM_SEC_STATE_DISCONNECTING:
        if (conn_handle == p_dev_rec->hci_handle) {
            return status;
        }
        p_dev_rec->sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH;
        break;
#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
    case BTM_SEC_STATE_DISCONNECTING_BLE:
        if (conn_handle == p_dev_rec->ble_hci_handle) {
            return status;
        }
        p_dev_rec->sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH;
        break;
    case BTM_SEC_STATE_DISCONNECTING_BOTH:
        return status;
#endif
    default:
        p_dev_rec->sec_state = (conn_handle == p_dev_rec->hci_handle) ?
                               BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE;
        break;
    }
    if (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING && p_dev_rec->hci_handle == conn_handle) {
        BTM_TRACE_DEBUG("RS in progress - Set DISC Pending flag in btm_sec_send_hci_disconnect to delay disconnect\n");
        p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING;
        status = BTM_SUCCESS;
    }
    else if (!btsnd_hcic_disconnect (conn_handle, reason)) {
        p_dev_rec->sec_state = old_state;
        status = BTM_NO_RESOURCES;
    }
    return status;
}
static tBTM_STATUS btm_sec_send_hci_disconnect ( tBTM_SEC_DEV_REC * p_dev_rec , UINT8 reason , UINT16 conn_handle ) { UINT8 old_state = p_dev_rec -> sec_state ; tBTM_STATUS status = BTM_CMD_STARTED ; BTM_TRACE_EVENT ( " \n " , conn_handle , reason ) ; switch ( old_state ) { case BTM_SEC_STATE_DISCONNECTING : if ( conn_handle == p_dev_rec -> hci_handle ) { return status ; } p_dev_rec -> sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH ; break ; #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE case BTM_SEC_STATE_DISCONNECTING_BLE : if ( conn_handle == p_dev_rec -> ble_hci_handle ) { return status ; } p_dev_rec -> sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH ; break ; case BTM_SEC_STATE_DISCONNECTING_BOTH : return status ; #endif default : p_dev_rec -> sec_state = ( conn_handle == p_dev_rec -> hci_handle ) ? BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE ; break ; } if ( p_dev_rec -> rs_disc_pending == BTM_SEC_RS_PENDING && p_dev_rec -> hci_handle == conn_handle ) { BTM_TRACE_DEBUG ( " \n " ) ; p_dev_rec -> rs_disc_pending = BTM_SEC_DISC_PENDING ; status = BTM_SUCCESS ; } else if ( ! btsnd_hcic_disconnect ( conn_handle , reason ) ) { p_dev_rec -> sec_state = old_state ; status = BTM_NO_RESOURCES ; } return status ; }
disconnect the ACL link, if it's not done yet.
disconnect the ACL link if it ' s not done yet .
/* send HCI_Disconnect on a transport only once */ /* If a role switch is in progress, delay the HCI Disconnect to avoid controller problem */ /* Tear down the HCI link */ /* could not send disconnect. restore old state */