/******************************************************************************* ** ** Function btm_ble_dequeue_direct_conn_req ** ** Description This function dequeues the direct connection request ** ** Returns None. ** *******************************************************************************/ void btm_ble_dequeue_direct_conn_req(BD_ADDR rem_bda) { tBTM_BLE_CONN_REQ *p_req = NULL; tL2C_LCB *p_lcb; if(btm_cb.ble_ctr_cb.conn_pending_q.count) { p_req = (tBTM_BLE_CONN_REQ*)GKI_getfirst(&btm_cb.ble_ctr_cb.conn_pending_q); } while(p_req != NULL) { p_lcb = (tL2C_LCB *)p_req->p_param; if((p_lcb != NULL) && (p_lcb->in_use)) { //If BD address matches if(!memcmp (rem_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN)) { GKI_remove_from_queue(&btm_cb.ble_ctr_cb.conn_pending_q, p_req); l2cu_release_lcb ((tL2C_LCB *)p_req->p_param); GKI_freebuf((void *)p_req); break; } } p_req = (tBTM_BLE_CONN_REQ*)GKI_getnext(p_req); } }
/******************************************************************************* ** ** 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 L2CA_CancelBleConnectReq ** ** Description Cancel a pending connection attempt to a BLE device. ** ** Parameters: BD Address of remote ** ** Return value: TRUE if connection was cancelled ** *******************************************************************************/ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) { tL2C_LCB *p_lcb; BOOLEAN rem_lcb = TRUE; /* There can be only one BLE connection request outstanding at a time */ if (btm_ble_get_conn_st() == BLE_CONN_IDLE) { L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - no connection pending"); return(FALSE); } if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) { L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x", (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3], (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5], (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); btm_ble_dequeue_direct_conn_req(rem_bda); return(FALSE); } if (btsnd_hcic_ble_create_conn_cancel()) { p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, BT_TRANSPORT_LE); /*Do not remove lcb if a LE link is already up as peripheral*/ if(p_lcb != NULL && p_lcb->link_role == HCI_ROLE_SLAVE && BTM_ACL_IS_CONNECTED(rem_bda)) { rem_lcb = FALSE; } if (rem_lcb && p_lcb != NULL) { p_lcb->disc_reason = L2CAP_CONN_CANCEL; l2cu_release_lcb (p_lcb); } /* update state to be cancel, wait for connection cancel complete */ btm_ble_set_conn_st (BLE_CONN_CANCEL); return(TRUE); } else return(FALSE); }
/******************************************************************************* ** ** Function L2CA_CancelBleConnectReq ** ** Description Cancel a pending connection attempt to a BLE device. ** ** Parameters: BD Address of remote ** ** Return value: TRUE if connection was cancelled ** *******************************************************************************/ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) { tL2C_LCB *p_lcb; /* There can be only one BLE connection request outstanding at a time */ //changed check for BLE_CONN_IDLE instead of incorrect BLE_DIR_CONN for no pending connection if (btm_ble_get_conn_st() == BLE_CONN_IDLE) { L2CAP_TRACE_WARNING0 ("L2CA_CancelBleConnectReq - no connection pending"); return(FALSE); } if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) { L2CAP_TRACE_WARNING4 ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x", (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3], (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5], (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); return(FALSE); } if (btsnd_hcic_ble_create_conn_cancel()) { if ((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda)) != NULL) { p_lcb->disc_reason = L2CAP_CONN_CANCEL; l2cu_release_lcb (p_lcb); } /* update conn state to IDLE */ btm_ble_set_conn_st (BLE_CONN_IDLE); return(TRUE); } else return(FALSE); }
/******************************************************************************* ** ** 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 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); } }