l2c_ble.c revision 61973be637027a4e91b99ca3e19fe964481936b2
15738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/****************************************************************************** 25738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 35738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Copyright (C) 2009-2012 Broadcom Corporation 45738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 55738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 65738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * you may not use this file except in compliance with the License. 75738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * You may obtain a copy of the License at: 85738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 95738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * See the License for the specific language governing permissions and 155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * limitations under the License. 165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/ 185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/****************************************************************************** 205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * this file contains functions relating to BLE management. 225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/ 245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include <string.h> 265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bt_target.h" 275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "l2cdefs.h" 285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "l2c_int.h" 295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "btu.h" 305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "btm_int.h" 315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "hcimsgs.h" 325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if (BLE_INCLUDED == TRUE) 345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function L2CA_CancelBleConnectReq 385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Cancel a pending connection attempt to a BLE device. 405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Parameters: BD Address of remote 425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Return value: TRUE if connection was cancelled 445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda) 475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* There can be only one BLE connection request outstanding at a time */ 516975b4d711142b885af479721cada448952c6b41Andre Eisenbach if (btm_ble_get_conn_st() == BLE_CONN_IDLE) 525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING0 ("L2CA_CancelBleConnectReq - no connection pending"); 545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(FALSE); 555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) 585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING4 ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x", 605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (l2cb.ble_connecting_bda[0]<<24)+(l2cb.ble_connecting_bda[1]<<16)+(l2cb.ble_connecting_bda[2]<<8)+l2cb.ble_connecting_bda[3], 615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (l2cb.ble_connecting_bda[4]<<8)+l2cb.ble_connecting_bda[5], 625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); 635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(FALSE); 655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (btsnd_hcic_ble_create_conn_cancel()) 685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda)) != NULL) 715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->disc_reason = L2CAP_CONN_CANCEL; 735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_release_lcb (p_lcb); 745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 756975b4d711142b885af479721cada448952c6b41Andre Eisenbach /* update state to be cancel, wait for connection cancel complete */ 766975b4d711142b885af479721cada448952c6b41Andre Eisenbach btm_ble_set_conn_st (BLE_CONN_CANCEL); 775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(TRUE); 795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(FALSE); 825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function L2CA_UpdateBleConnParams 885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Update BLE connection parameters. 905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Parameters: BD Address of remote 925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Return value: TRUE if update started 945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_int, UINT16 latency, UINT16 timeout) 975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* See if we have a link control block for the remote device */ 1015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda); 1025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* If we don't have one, create one and accept the connection. */ 1045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb) 1055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING2 ("L2CA_UpdateBleConnParams - unknown BD_ADDR %08x%04x", 1075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); 1085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(FALSE); 1095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb->is_ble_link) 1125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING2 ("L2CA_UpdateBleConnParams - BD_ADDR %08x%04x not LE", 1145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); 1155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(FALSE); 1165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_lcb->link_role == HCI_ROLE_MASTER) 1195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, min_int, max_int, latency, timeout, 0, 0); 1205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 1215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_send_peer_ble_par_req (p_lcb, min_int, max_int, latency, timeout); 1225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(TRUE); 1245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 1255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 1285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function L2CA_EnableUpdateBleConnParams 1305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Enable or disable update based on the request from the peer 1325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Parameters: BD Address of remote 1345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Return value: TRUE if update started 1365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 1385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable) 1395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 1415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* See if we have a link control block for the remote device */ 1435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda); 1445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* If we don't have one, create one and accept the connection. */ 1465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb) 1475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING2 ("L2CA_EnableUpdateBleConnParams - unknown BD_ADDR %08x%04x", 1495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]); 1505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return (FALSE); 1515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_API4 ("L2CA_EnableUpdateBleConnParams - BD_ADDR %08x%04x enable %d current upd state %d", 1545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5], enable, p_lcb->upd_disabled); 1555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb->is_ble_link || (p_lcb->link_role != HCI_ROLE_MASTER)) 1575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING3 ("L2CA_EnableUpdateBleConnParams - BD_ADDR %08x%04x not LE or not master %d", 1595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5], p_lcb->link_role); 1605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return (FALSE); 1615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (enable) 1645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* application allows to do update, if we were delaying one do it now, otherwise 1665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project just mark lcb that updates are enabled */ 1675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_lcb->upd_disabled == UPD_PENDING) 1685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, p_lcb->min_interval, p_lcb->max_interval, 1705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->latency, p_lcb->timeout, 0, 0); 1715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->upd_disabled = UPD_UPDATED; 1725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->upd_disabled = UPD_ENABLED; 1765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 1795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* application requests to disable parameters update. If parameters are already updated, lets set them 1815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project up to what has been requested during connection establishement */ 1825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_lcb->upd_disabled == UPD_UPDATED) 1835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (rem_bda); 1855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, 187ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (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), 188ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (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), 189ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (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), 190ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (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), 1915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 0, 0); 1925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 19361973be637027a4e91b99ca3e19fe964481936b2Zhihai Xu 19461973be637027a4e91b99ca3e19fe964481936b2Zhihai Xu if (p_lcb->upd_disabled != UPD_PENDING) 19561973be637027a4e91b99ca3e19fe964481936b2Zhihai Xu { 19661973be637027a4e91b99ca3e19fe964481936b2Zhihai Xu p_lcb->upd_disabled = UPD_DISABLED; 19761973be637027a4e91b99ca3e19fe964481936b2Zhihai Xu } 1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return (TRUE); 2015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function L2CA_GetBleConnRole 2065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function returns the connection role. 2085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns link role. 2105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8 L2CA_GetBleConnRole (BD_ADDR bd_addr) 2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 role = HCI_ROLE_UNKNOWN; 2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_lcb = l2cu_find_lcb_by_bd_addr (bd_addr)) != NULL) 2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project role = p_lcb->link_role; 2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return role; 2225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function L2CA_GetDisconnectReason 2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function returns the disconnect reason code. 2285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns disconnect reason 2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT16 L2CA_GetDisconnectReason (BD_ADDR remote_bda) 2335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 2355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 reason = 0; 2365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_lcb = l2cu_find_lcb_by_bd_addr (remote_bda)) != NULL) 2385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project reason = p_lcb->disc_reason; 2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_DEBUG1 ("L2CA_GetDisconnectReason=%d ",reason); 2415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return reason; 2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function l2cble_scanner_conn_comp 2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called when an HCI Connection Complete 2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** event is received while we are a scanner (so we are master). 2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 255ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Battavoid l2cble_scanner_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type, 256ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout) 2575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (bda); 2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_DEBUG5 ("l2cble_scanner_conn_comp: HANDLE=%d addr_type=%d conn_interval=%d slave_latency=%d supervision_tout=%d", 2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project handle, type, conn_interval, conn_latency, conn_timeout); 2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cb.is_ble_connecting = FALSE; 2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* See if we have a link control block for the remote device */ 2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb = l2cu_find_lcb_by_bd_addr (bda); 2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* If we don't have one, create one. this is auto connection complete. */ 2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb) 2715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb = l2cu_allocate_lcb (bda, FALSE); 2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb) 2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); 2765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_ERROR0 ("l2cble_scanner_conn_comp - failed to allocate LCB"); 2775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return; 2785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) 2825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); 2845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING0 ("l2cble_scanner_conn_comp - LCB but no CCB"); 2855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return ; 2865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else if (p_lcb->link_state != LST_CONNECTING) 2905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_ERROR1 ("L2CAP got BLE scanner conn_comp in bad state: %d", p_lcb->link_state); 2925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return; 2935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btu_stop_timer(&p_lcb->timer_entry); 2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Save the handle */ 2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->handle = handle; 2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Connected OK. Change state to connected, we were scanning so we are master */ 3005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->link_state = LST_CONNECTED; 3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->link_role = HCI_ROLE_MASTER; 3025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->is_ble_link = TRUE; 3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* If there are any preferred connection parameters, set them now */ 305ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if ( (p_dev_rec->conn_params.min_conn_int >= BTM_BLE_CONN_INT_MIN ) && 306ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (p_dev_rec->conn_params.min_conn_int <= BTM_BLE_CONN_INT_MAX ) && 307ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (p_dev_rec->conn_params.max_conn_int >= BTM_BLE_CONN_INT_MIN ) && 308ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (p_dev_rec->conn_params.max_conn_int <= BTM_BLE_CONN_INT_MAX ) && 309ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (p_dev_rec->conn_params.slave_latency <= BTM_BLE_CONN_LATENCY_MAX ) && 310ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (p_dev_rec->conn_params.supervision_tout >= BTM_BLE_CONN_SUP_TOUT_MIN) && 311ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta (p_dev_rec->conn_params.supervision_tout <= BTM_BLE_CONN_SUP_TOUT_MAX) && 3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ((conn_interval < p_dev_rec->conn_params.min_conn_int && 3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) || 3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (conn_interval > p_dev_rec->conn_params.max_conn_int) || 3155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (conn_latency > p_dev_rec->conn_params.slave_latency) || 3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (conn_timeout > p_dev_rec->conn_params.supervision_tout))) 3175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_ERROR5 ("upd_ll_conn_params: HANDLE=%d min_conn_int=%d max_conn_int=%d slave_latency=%d supervision_tout=%d", 3195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project handle, p_dev_rec->conn_params.min_conn_int, p_dev_rec->conn_params.max_conn_int, 3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec->conn_params.slave_latency, p_dev_rec->conn_params.supervision_tout); 3215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btsnd_hcic_ble_upd_ll_conn_params (handle, 3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec->conn_params.min_conn_int, 3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec->conn_params.max_conn_int, 3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec->conn_params.slave_latency, 3265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec->conn_params.supervision_tout, 3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 0, 0); 3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Tell BTM Acl management about the link */ 3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, TRUE); 3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_lcb->p_echo_rsp_cb) 3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_ERROR0 ("l2cu_send_peer_echo_req"); 3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_send_peer_echo_req (p_lcb, NULL, 0); 3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; 3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_process_fixed_chnl_resp (p_lcb); 3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function l2cble_advertiser_conn_comp 3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called when an HCI Connection Complete 3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** event is received while we are an advertiser (so we are slave). 3515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 3535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid l2cble_advertiser_conn_comp (UINT16 handle, BD_ADDR bda, tBLE_ADDR_TYPE type, 3565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout) 3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tL2C_LCB *p_lcb; 3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTM_SEC_DEV_REC *p_dev_rec; 3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* See if we have a link control block for the remote device */ 3625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb = l2cu_find_lcb_by_bd_addr (bda); 3635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* If we don't have one, create one and accept the connection. */ 3655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb) 3665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb = l2cu_allocate_lcb (bda, FALSE); 3685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!p_lcb) 3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); 3715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_ERROR0 ("l2cble_advertiser_conn_comp - failed to allocate LCB"); 3725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return; 3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!l2cu_initialize_fixed_ccb (p_lcb, L2CAP_ATT_CID, &l2cb.fixed_reg[L2CAP_ATT_CID - L2CAP_FIRST_FIXED_CHNL].fixed_chnl_opts)) 3775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btm_sec_disconnect (handle, HCI_ERR_NO_CONNECTION); 3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING0 ("l2cble_scanner_conn_comp - LCB but no CCB"); 3805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return ; 3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Save the handle */ 3865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->handle = handle; 3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Connected OK. Change state to connected, we were advertising, so we are slave */ 3895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->link_state = LST_CONNECTED; 3905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->link_role = HCI_ROLE_SLAVE; 3915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->is_ble_link = TRUE; 3925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Tell BTM Acl management about the link */ 3945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_dev_rec = btm_find_or_alloc_dev (bda); 3955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btm_acl_created (bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role, TRUE); 3975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT | L2CAP_FIXED_CHNL_BLE_SIG_BIT | L2CAP_FIXED_CHNL_SMP_BIT; 3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_process_fixed_chnl_resp (p_lcb); 4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function l2cble_conn_comp 4065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called when an HCI Connection Complete 4085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** event is received. 4095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 4115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid l2cble_conn_comp(UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_TYPE type, 4145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 conn_interval, UINT16 conn_latency, UINT16 conn_timeout) 4155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (role == HCI_ROLE_MASTER) 4175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cble_scanner_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout); 4195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cble_advertiser_conn_comp(handle, bda, type, conn_interval, conn_latency, conn_timeout); 4235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function l2cble_process_sig_cmd 4285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called when a signalling packet is received 4305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** on the BLE signalling CID 4315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 4335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len) 4365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 *p_pkt_end; 4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 cmd_code, id; 4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 cmd_len, rej_reason; 4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 result; 4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 min_interval, max_interval, latency, timeout; 4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_pkt_end = p + pkt_len; 4445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT8 (cmd_code, p); 4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT8 (id, p); 4475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (cmd_len, p); 4485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Check command length does not exceed packet length */ 4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p + cmd_len) > p_pkt_end) 4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING3 ("L2CAP - LE - format error, pkt_len: %d cmd_len: %d code: %d", pkt_len, cmd_len, cmd_code); 4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return; 4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project switch (cmd_code) 4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_REJECT: 4595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_ECHO_RSP: 4605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_INFO_RSP: 4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (rej_reason, p); 4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_ECHO_REQ: 4645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_INFO_REQ: 4655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); 4665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 4675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_BLE_UPDATE_REQ: 4695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (min_interval, p); /* 0x0006 - 0x0C80 */ 4705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (max_interval, p); /* 0x0006 - 0x0C80 */ 4715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (latency, p); /* 0x0000 - 0x03E8 */ 4725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (timeout, p); /* 0x000A - 0x0C80 */ 4735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* If we are a master, the slave wants to update the parameters */ 4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_lcb->link_role == HCI_ROLE_MASTER) 4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 476ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (min_interval < BTM_BLE_CONN_INT_MIN || min_interval > BTM_BLE_CONN_INT_MAX || 477ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta max_interval < BTM_BLE_CONN_INT_MIN || max_interval > BTM_BLE_CONN_INT_MAX || 478ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta latency > BTM_BLE_CONN_LATENCY_MAX || 4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /*(timeout >= max_interval && latency > (timeout * 10/(max_interval * 1.25) - 1)) ||*/ 480ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta timeout < BTM_BLE_CONN_SUP_TOUT_MIN || timeout > BTM_BLE_CONN_SUP_TOUT_MAX || 4815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project max_interval < min_interval) 4825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 483ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_UNACCEPTABLE_PARAMS, id); 4845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_send_peer_ble_par_rsp (p_lcb, L2CAP_CFG_OK, id); 4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->min_interval = min_interval; 4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->max_interval = max_interval; 4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->latency = latency; 4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->timeout = timeout; 4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_lcb->upd_disabled == UPD_ENABLED) 4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btsnd_hcic_ble_upd_ll_conn_params (p_lcb->handle, min_interval, max_interval, 4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project latency, timeout, 0, 0); 4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->upd_disabled = UPD_UPDATED; 5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_EVENT0 ("L2CAP - LE - update currently disabled"); 5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_lcb->upd_disabled = UPD_PENDING; 5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); 5105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case L2CAP_CMD_BLE_UPDATE_RSP: 5135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project STREAM_TO_UINT16 (result, p); 5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 5155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project default: 5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CAP_TRACE_WARNING1 ("L2CAP - LE - unknown cmd code: %d", cmd_code); 5185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0); 5195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return; 5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 526ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Function l2cble_init_direct_conn 5275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 528ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description This function is to initate a direct connection 5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 530ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns TRUE connection initiated, FALSE otherwise. 5315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 533ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi BattaBOOLEAN l2cble_init_direct_conn (tL2C_LCB *p_lcb) 5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTM_SEC_DEV_REC *p_dev_rec = btm_find_or_alloc_dev (p_lcb->remote_bd_addr); 536ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; 537ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta UINT16 scan_int, scan_win; 538ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BD_ADDR init_addr; 539ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta UINT8 init_addr_type = BLE_ADDR_PUBLIC, 540ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta own_addr_type = BLE_ADDR_PUBLIC; 5415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* There can be only one BLE connection request outstanding at a time */ 543ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (p_dev_rec == NULL) 5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 545ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BTM_TRACE_WARNING0 ("unknown device, can not initate connection"); 5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return(FALSE); 5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 549ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int; 550ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win; 5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 552ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta init_addr_type = p_lcb->ble_addr_type; 553ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy(init_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); 5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int */ 5565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project scan_win, /* UINT16 scan_win */ 5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project FALSE, /* UINT8 white_list */ 5586975b4d711142b885af479721cada448952c6b41Andre Eisenbach init_addr_type, /* UINT8 addr_type_peer */ 5596975b4d711142b885af479721cada448952c6b41Andre Eisenbach init_addr, /* BD_ADDR bda_peer */ 5606975b4d711142b885af479721cada448952c6b41Andre Eisenbach own_addr_type, /* UINT8 addr_type_own */ 5613dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu (UINT16) ((p_dev_rec->conn_params.min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? 5623dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu p_dev_rec->conn_params.min_conn_int : BTM_BLE_CONN_INT_MIN_DEF), /* conn_int_min */ 5633dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu (UINT16) ((p_dev_rec->conn_params.max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) ? 5643dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu p_dev_rec->conn_params.max_conn_int : BTM_BLE_CONN_INT_MAX_DEF), /* conn_int_max */ 5653dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu (UINT16) ((p_dev_rec->conn_params.slave_latency != BTM_BLE_CONN_PARAM_UNDEF) ? 5663dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu p_dev_rec->conn_params.slave_latency : 0), /* UINT16 conn_latency */ 5673dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu (UINT16) ((p_dev_rec->conn_params.supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) ? 5683dc5945f1d62f9d30c7fcd4b1fe4077a3ba2f605Zhihai Xu p_dev_rec->conn_params.supervision_tout : BTM_BLE_CONN_SUP_TOUT_DEF), /* conn_timeout */ 5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 0, /* UINT16 min_len */ 5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 0)) /* UINT16 max_len */ 5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cu_release_lcb (p_lcb); 573ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta L2CAP_TRACE_ERROR0("initate direct connection fail, no resources"); 574ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return (FALSE); 5755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 577ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 578ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta p_lcb->link_state = LST_CONNECTING; 5796975b4d711142b885af479721cada448952c6b41Andre Eisenbach l2cb.is_ble_connecting = TRUE; 580ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta memcpy (l2cb.ble_connecting_bda, p_lcb->remote_bd_addr, BD_ADDR_LEN); 5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project btu_start_timer (&p_lcb->timer_entry, BTU_TTYPE_L2CAP_LINK, L2CAP_BLE_LINK_CONNECT_TOUT); 582ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btm_ble_set_conn_st (BLE_DIR_CONN); 5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 584ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return (TRUE); 585ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 586ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta} 587ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 588ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta/******************************************************************************* 589ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** 590ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Function l2cble_create_conn 591ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** 592ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Description This function initiates an acl connection via HCI 593ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** 594ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** Returns TRUE if successful, FALSE if connection not started. 595ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta** 596ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta*******************************************************************************/ 597ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi BattaBOOLEAN l2cble_create_conn (tL2C_LCB *p_lcb) 598ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta{ 599ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta tBTM_BLE_CONN_ST conn_st = btm_ble_get_conn_st(); 600ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta BOOLEAN rt = FALSE; 601ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 602ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta /* There can be only one BLE connection request outstanding at a time */ 603ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (conn_st == BLE_CONN_IDLE) 604ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 605ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta rt = l2cble_init_direct_conn(p_lcb); 606ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 607ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta else 608ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta { 609ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta L2CAP_TRACE_WARNING1 ("L2CAP - LE - cannot start new connection at conn st: %d", conn_st); 610ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 611ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btm_ble_enqueue_direct_conn_req(p_lcb); 612ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 613ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta if (conn_st == BLE_BG_CONN) 614ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta btm_ble_suspend_bg_conn(); 615ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta 616ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta rt = TRUE; 617ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta } 618ead3cde4bac0c3e32cd31f149093f004eef8ceebGanesh Ganapathi Batta return rt; 6195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function l2c_link_processs_ble_num_bufs 6245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called when a "controller buffer size" 6265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** event is first received from the controller. It updates 6275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the L2CAP values. 6285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 6305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 6325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid l2c_link_processs_ble_num_bufs (UINT16 num_lm_ble_bufs) 6335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 6340082e027d5ae3f45a3a613ed720c31e35f61d0ebAndre Eisenbach if (num_lm_ble_bufs == 0) 63512c3f496c3612472a22cbb0afd89812b154b4186Andre Eisenbach { 63612c3f496c3612472a22cbb0afd89812b154b4186Andre Eisenbach num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED; 63712c3f496c3612472a22cbb0afd89812b154b4186Andre Eisenbach l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED; 63812c3f496c3612472a22cbb0afd89812b154b4186Andre Eisenbach } 63912c3f496c3612472a22cbb0afd89812b154b4186Andre Eisenbach 6405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project l2cb.num_lm_ble_bufs = l2cb.controller_le_xmit_window = num_lm_ble_bufs; 6415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif /* (BLE_INCLUDED == TRUE) */ 644