/******************************************************************************* ** ** 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; }
/******************************************************************************* ** ** Function btm_update_dev_to_white_list ** ** Description This function adds a device into white list. *******************************************************************************/ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type) { /* look up the sec device record, and find the address */ tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; tBTM_SEC_DEV_REC *p_dev_rec; BD_ADDR dummy_bda = {0}; BOOLEAN started = FALSE, suspend = FALSE; if (btm_cb.btm_inq_vars.inq_active) { suspend = TRUE; btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); } if ((p_dev_rec = btm_find_dev (bd_addr)) != NULL && p_dev_rec->device_type == BT_DEVICE_TYPE_BLE) { BTM_TRACE_DEBUG0("btm_update_dev_to_white_list 1"); if ((to_add && p_cb->num_empty_filter == 0) || (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries)) { BTM_TRACE_ERROR1("num_entry available in controller: %d", p_cb->num_empty_filter); return started; } if ( p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC) { if (to_add) started = btsnd_hcic_ble_add_white_list (BLE_ADDR_PUBLIC, bd_addr); else started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_PUBLIC, bd_addr); } else { if (BLE_ADDR_IS_STATIC(bd_addr)) { if (to_add) started = btsnd_hcic_ble_add_white_list (BLE_ADDR_RANDOM, bd_addr); else started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_RANDOM, bd_addr); } if (memcmp(p_dev_rec->ble.reconn_addr, dummy_bda, BD_ADDR_LEN) != 0) { if (to_add) started = btsnd_hcic_ble_add_white_list (BLE_ADDR_RANDOM, p_dev_rec->ble.reconn_addr); else started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_RANDOM, p_dev_rec->ble.reconn_addr); } } } /* if not a known device, shall we add it? */ else { if (to_add) started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr); else started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr); } if (suspend) { btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, BTM_BLE_DUPLICATE_DISABLE); } return started; }
/******************************************************************************* ** ** Function btm_ble_start_select_conn ** ** Description This function is to start/stop selective connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** p_select_cback: callback function to return application ** selection. ** ** Returns BOOLEAN: selective connectino procedure is started. ** *******************************************************************************/ BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cback) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UINT32 scan_int = p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; UINT32 scan_win = p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; BTM_TRACE_EVENT ("%s", __func__); if (start) { if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) { if (p_select_cback != NULL) btm_cb.ble_ctr_cb.p_select_cback = p_select_cback; btm_execute_wl_dev_operation(); btm_update_scanner_filter_policy(SP_ADV_WL); btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS; /* Process advertising packets only from devices in the white list */ if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) { /* use passive scan by default */ if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, scan_int, scan_win, p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL)) { return FALSE; } } else { if (!btm_ble_send_extended_scan_params(BTM_BLE_SCAN_MODE_PASS, scan_int, scan_win, p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL)) { return FALSE; } } if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) { BTM_TRACE_ERROR("peripheral device cannot initiate passive scan for a selective connection"); return FALSE; } else if (background_connections_pending()) { #if BLE_PRIVACY_SPT == TRUE btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); #endif if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */ return FALSE; /* mark up inquiry status flag */ p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE; p_cb->wl_state |= BTM_BLE_WL_SCAN; } } else { BTM_TRACE_ERROR("scan active, can not start selective connection procedure"); return FALSE; } } else /* disable selective connection mode */ { p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE; p_cb->p_select_cback = NULL; p_cb->wl_state &= ~BTM_BLE_WL_SCAN; /* stop scanning */ if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) btm_ble_stop_scan(); /* duplicate filtering enabled */ } return TRUE; }
/******************************************************************************* ** ** Function btm_ble_start_select_conn ** ** Description This function is to start/stop selective connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** p_select_cback: callback function to return application ** selection. ** ** Returns BOOLEAN: selective connectino procedure is started. ** *******************************************************************************/ BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK *p_select_cback) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UINT16 scan_int, scan_win; BTM_TRACE_EVENT0 ("btm_ble_start_select_conn"); scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_INT : p_cb->scan_int; scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_WIND : p_cb->scan_win; if (start) { if (!btm_cb.btm_inq_vars.inq_active) { btm_cb.ble_ctr_cb.p_select_cback = p_select_cback; btm_update_scanner_filter_policy(SP_ADV_WL); if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, /* use passive scan by default */ scan_int, /* scan interval */ scan_win, /* scan window */ BLE_ADDR_PUBLIC, /* own device, DUMO always use public */ SP_ADV_WL) /* process advertising packets only from devices in the White List */ ) return FALSE; if (p_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE) { BTM_TRACE_ERROR0("peripheral device cannot initiate a selective connection"); return FALSE; } else if (p_cb->bg_conn_dev_num > 0 && btm_ble_count_unconn_dev_in_whitelist() > 0 ) { if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */ return FALSE; /* mark up inquiry status flag */ btm_cb.btm_inq_vars.inq_active = TRUE; btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_SELECT_SCAN; p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE; } } else { BTM_TRACE_ERROR0("scan active, can not start selective connection procedure"); return FALSE; } } else /* disable selective connection mode */ { p_cb->p_select_cback = NULL; btm_cb.btm_inq_vars.inq_active = FALSE; btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE; btm_update_scanner_filter_policy(SP_ADV_ALL); /* stop scanning */ if (p_cb->bg_conn_dev_num > 0) { if (!btsnd_hcic_ble_set_scan_enable(FALSE, TRUE)) /* duplicate filtering enabled */ return FALSE; } } return TRUE; }
/******************************************************************************* ** ** Function btm_ble_start_select_conn ** ** Description This function is to start/stop selective connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** p_select_cback: callback function to return application ** selection. ** ** Returns BOOLEAN: selective connectino procedure is started. ** *******************************************************************************/ BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK *p_select_cback) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UINT16 scan_int, scan_win; BTM_TRACE_EVENT ("btm_ble_start_select_conn"); scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; if (start) { if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) { if (p_select_cback != NULL) btm_cb.ble_ctr_cb.p_select_cback = p_select_cback; btm_execute_wl_dev_operation(); btm_update_scanner_filter_policy(SP_ADV_WL); btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS; if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, /* use passive scan by default */ scan_int, /* scan interval */ scan_win, /* scan window */ p_cb->addr_mgnt_cb.own_addr_type, SP_ADV_WL) /* process advertising packets only from devices in the White List */ ) return FALSE; if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) { BTM_TRACE_ERROR("peripheral device cannot initiate passive scan for a selective connection"); return FALSE; } else if (p_cb->bg_dev_num > 0 && btm_ble_count_unconn_dev_in_whitelist() > 0 ) { if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */ return FALSE; /* mark up inquiry status flag */ p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE; p_cb->wl_state |= BTM_BLE_WL_SCAN; } } else { BTM_TRACE_ERROR("scan active, can not start selective connection procedure"); return FALSE; } } else /* disable selective connection mode */ { p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE; p_cb->p_select_cback = NULL; #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) if (btm_cb.cmn_ble_vsc_cb.rpa_offloading == TRUE) btm_ble_vendor_disable_irk_list(); #endif p_cb->wl_state |= BTM_BLE_WL_SCAN; /* stop scanning */ if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) btm_ble_stop_scan(); /* duplicate filtering enabled */ btm_update_scanner_filter_policy(SP_ADV_ALL); } return TRUE; }