/*******************************************************************************
**
** Function         btm_ble_suspend_bg_sele_conn
**
** Description      This function is to suspend an active background connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
void btm_ble_suspend_bg_sele_conn(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BTM_TRACE_EVENT0 ("btm_ble_suspend_bg_sele_conn");

    if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
    {
        p_cb->bg_conn_state = BLE_BG_CONN_SUSPEND;
        btm_ble_start_select_conn(FALSE, NULL);
    }
}
/*******************************************************************************
**
** Function         btm_ble_suspend_bg_conn
**
** Description      This function is to suspend an active background connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
BOOLEAN btm_ble_suspend_bg_conn(void)
{
    BTM_TRACE_EVENT ("%s", __func__);

    if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO)
        return btm_ble_start_auto_conn(FALSE);
    else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE)
        return btm_ble_start_select_conn(FALSE, NULL);

    return FALSE;
}
/*******************************************************************************
**
** Function         btm_ble_suspend_bg_conn
**
** Description      This function is to suspend an active background connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
void btm_ble_suspend_bg_conn(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BTM_TRACE_EVENT ("btm_ble_suspend_bg_conn");

    if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
    {
        btm_ble_start_auto_conn(FALSE);
    }
    else if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
    {
        btm_ble_start_select_conn(FALSE, NULL);
    }
}
/*******************************************************************************
**
** Function         btm_ble_resume_bg_conn
**
** Description      This function is to resume a background auto connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
BOOLEAN btm_ble_resume_bg_conn(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BOOLEAN ret = FALSE;

    if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE)
    {
        if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
            ret = btm_ble_start_auto_conn(TRUE);

        if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
            ret = btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback);
    }

    return ret;
}
/*******************************************************************************
**
** Function         btm_suspend_wl_activity
**
** Description      This function is to suspend white list related activity
**
** Returns          none.
**
*******************************************************************************/
static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state)
{
    if (wl_state & BTM_BLE_WL_INIT)
    {
        btm_ble_start_auto_conn(FALSE);
    }
    if (wl_state & BTM_BLE_WL_SCAN)
    {
        btm_ble_start_select_conn(FALSE, NULL);
    }
    if (wl_state & BTM_BLE_WL_ADV)
    {
        btm_ble_stop_adv();
    }

}
/*******************************************************************************
**
** Function         btm_suspend_wl_activity
**
** Description      This function is to suspend white list related activity
**
** Returns          none.
**
*******************************************************************************/
static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state)
{
    if (wl_state & BTM_BLE_WL_INIT)
    {
        btm_ble_start_auto_conn(FALSE);
    }
    if (wl_state & BTM_BLE_WL_SCAN)
    {
        btm_ble_start_select_conn(FALSE, NULL);
    }
    if (wl_state & BTM_BLE_WL_ADV)
    {
        btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_DISABLE);
    }

}
/*******************************************************************************
**
** Function         btm_ble_resume_bg_conn
**
** Description      This function is to resume a background auto connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
BOOLEAN btm_ble_resume_bg_conn(tBTM_BLE_SEL_CBACK *p_sele_callback, BOOLEAN def_param)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BOOLEAN ret = FALSE;

    if (p_cb->bg_conn_state != BLE_BG_CONN_ACTIVE )
    {
        if (def_param)
        {
            p_cb->scan_int = BTM_BLE_CONN_PARAM_UNDEF;
            p_cb->scan_win = BTM_BLE_CONN_PARAM_UNDEF;

            /* start scan param idle timer */
            btu_start_timer(&p_cb->scan_param_idle_timer,
                            BTU_TTYPE_BLE_SCAN_PARAM_IDLE,
                            BTM_BLE_SCAN_PARAM_TOUT);
        }

        if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
            ret = btm_ble_start_auto_conn(TRUE);

        if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
        {
            /* terminate selective connection mode if all devices are connected */
            if (btm_ble_count_unconn_dev_in_whitelist() == 0)
            {
                btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_DISABLE);
                btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE;
                btm_cb.btm_inq_vars.inq_active = FALSE;
            }
            else if (!btm_cb.btm_inq_vars.inq_active)
                btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback);
        }

        if (ret)
            p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;

    }

    return ret;
}