/******************************************************************************* ** ** Function btm_ble_start_auto_conn ** ** Description This function is to start/stop auto connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** ** Returns void ** *******************************************************************************/ BOOLEAN btm_ble_start_auto_conn(BOOLEAN start) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; BD_ADDR dummy_bda = {0}; BOOLEAN exec = TRUE; UINT16 scan_int, scan_win; 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 (!l2cb.is_ble_connecting && btm_ble_count_unconn_dev_in_whitelist() > 0) { if (p_cb->bg_conn_state != BLE_BG_CONN_ACTIVE && p_cb->bg_conn_dev_num > 0) { if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ 0x01, /* UINT8 white_list */ BLE_ADDR_PUBLIC, /* UINT8 addr_type_peer */ dummy_bda, /* BD_ADDR bda_peer */ BLE_ADDR_PUBLIC, /* UINT8 addr_type_own */ BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */ BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */ BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */ BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { /* start auto connection failed */ exec = FALSE; } else { p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE; } } } else exec = FALSE; } else { if (p_cb->bg_conn_state == BLE_BG_CONN_ACTIVE) { if (!btsnd_hcic_ble_create_conn_cancel()) exec = FALSE; else p_cb->bg_conn_state = BLE_BG_CONN_IDLE; } } return exec; }
/******************************************************************************* ** ** Function l2cble_init_direct_conn ** ** Description This function is to initate a direct connection ** ** Returns TRUE connection initiated, FALSE otherwise. ** *******************************************************************************/ BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb) { tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr); tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UINT16 scan_int, scan_win; BD_ADDR init_addr; UINT8 init_addr_type = BLE_ADDR_PUBLIC, own_addr_type = BLE_ADDR_PUBLIC; /* There can be only one BLE connection request outstanding at a time */ if (p_dev_rec == NULL) { BTM_TRACE_WARNING0 ("unknown device, can not initate connection"); return(FALSE); } 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; init_addr_type = p_lcb->ble_addr_type; memcpy(init_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ FALSE, /* UINT8 white_list */ p_lcb->ble_addr_type, /* UINT8 addr_type_peer */ p_lcb->remote_bd_addr, /* BD_ADDR bda_peer */ BLE_ADDR_PUBLIC, /* UINT8 addr_type_own */ (UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN), /* UINT16 conn_int_min */ (UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MIN), /* UINT16 conn_int_max */ (UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : 0), /* UINT16 conn_latency */ (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_SUP_TOUT_DEF), /* UINT16 conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { l2cu_release_lcb (p_lcb); L2CAP_TRACE_ERROR0("initate direct connection fail, no resources"); return (FALSE); } else { p_lcb->link_state = LST_CONNECTING; memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); //Assigning below variable which is checked at LE conn cancel l2cb.is_ble_connecting=TRUE; btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_BLE_LINK_CONNECT_TOUT); btm_ble_set_conn_st (BLE_DIR_CONN); return (TRUE); } }
/******************************************************************************* ** ** Function l2cble_init_direct_conn ** ** Description This function is to initate a direct connection ** ** Returns TRUE connection initiated, FALSE otherwise. ** *******************************************************************************/ BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb) { tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr); tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UINT16 scan_int; UINT16 scan_win; BD_ADDR peer_addr; UINT8 peer_addr_type = BLE_ADDR_PUBLIC; UINT8 own_addr_type = BLE_ADDR_PUBLIC; /* There can be only one BLE connection request outstanding at a time */ if (p_dev_rec == NULL) { L2CAP_TRACE_WARNING ("unknown device, can not initate connection"); return(FALSE); } scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; peer_addr_type = p_lcb->ble_addr_type; memcpy(peer_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); #if ( (defined BLE_PRIVACY_SPT) && (BLE_PRIVACY_SPT == TRUE)) own_addr_type = btm_cb.ble_ctr_cb.privacy_mode ? BLE_ADDR_RANDOM : BLE_ADDR_PUBLIC; if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { if (btm_cb.ble_ctr_cb.privacy_mode >= BTM_PRIVACY_1_2) own_addr_type |= BLE_ADDR_TYPE_ID_BIT; btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); btm_random_pseudo_to_identity_addr(peer_addr, &peer_addr_type); } else btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, TRUE); #endif if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) { l2cu_release_lcb (p_lcb); L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); return FALSE; } if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ FALSE, /* UINT8 white_list */ peer_addr_type, /* UINT8 addr_type_peer */ peer_addr, /* BD_ADDR bda_peer */ own_addr_type, /* UINT8 addr_type_own */ (UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* UINT16 conn_int_min */ (UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* UINT16 conn_int_max */ (UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* UINT16 conn_latency */ (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { l2cu_release_lcb (p_lcb); L2CAP_TRACE_ERROR("initate direct connection fail, no resources"); return (FALSE); } else { p_lcb->link_state = LST_CONNECTING; l2cb.is_ble_connecting = TRUE; memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_BLE_LINK_CONNECT_TOUT); btm_ble_set_conn_st (BLE_DIR_CONN); return (TRUE); } }
/******************************************************************************* ** ** Function btm_ble_start_auto_conn ** ** Description This function is to start/stop auto connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** ** Returns void ** *******************************************************************************/ BOOLEAN btm_ble_start_auto_conn(BOOLEAN start) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; BD_ADDR dummy_bda = {0}; BOOLEAN exec = TRUE; UINT16 scan_int; UINT16 scan_win; UINT8 own_addr_type = p_cb->addr_mgnt_cb.own_addr_type; UINT8 peer_addr_type = BLE_ADDR_PUBLIC; if (start) { if (p_cb->conn_state == BLE_CONN_IDLE && background_connections_pending() && btm_ble_topology_check(BTM_BLE_STATE_INIT)) { p_cb->wl_state |= BTM_BLE_WL_INIT; btm_execute_wl_dev_operation(); #if BLE_PRIVACY_SPT == TRUE btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT); #endif scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int; scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win; #if BLE_PRIVACY_SPT == TRUE if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE) { own_addr_type |= BLE_ADDR_TYPE_ID_BIT; peer_addr_type |= BLE_ADDR_TYPE_ID_BIT; } #endif if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ 0x01, /* UINT8 white_list */ peer_addr_type, /* UINT8 addr_type_peer */ dummy_bda, /* BD_ADDR bda_peer */ own_addr_type, /* UINT8 addr_type_own */ BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */ BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */ BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */ BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { /* start auto connection failed */ exec = FALSE; p_cb->wl_state &= ~BTM_BLE_WL_INIT; } else { btm_ble_set_conn_st (BLE_BG_CONN); } } else { exec = FALSE; } } else { if (p_cb->conn_state == BLE_BG_CONN) { btsnd_hcic_ble_create_conn_cancel(); btm_ble_set_conn_st (BLE_CONN_CANCEL); p_cb->wl_state &= ~BTM_BLE_WL_INIT; } else { BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop", p_cb->conn_state); exec = FALSE; } } return exec; }
/******************************************************************************* ** ** Function btm_ble_start_auto_conn ** ** Description This function is to start/stop auto connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** ** Returns void ** *******************************************************************************/ BOOLEAN btm_ble_start_auto_conn(BOOLEAN start) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; BD_ADDR dummy_bda = {0}; BOOLEAN exec = TRUE; UINT16 scan_int, scan_win; if (start) { if ( p_cb->conn_state == BLE_CONN_IDLE ) { exec = btm_execute_wl_dev_operation(); } if ((p_cb->conn_state == BLE_CONN_IDLE && btm_ble_count_unconn_dev_in_whitelist() > 0) && btm_ble_topology_check(BTM_BLE_STATE_INIT)) { #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) /*enable offload if any unconn dev in WL are in IRK list*/ if (btm_cb.cmn_ble_vsc_cb.rpa_offloading == TRUE && btm_ble_count_unconn_dev_in_wl_irk() > 0) btm_ble_vendor_enable_irk_feature(TRUE); #endif scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int; scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win; if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ 0x01, /* UINT8 white_list */ BLE_ADDR_PUBLIC, /* UINT8 addr_type_peer */ dummy_bda, /* BD_ADDR bda_peer */ p_cb->addr_mgnt_cb.own_addr_type, /* UINT8 addr_type_own, not allow random address for central */ BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */ BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */ BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */ BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { /* start auto connection failed */ exec = FALSE; } else { btm_ble_set_conn_st (BLE_BG_CONN); p_cb->wl_state |= BTM_BLE_WL_INIT; } } else { exec = FALSE; } } else { if (p_cb->conn_state == BLE_BG_CONN) { btsnd_hcic_ble_create_conn_cancel(); btm_ble_set_conn_st (BLE_CONN_CANCEL); p_cb->wl_state |= BTM_BLE_WL_INIT; } else { #if 0 BTM_TRACE_ERROR("conn_st = %d, not in auto conn state, can not stop.", p_cb->conn_state); exec = FALSE; #endif } } return exec; }
/******************************************************************************* ** ** Function btm_ble_start_auto_conn ** ** Description This function is to start/stop auto connection procedure. ** ** Parameters start: TRUE to start; FALSE to stop. ** ** Returns void ** *******************************************************************************/ BOOLEAN btm_ble_start_auto_conn(BOOLEAN start) { tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; BD_ADDR dummy_bda = {0}; BOOLEAN exec = TRUE; UINT8 own_addr_type = BLE_ADDR_PUBLIC; UINT16 scan_int, scan_win; if (start) { if (p_cb->conn_state == BLE_CONN_IDLE && btm_ble_count_unconn_dev_in_whitelist() > 0) { btm_execute_wl_dev_operation(); scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int; scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win; if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ 0x01, /* UINT8 white_list */ BLE_ADDR_PUBLIC, /* UINT8 addr_type_peer */ dummy_bda, /* BD_ADDR bda_peer */ own_addr_type, /* UINT8 addr_type_own, not allow random address for central */ BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */ BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */ BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */ BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { /* start auto connection failed */ exec = FALSE; } else { #ifdef BLUETOOTH_RTK p_cb->wl_state |= BTM_BLE_WL_INIT; #endif btm_ble_set_conn_st (BLE_BG_CONN); } } else { exec = FALSE; } } else { if (p_cb->conn_state == BLE_BG_CONN) { btsnd_hcic_ble_create_conn_cancel(); btm_ble_set_conn_st (BLE_CONN_CANCEL); } else { #if 0 BTM_TRACE_ERROR1("conn_st = %d, not in auto conn state, can not stop.", p_cb->conn_state); exec = FALSE; #endif } } return exec; }
/******************************************************************************* ** ** Function l2cble_init_direct_conn ** ** Description This function is to initate a direct connection ** ** Returns TRUE connection initiated, FALSE otherwise. ** *******************************************************************************/ BOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb) { tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr); tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UINT16 scan_int, scan_win; BD_ADDR init_addr; UINT8 init_addr_type = BLE_ADDR_PUBLIC, own_addr_type = BLE_ADDR_PUBLIC; /* There can be only one BLE connection request outstanding at a time */ if (p_dev_rec == NULL) { L2CAP_TRACE_WARNING ("unknown device, can not initate connection"); return(FALSE); } 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; init_addr_type = p_lcb->ble_addr_type; memcpy(init_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); #if BLE_PRIVACY_SPT == TRUE /* if RPA offloading supported */ if (btm_ble_vendor_irk_list_load_dev(p_dev_rec)) btm_random_pseudo_to_public(init_addr, &init_addr_type); /* otherwise, if remote is RPA enabled, use latest RPA */ else if (p_dev_rec->ble.active_addr_type == BTM_BLE_ADDR_RRA) { init_addr_type = BLE_ADDR_RANDOM; memcpy(init_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN); } /* if privacy is on and current do not consider using reconnection address */ if (btm_cb.ble_ctr_cb.privacy ) /* && p_dev_rec->ble.use_reconn_addr */ own_addr_type = BLE_ADDR_RANDOM; #endif if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) { l2cu_release_lcb (p_lcb); L2CAP_TRACE_ERROR("initate direct connection fail, topology limitation"); return FALSE; } if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */ scan_win, /* UINT16 scan_win */ FALSE, /* UINT8 white_list */ init_addr_type, /* UINT8 addr_type_peer */ init_addr, /* BD_ADDR bda_peer */ own_addr_type, /* UINT8 addr_type_own */ (UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* UINT16 conn_int_min */ (UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* UINT16 conn_int_max */ (UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.slave_latency : BTM_BLE_CONN_SLAVE_LATENCY_DEF), /* UINT16 conn_latency */ (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_TIMEOUT_DEF), /* conn_timeout */ 0, /* UINT16 min_len */ 0)) /* UINT16 max_len */ { l2cu_release_lcb (p_lcb); L2CAP_TRACE_ERROR("initate direct connection fail, no resources"); return (FALSE); } else { p_lcb->link_state = LST_CONNECTING; l2cb.is_ble_connecting = TRUE; memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_BLE_LINK_CONNECT_TOUT); btm_ble_set_conn_st (BLE_DIR_CONN); return (TRUE); } }