2016-09-26 09:37:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
**
|
|
|
|
** Name: btm_acl.c
|
|
|
|
**
|
|
|
|
** Description: This file contains functions that handle ACL connections.
|
|
|
|
** This includes operations such as hold and sniff modes,
|
|
|
|
** supported packet types.
|
|
|
|
**
|
|
|
|
** This module contains both internal and external (API)
|
|
|
|
** functions. External (API) functions are distinguishable
|
|
|
|
** by their names beginning with uppercase BTM.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
//#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/bt_types.h"
|
|
|
|
#include "common/bt_target.h"
|
|
|
|
#include "device/controller.h"
|
|
|
|
#include "stack/hcimsgs.h"
|
|
|
|
#include "stack/btu.h"
|
|
|
|
#include "stack/btm_api.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "btm_int.h"
|
2022-07-28 00:32:56 -04:00
|
|
|
#include "stack/acl_hci_link_interface.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
#include "l2c_int.h"
|
2022-07-28 00:32:56 -04:00
|
|
|
#include "stack/l2cap_hci_link_interface.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "stack/hcidefs.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
//#include "bt_utils.h"
|
2020-07-01 14:35:54 -04:00
|
|
|
#include "osi/list.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
static void btm_read_remote_features (UINT16 handle);
|
|
|
|
static void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number);
|
|
|
|
static void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages);
|
|
|
|
|
|
|
|
#define BTM_DEV_REPLY_TIMEOUT 3 /* 3 second timeout waiting for responses */
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_init
|
|
|
|
**
|
|
|
|
** Description This function is called at BTM startup to initialize
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_init (void)
|
|
|
|
{
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_init\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
#if 0 /* cleared in btm_init; put back in if called from anywhere else! */
|
|
|
|
memset (&btm_cb.acl_db, 0, sizeof (btm_cb.acl_db));
|
|
|
|
memset (btm_cb.btm_scn, 0, BTM_MAX_SCN); /* Initialize the SCN usage to FALSE */
|
|
|
|
btm_cb.btm_def_link_policy = 0;
|
|
|
|
btm_cb.p_bl_changed_cb = NULL;
|
|
|
|
#endif
|
2020-07-01 14:35:54 -04:00
|
|
|
btm_cb.p_acl_db_list = list_new(osi_free_func);
|
|
|
|
btm_cb.p_pm_mode_db_list = list_new(osi_free_func);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Initialize nonzero defaults */
|
|
|
|
btm_cb.btm_def_link_super_tout = HCI_DEFAULT_INACT_TOUT;
|
|
|
|
btm_cb.acl_disc_reason = 0xff ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_bda_to_acl
|
|
|
|
**
|
|
|
|
** Description This function returns the FIRST acl_db entry for the passed BDA.
|
|
|
|
**
|
|
|
|
** Parameters bda : BD address of the remote device
|
|
|
|
** transport : Physical transport used for ACL connection (BR/EDR or LE)
|
|
|
|
**
|
|
|
|
** Returns Returns pointer to the ACL DB for the requested BDA if found.
|
|
|
|
** NULL if not found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2020-07-01 14:35:54 -04:00
|
|
|
BOOLEAN btm_get_acl_db(void *p_acl_db_node, void *context)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_db =(tACL_CONN *)p_acl_db_node;
|
|
|
|
BOOLEAN ret = TRUE;
|
|
|
|
tACL_DB_PARAM *p_param = (tACL_DB_PARAM *)context;
|
|
|
|
switch(p_param->type) {
|
|
|
|
case ACL_DB_BDA:
|
|
|
|
{
|
|
|
|
UINT8 *p_bda = (UINT8 *)p_param->p_data1;
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BLE_INCLUDED == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
tBT_TRANSPORT transport = (tBT_TRANSPORT)(*((UINT8 *)p_param->p_data2));
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2020-07-01 14:35:54 -04:00
|
|
|
if (p_acl_db->in_use
|
|
|
|
&& !memcmp(p_bda, p_acl_db->remote_addr, BD_ADDR_LEN)
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
&& transport == p_acl_db->transport
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ACL_DB_HANDLE:
|
|
|
|
{
|
|
|
|
UINT16 handle = (UINT16) *((UINT16 *)p_param->p_data1);
|
|
|
|
if (p_acl_db->in_use && handle == p_acl_db->hci_handle) {
|
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
return ret;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *btm_bda_to_acl (BD_ADDR bda, tBT_TRANSPORT transport)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_db = NULL;
|
|
|
|
list_node_t *p_node = NULL;
|
|
|
|
tACL_DB_PARAM acl_params;
|
|
|
|
acl_params.type = ACL_DB_BDA;
|
|
|
|
acl_params.p_data1 = (void *)bda;
|
|
|
|
acl_params.p_data2 = (void *)&transport;
|
|
|
|
p_node = list_foreach(btm_cb.p_acl_db_list, btm_get_acl_db, (void *)&acl_params);
|
|
|
|
if (p_node) {
|
|
|
|
p_acl_db = list_node(p_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (p_acl_db);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2017-06-14 09:19:48 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_handle_to_acl
|
|
|
|
**
|
|
|
|
** Description This function returns the FIRST acl_db entry for the passed hci_handle.
|
|
|
|
**
|
|
|
|
** Returns Returns pointer to the ACL DB for the requested BDA if found.
|
|
|
|
** NULL if not found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tACL_CONN *btm_handle_to_acl (UINT16 hci_handle)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_db = NULL;
|
|
|
|
tACL_DB_PARAM acl_params;
|
|
|
|
list_node_t *p_node = NULL;
|
|
|
|
|
|
|
|
BTM_TRACE_DEBUG ("btm_handle_to_acl_index: %d\n", hci_handle);
|
|
|
|
|
|
|
|
acl_params.type = ACL_DB_HANDLE;
|
|
|
|
acl_params.p_data1 = (void *)&hci_handle;
|
|
|
|
acl_params.p_data2 = NULL;
|
|
|
|
p_node = list_foreach(btm_cb.p_acl_db_list, btm_get_acl_db, (void *)&acl_params);
|
|
|
|
if (p_node) {
|
|
|
|
p_acl_db = list_node(p_node);
|
2017-06-14 09:19:48 -04:00
|
|
|
}
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
return (p_acl_db);
|
2017-06-14 09:19:48 -04:00
|
|
|
}
|
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BLE_PRIVACY_SPT == TRUE
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_get_acl_remote_addr
|
|
|
|
**
|
|
|
|
** Description This function reads the active remote address used for the
|
|
|
|
** connection.
|
|
|
|
**
|
|
|
|
** Returns success return TRUE, otherwise FALSE.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr,
|
|
|
|
tBLE_ADDR_TYPE *p_addr_type)
|
|
|
|
{
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
BOOLEAN st = TRUE;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec == NULL) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("btm_ble_get_acl_remote_addr can not find device with matching address\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (p_dev_rec->ble.active_addr_type) {
|
2016-09-26 09:37:39 -04:00
|
|
|
case BTM_BLE_ADDR_PSEUDO:
|
|
|
|
memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
|
|
|
|
* p_addr_type = p_dev_rec->ble.ble_addr_type;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTM_BLE_ADDR_RRA:
|
|
|
|
memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
|
|
|
|
* p_addr_type = BLE_ADDR_RANDOM;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTM_BLE_ADDR_STATIC:
|
|
|
|
memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
|
|
|
|
* p_addr_type = p_dev_rec->ble.static_addr_type;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("Unknown active address: %d\n", p_dev_rec->ble.active_addr_type);
|
2016-09-26 09:37:39 -04:00
|
|
|
st = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return st;
|
|
|
|
#else
|
|
|
|
UNUSED(p_dev_rec);
|
|
|
|
UNUSED(conn_addr);
|
|
|
|
UNUSED(p_addr_type);
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_created
|
|
|
|
**
|
|
|
|
** Description This function is called by L2CAP when an ACL connection
|
|
|
|
** is created.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_created (BD_ADDR bda, DEV_CLASS dc, BD_NAME bdn,
|
|
|
|
UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport)
|
|
|
|
{
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
|
|
|
|
tACL_CONN *p;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_created hci_handle=%d link_role=%d transport=%d\n",
|
2020-04-28 06:24:31 -04:00
|
|
|
hci_handle, link_role, transport);
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Ensure we don't have duplicates */
|
|
|
|
p = btm_bda_to_acl(bda, transport);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->hci_handle = hci_handle;
|
|
|
|
p->link_role = link_role;
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
p->transport = transport;
|
|
|
|
#endif
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("Duplicate btm_acl_created: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2020-04-28 06:24:31 -04:00
|
|
|
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_SetLinkPolicy(p->remote_addr, &btm_cb.btm_def_link_policy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate acl_db entry */
|
2020-07-01 14:35:54 -04:00
|
|
|
if (list_length(btm_cb.p_acl_db_list) >= MAX_L2CAP_LINKS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p = (tACL_CONN *)osi_malloc(sizeof(tACL_CONN));
|
|
|
|
if (p && list_append(btm_cb.p_acl_db_list, p)) {
|
|
|
|
memset(p, 0, sizeof(tACL_CONN));
|
2016-09-26 09:37:39 -04:00
|
|
|
p->in_use = TRUE;
|
|
|
|
p->hci_handle = hci_handle;
|
|
|
|
p->link_role = link_role;
|
|
|
|
p->link_up_issued = FALSE;
|
|
|
|
memcpy (p->remote_addr, bda, BD_ADDR_LEN);
|
2017-06-15 02:13:31 -04:00
|
|
|
/* Set the default version of the peer device to version4.0 before exchange the version with it.
|
|
|
|
If the peer device act as a master and don't exchange the version with us, then it can only use the
|
|
|
|
legacy connect instead of secure connection in the pairing step. */
|
|
|
|
p->lmp_version = HCI_PROTO_VERSION_4_0;
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
p->transport = transport;
|
|
|
|
#if BLE_PRIVACY_SPT == TRUE
|
2019-03-26 02:37:37 -04:00
|
|
|
if (transport == BT_TRANSPORT_LE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_ble_refresh_local_resolvable_private_addr(bda,
|
2016-11-24 13:10:15 -05:00
|
|
|
btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr);
|
2019-03-26 02:37:37 -04:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#else
|
|
|
|
p->conn_addr_type = BLE_ADDR_PUBLIC;
|
|
|
|
memcpy(p->conn_addr, &controller_get_interface()->get_address()->address, BD_ADDR_LEN);
|
2017-04-17 22:53:43 -04:00
|
|
|
BTM_TRACE_DEBUG ("conn_addr: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2020-04-28 06:24:31 -04:00
|
|
|
p->conn_addr[0], p->conn_addr[1], p->conn_addr[2], p->conn_addr[3], p->conn_addr[4], p->conn_addr[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
p->p_pm_mode_db = btm_pm_sm_alloc();
|
|
|
|
#if BTM_PM_DEBUG == TRUE
|
|
|
|
BTM_TRACE_DEBUG( "btm_pm_sm_alloc handle:%d st:%d", hci_handle, p->p_pm_mode_db->state);
|
|
|
|
#endif // BTM_PM_DEBUG
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-04-28 06:24:31 -04:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
|
|
|
btm_sec_update_legacy_auth_state(p, BTM_ACL_LEGACY_AUTH_NONE);
|
|
|
|
#endif
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (dc) {
|
2016-09-26 09:37:39 -04:00
|
|
|
memcpy (p->remote_dc, dc, DEV_CLASS_LEN);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (bdn) {
|
2016-09-26 09:37:39 -04:00
|
|
|
memcpy (p->remote_name, bdn, BTM_MAX_REM_BD_NAME_LEN);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* if BR/EDR do something more */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (transport == BT_TRANSPORT_BR_EDR) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btsnd_hcic_read_rmt_clk_offset (p->hci_handle);
|
|
|
|
btsnd_hcic_rmt_ver_req (p->hci_handle);
|
|
|
|
}
|
|
|
|
p_dev_rec = btm_find_dev_by_handle (hci_handle);
|
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec ) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("device_type=0x%x\n", p_dev_rec->device_type);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec && !(transport == BT_TRANSPORT_LE)) {
|
2020-04-28 06:24:31 -04:00
|
|
|
if (!p_dev_rec->remote_secure_connection_previous_state) {
|
|
|
|
/* If remote features already known, copy them and continue connection setup */
|
|
|
|
if ((p_dev_rec->num_read_pages) &&
|
|
|
|
(p_dev_rec->num_read_pages <= (HCI_EXT_FEATURES_PAGE_MAX + 1))) {
|
|
|
|
memcpy (p->peer_lmp_features, p_dev_rec->features,
|
|
|
|
(HCI_FEATURE_BYTES_PER_PAGE * p_dev_rec->num_read_pages));
|
|
|
|
p->num_read_pages = p_dev_rec->num_read_pages;
|
2017-04-17 22:53:43 -04:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
2020-04-28 06:24:31 -04:00
|
|
|
const UINT8 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
|
2017-04-17 22:53:43 -04:00
|
|
|
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
2020-04-28 06:24:31 -04:00
|
|
|
/* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
|
2017-04-24 23:46:37 -04:00
|
|
|
#if (SMP_INCLUDED == TRUE)
|
2020-04-28 06:24:31 -04:00
|
|
|
btm_sec_set_peer_sec_caps(p, p_dev_rec);
|
2017-04-24 23:46:37 -04:00
|
|
|
#endif ///SMP_INCLUDED == TRUE
|
2017-04-17 22:53:43 -04:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
2020-04-28 06:24:31 -04:00
|
|
|
BTM_TRACE_API("%s: pend:%d\n", __FUNCTION__, req_pend);
|
|
|
|
if (req_pend) {
|
|
|
|
/* Request for remaining Security Features (if any) */
|
|
|
|
l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
|
|
|
|
}
|
2017-04-17 22:53:43 -04:00
|
|
|
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
2020-04-28 06:24:31 -04:00
|
|
|
btm_establish_continue (p);
|
|
|
|
return;
|
|
|
|
}
|
2022-10-18 07:38:59 -04:00
|
|
|
} else {
|
|
|
|
/* If remote features indicated secure connection (SC) mode, check the remote feautres again*/
|
|
|
|
/* this is to prevent from BIAS attack where attacker can downgrade SC mode*/
|
|
|
|
btm_read_remote_features (p->hci_handle);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
|
|
|
/* If here, features are not known yet */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec && transport == BT_TRANSPORT_LE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BLE_PRIVACY_SPT == TRUE
|
|
|
|
btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr,
|
2020-04-28 06:24:31 -04:00
|
|
|
&p->active_remote_addr_type);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
2017-04-18 03:23:38 -04:00
|
|
|
if (link_role == HCI_ROLE_MASTER) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btsnd_hcic_ble_read_remote_feat(p->hci_handle);
|
2017-04-13 10:14:28 -04:00
|
|
|
} else if (HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(controller_get_interface()->get_features_ble()->as_array)
|
2020-04-28 06:24:31 -04:00
|
|
|
&& link_role == HCI_ROLE_SLAVE) {
|
2018-04-28 04:22:38 -04:00
|
|
|
btsnd_hcic_rmt_ver_req (p->hci_handle);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2017-04-21 02:43:35 -04:00
|
|
|
btm_establish_continue(p);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
} else
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
btm_read_remote_features (p->hci_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read page 1 - on rmt feature event for buffer reasons */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_report_role_change
|
|
|
|
**
|
|
|
|
** Description This function is called when the local device is deemed
|
|
|
|
** to be down. It notifies L2CAP of the failure.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_report_role_change (UINT8 hci_status, BD_ADDR bda)
|
|
|
|
{
|
|
|
|
tBTM_ROLE_SWITCH_CMPL ref_data;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_report_role_change\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
if (btm_cb.devcb.p_switch_role_cb
|
2016-11-24 13:10:15 -05:00
|
|
|
&& (bda && (0 == memcmp(btm_cb.devcb.switch_role_ref_data.remote_bd_addr, bda, BD_ADDR_LEN)))) {
|
2016-09-26 09:37:39 -04:00
|
|
|
memcpy (&ref_data, &btm_cb.devcb.switch_role_ref_data, sizeof(tBTM_ROLE_SWITCH_CMPL));
|
|
|
|
ref_data.hci_status = hci_status;
|
|
|
|
(*btm_cb.devcb.p_switch_role_cb)(&ref_data);
|
|
|
|
memset (&btm_cb.devcb.switch_role_ref_data, 0, sizeof(tBTM_ROLE_SWITCH_CMPL));
|
|
|
|
btm_cb.devcb.p_switch_role_cb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_removed
|
|
|
|
**
|
|
|
|
** Description This function is called by L2CAP when an ACL connection
|
|
|
|
** is removed. Since only L2CAP creates ACL links, we use
|
|
|
|
** the L2CAP link index as our index into the control blocks.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_removed (BD_ADDR bda, tBT_TRANSPORT transport)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
tBTM_BL_EVENT_DATA evt_data;
|
|
|
|
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_removed\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
p = btm_bda_to_acl(bda, transport);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->in_use = FALSE;
|
|
|
|
|
|
|
|
/* if the disconnected channel has a pending role switch, clear it now */
|
|
|
|
btm_acl_report_role_change(HCI_ERR_NO_CONNECTION, bda);
|
|
|
|
|
|
|
|
/* Only notify if link up has had a chance to be issued */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->link_up_issued) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->link_up_issued = FALSE;
|
|
|
|
|
|
|
|
/* If anyone cares, tell him database changed */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.p_bl_changed_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
evt_data.event = BTM_BL_DISCN_EVT;
|
|
|
|
evt_data.discn.p_bda = bda;
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
evt_data.discn.handle = p->hci_handle;
|
|
|
|
evt_data.discn.transport = p->transport;
|
|
|
|
#endif
|
|
|
|
(*btm_cb.p_bl_changed_cb)(&evt_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
btm_acl_update_busy_level (BTM_BLI_ACL_DOWN_EVT);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("acl hci_handle=%d transport=%d connectable_mode=0x%0x link_role=%d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
p->hci_handle,
|
|
|
|
p->transport,
|
|
|
|
btm_cb.ble_ctr_cb.inq_var.connectable_mode,
|
|
|
|
p->link_role);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p_dev_rec = btm_find_dev(bda);
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( p_dev_rec) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("before update p_dev_rec->sec_flags=0x%x\n", p_dev_rec->sec_flags);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->transport == BT_TRANSPORT_LE) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("LE link down\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->sec_flags &= ~(BTM_SEC_LE_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_KNOWN) == 0) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("Not Bonded\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->sec_flags &= ~(BTM_SEC_LE_LINK_KEY_AUTHED | BTM_SEC_LE_AUTHENTICATED);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("Bonded\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("Bletooth link down\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->sec_flags &= ~(BTM_SEC_AUTHORIZED | BTM_SEC_AUTHENTICATED
|
2016-11-24 13:10:15 -05:00
|
|
|
| BTM_SEC_ENCRYPTED | BTM_SEC_ROLE_SWITCHED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("after update p_dev_rec->sec_flags=0x%x\n", p_dev_rec->sec_flags);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("Device not found\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
list_remove(btm_cb.p_pm_mode_db_list, p->p_pm_mode_db);
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Clear the ACL connection data */
|
|
|
|
memset(p, 0, sizeof(tACL_CONN));
|
2020-07-01 14:35:54 -04:00
|
|
|
if (list_remove(btm_cb.p_acl_db_list, p)) {
|
|
|
|
p = NULL;
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_device_down
|
|
|
|
**
|
|
|
|
** Description This function is called when the local device is deemed
|
|
|
|
** to be down. It notifies L2CAP of the failure.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_device_down (void)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p = NULL;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_device_down\n");
|
2020-07-01 14:35:54 -04:00
|
|
|
for (list_node_t *p_node = list_begin(btm_cb.p_acl_db_list); p_node; p_node = list_next(p_node)) {
|
|
|
|
p = list_node(p_node);
|
2021-11-12 03:19:44 -05:00
|
|
|
if (p && p->in_use) {
|
2020-07-01 14:35:54 -04:00
|
|
|
BTM_TRACE_DEBUG ("hci_handle=%d HCI_ERR_HW_FAILURE \n", p->hci_handle );
|
|
|
|
l2c_link_hci_disc_comp (p->hci_handle, HCI_ERR_HW_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_update_busy_level
|
|
|
|
**
|
|
|
|
** Description This function is called to update the busy level of the system
|
|
|
|
** .
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_update_busy_level (tBTM_BLI_EVENT event)
|
|
|
|
{
|
|
|
|
tBTM_BL_UPDATE_DATA evt;
|
|
|
|
UINT8 busy_level;
|
|
|
|
BTM_TRACE_DEBUG ("btm_acl_update_busy_level\n");
|
|
|
|
BOOLEAN old_inquiry_state = btm_cb.is_inquiry;
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (event) {
|
|
|
|
case BTM_BLI_ACL_UP_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_ACL_UP_EVT\n");
|
|
|
|
break;
|
|
|
|
case BTM_BLI_ACL_DOWN_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_ACL_DOWN_EVT\n");
|
|
|
|
break;
|
|
|
|
case BTM_BLI_PAGE_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_PAGE_EVT\n");
|
|
|
|
btm_cb.is_paging = TRUE;
|
|
|
|
evt.busy_level_flags = BTM_BL_PAGING_STARTED;
|
|
|
|
break;
|
|
|
|
case BTM_BLI_PAGE_DONE_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_PAGE_DONE_EVT\n");
|
|
|
|
btm_cb.is_paging = FALSE;
|
|
|
|
evt.busy_level_flags = BTM_BL_PAGING_COMPLETE;
|
|
|
|
break;
|
|
|
|
case BTM_BLI_INQ_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_INQ_EVT\n");
|
|
|
|
btm_cb.is_inquiry = TRUE;
|
|
|
|
evt.busy_level_flags = BTM_BL_INQUIRY_STARTED;
|
|
|
|
break;
|
|
|
|
case BTM_BLI_INQ_CANCEL_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_INQ_CANCEL_EVT\n");
|
|
|
|
btm_cb.is_inquiry = FALSE;
|
|
|
|
evt.busy_level_flags = BTM_BL_INQUIRY_CANCELLED;
|
|
|
|
break;
|
|
|
|
case BTM_BLI_INQ_DONE_EVT:
|
|
|
|
BTM_TRACE_DEBUG ("BTM_BLI_INQ_DONE_EVT\n");
|
|
|
|
btm_cb.is_inquiry = FALSE;
|
|
|
|
evt.busy_level_flags = BTM_BL_INQUIRY_COMPLETE;
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.is_paging || btm_cb.is_inquiry) {
|
2016-09-26 09:37:39 -04:00
|
|
|
busy_level = 10;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
busy_level = BTM_GetNumAclLinks();
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((busy_level != btm_cb.busy_level) || (old_inquiry_state != btm_cb.is_inquiry)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
evt.event = BTM_BL_UPDATE_EVT;
|
|
|
|
evt.busy_level = busy_level;
|
|
|
|
btm_cb.busy_level = busy_level;
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_UPDATE_MASK)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
(*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 00:32:56 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_link_stat_report
|
|
|
|
**
|
|
|
|
** Description This function is called when the ACL link related
|
|
|
|
events are received from controller. It reports the ACL
|
|
|
|
link status to upper layer.
|
|
|
|
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_link_stat_report(tBTM_ACL_LINK_STAT_EVENT_DATA *p_data)
|
|
|
|
{
|
|
|
|
BTM_TRACE_DEBUG ("btm_acl_link_stat_report\n");
|
|
|
|
|
|
|
|
if (btm_cb.p_acl_link_stat_cb) {
|
|
|
|
(*btm_cb.p_acl_link_stat_cb)(p_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_GetRole
|
|
|
|
**
|
|
|
|
** Description This function is called to get the role of the local device
|
|
|
|
** for the ACL connection with the specified remote device
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if connection exists.
|
|
|
|
** BTM_UNKNOWN_ADDR if no active link with bd addr specified
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_GetRole (BD_ADDR remote_bd_addr, UINT8 *p_role)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_GetRole\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_role = BTM_ROLE_UNDEFINED;
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the current role */
|
|
|
|
*p_role = p->link_role;
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_SUCCESS);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SwitchRole
|
|
|
|
**
|
|
|
|
** Description This function is called to switch role between master and
|
|
|
|
** slave. If role is already set it will do nothing. If the
|
|
|
|
** command was initiated, the callback function is called upon
|
|
|
|
** completion.
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if already in specified role.
|
|
|
|
** BTM_CMD_STARTED if command issued to controller.
|
|
|
|
** BTM_NO_RESOURCES if couldn't allocate memory to issue command
|
|
|
|
** BTM_UNKNOWN_ADDR if no active link with bd addr specified
|
|
|
|
** BTM_MODE_UNSUPPORTED if local device does not support role switching
|
|
|
|
** BTM_BUSY if the previous command is not completed
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SwitchRole (BD_ADDR remote_bd_addr, UINT8 new_role, tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
|
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
|
|
|
BOOLEAN is_sco_active;
|
|
|
|
#endif
|
|
|
|
tBTM_STATUS status;
|
|
|
|
tBTM_PM_MODE pwr_mode;
|
|
|
|
tBTM_PM_PWR_MD settings;
|
|
|
|
#if (BT_USE_TRACES == TRUE)
|
|
|
|
BD_ADDR_PTR p_bda;
|
|
|
|
#endif
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_SwitchRole BDA: %02x-%02x-%02x-%02x-%02x-%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
remote_bd_addr[0], remote_bd_addr[1], remote_bd_addr[2],
|
|
|
|
remote_bd_addr[3], remote_bd_addr[4], remote_bd_addr[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Make sure the local device supports switching */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!controller_get_interface()->supports_master_slave_role_switch()) {
|
|
|
|
return (BTM_MODE_UNSUPPORTED);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.devcb.p_switch_role_cb && p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (BT_USE_TRACES == TRUE)
|
|
|
|
p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("Role switch on other device is in progress 0x%02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
p_bda[0], p_bda[1], p_bda[2],
|
|
|
|
p_bda[3], p_bda[4], p_bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_BUSY);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((p = btm_bda_to_acl(remote_bd_addr, BT_TRANSPORT_BR_EDR)) == NULL) {
|
|
|
|
return (BTM_UNKNOWN_ADDR);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Finished if already in desired role */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->link_role == new_role) {
|
|
|
|
return (BTM_SUCCESS);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
|
|
|
/* Check if there is any SCO Active on this BD Address */
|
|
|
|
is_sco_active = btm_is_sco_active_by_bdaddr(remote_bd_addr);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (is_sco_active == TRUE) {
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Ignore role switch request if the previous request was not completed */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_SwitchRole busy: %d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
p->switch_role_state);
|
|
|
|
return (BTM_BUSY);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((status = BTM_ReadPowerMode(p->remote_addr, &pwr_mode)) != BTM_SUCCESS) {
|
|
|
|
return (status);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Wake up the link if in sniff or park before attempting switch */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (pwr_mode == BTM_PM_MD_PARK || pwr_mode == BTM_PM_MD_SNIFF) {
|
|
|
|
memset( (void *)&settings, 0, sizeof(settings));
|
2016-09-26 09:37:39 -04:00
|
|
|
settings.mode = BTM_PM_MD_ACTIVE;
|
|
|
|
status = BTM_SetPowerMode (BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (status != BTM_CMD_STARTED) {
|
|
|
|
return (BTM_WRONG_MODE);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
|
|
|
|
}
|
|
|
|
/* some devices do not support switch while encryption is on */
|
2016-11-24 13:10:15 -05:00
|
|
|
else {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec = btm_find_dev (remote_bd_addr);
|
|
|
|
if ((p_dev_rec != NULL)
|
2016-11-24 13:10:15 -05:00
|
|
|
&& ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
|
|
|
|
&& !BTM_EPR_AVAILABLE(p)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* bypass turning off encryption if change link key is already doing it */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->encrypt_state != BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF) {
|
|
|
|
if (!btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) {
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
|
|
|
if (!btsnd_hcic_switch_role (remote_bd_addr, new_role)) {
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
|
|
|
|
|
|
|
|
#if BTM_DISC_DURING_RS == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize return structure in case request fails */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
memcpy (btm_cb.devcb.switch_role_ref_data.remote_bd_addr, remote_bd_addr,
|
|
|
|
BD_ADDR_LEN);
|
|
|
|
btm_cb.devcb.switch_role_ref_data.role = new_role;
|
|
|
|
/* initialized to an error code */
|
|
|
|
btm_cb.devcb.switch_role_ref_data.hci_status = HCI_ERR_UNSUPPORTED_VALUE;
|
|
|
|
btm_cb.devcb.p_switch_role_cb = p_cb;
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_CMD_STARTED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_encrypt_change
|
|
|
|
**
|
|
|
|
** Description This function is when encryption of the connection is
|
|
|
|
** completed by the LM. Checks to see if a role switch or
|
|
|
|
** change of link key was active and initiates or continues
|
|
|
|
** process if needed.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec;
|
|
|
|
tBTM_BL_ROLE_CHG_DATA evt;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
handle, status, encr_enable);
|
2020-07-01 14:35:54 -04:00
|
|
|
p = btm_handle_to_acl(handle);
|
|
|
|
if (p == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Process Role Switch if active */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* if encryption turn off failed we still will try to switch role */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (encr_enable) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
|
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING;
|
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_TEMP_FUNC;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
|
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
|
|
|
|
btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
|
|
|
|
}
|
|
|
|
#if BTM_DISC_DURING_RS == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
else {
|
|
|
|
if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
/* Finished enabling Encryption after role switch */
|
2016-11-24 13:10:15 -05:00
|
|
|
else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
|
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
|
|
|
|
btm_acl_report_role_change(btm_cb.devcb.switch_role_ref_data.hci_status, p->remote_addr);
|
|
|
|
|
|
|
|
/* if role change event is registered, report it now */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
evt.event = BTM_BL_ROLE_CHG_EVT;
|
|
|
|
evt.new_role = btm_cb.devcb.switch_role_ref_data.role;
|
|
|
|
evt.p_bda = btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
|
|
|
|
evt.hci_status = btm_cb.devcb.switch_role_ref_data.hci_status;
|
|
|
|
(*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
evt.new_role, evt.hci_status, p->switch_role_state);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if BTM_DISC_DURING_RS == TRUE
|
|
|
|
/* If a disconnect is pending, issue it now that role switch has completed */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((p_dev_rec = btm_find_dev (p->remote_addr)) != NULL) {
|
|
|
|
if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_WARNING("btm_acl_encrypt_change -> Issuing delayed HCI_Disconnect!!!\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
|
|
|
|
}
|
2020-07-15 03:49:37 -04:00
|
|
|
BTM_TRACE_WARNING("btm_acl_encrypt_change: tBTM_SEC_DEV:0x%x rs_disc_pending=%d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
(UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetLinkPolicy
|
|
|
|
**
|
|
|
|
** Description Create and send HCI "Write Policy Set" command
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetLinkPolicy (BD_ADDR remote_bda, UINT16 *settings)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
UINT8 *localFeatures = BTM_ReadLocalFeatures();
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_SetLinkPolicy\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
/* BTM_TRACE_API ("BTM_SetLinkPolicy: requested settings: 0x%04x", *settings ); */
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* First, check if hold mode is supported */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (*settings != HCI_DISABLE_ALL_LM_MODES) {
|
|
|
|
if ( (*settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*settings &= (~HCI_ENABLE_MASTER_SLAVE_SWITCH);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_SetLinkPolicy switch not supported (settings: 0x%04x)\n", *settings );
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (*settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*settings &= (~HCI_ENABLE_HOLD_MODE);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_SetLinkPolicy hold not supported (settings: 0x%04x)\n", *settings );
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (*settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*settings &= (~HCI_ENABLE_SNIFF_MODE);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_SetLinkPolicy sniff not supported (settings: 0x%04x)\n", *settings );
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (*settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures)) ) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*settings &= (~HCI_ENABLE_PARK_MODE);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_SetLinkPolicy park not supported (settings: 0x%04x)\n", *settings );
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR)) != NULL) {
|
|
|
|
return (btsnd_hcic_write_policy_set (p->hci_handle, *settings) ? BTM_CMD_STARTED : BTM_NO_RESOURCES);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetDefaultLinkPolicy
|
|
|
|
**
|
|
|
|
** Description Set the default value for HCI "Write Policy Set" command
|
|
|
|
** to use when an ACL link is created.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTM_SetDefaultLinkPolicy (UINT16 settings)
|
|
|
|
{
|
|
|
|
UINT8 *localFeatures = BTM_ReadLocalFeatures();
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy setting:0x%04x\n", settings);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((settings & HCI_ENABLE_MASTER_SLAVE_SWITCH) && (!HCI_SWITCH_SUPPORTED(localFeatures))) {
|
2016-09-26 09:37:39 -04:00
|
|
|
settings &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy switch not supported (settings: 0x%04x)\n", settings);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((settings & HCI_ENABLE_HOLD_MODE) && (!HCI_HOLD_MODE_SUPPORTED(localFeatures))) {
|
2016-09-26 09:37:39 -04:00
|
|
|
settings &= ~HCI_ENABLE_HOLD_MODE;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy hold not supported (settings: 0x%04x)\n", settings);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((settings & HCI_ENABLE_SNIFF_MODE) && (!HCI_SNIFF_MODE_SUPPORTED(localFeatures))) {
|
2016-09-26 09:37:39 -04:00
|
|
|
settings &= ~HCI_ENABLE_SNIFF_MODE;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy sniff not supported (settings: 0x%04x)\n", settings);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((settings & HCI_ENABLE_PARK_MODE) && (!HCI_PARK_MODE_SUPPORTED(localFeatures))) {
|
2016-09-26 09:37:39 -04:00
|
|
|
settings &= ~HCI_ENABLE_PARK_MODE;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM_SetDefaultLinkPolicy park not supported (settings: 0x%04x)\n", settings);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("Set DefaultLinkPolicy:0x%04x\n", settings);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
btm_cb.btm_def_link_policy = settings;
|
|
|
|
|
|
|
|
/* Set the default Link Policy of the controller */
|
|
|
|
btsnd_hcic_write_def_policy_set(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_remote_version_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the remote version info.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_remote_version_complete (UINT8 *p)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
2016-09-26 09:37:39 -04:00
|
|
|
UINT8 status;
|
|
|
|
UINT16 handle;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_read_remote_version_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
STREAM_TO_UINT8 (status, p);
|
|
|
|
STREAM_TO_UINT16 (handle, p);
|
|
|
|
|
|
|
|
/* Look up the connection by handle and copy features */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb) {
|
|
|
|
if (status == HCI_SUCCESS) {
|
|
|
|
STREAM_TO_UINT8 (p_acl_cb->lmp_version, p);
|
|
|
|
STREAM_TO_UINT16 (p_acl_cb->manufacturer, p);
|
|
|
|
STREAM_TO_UINT16 (p_acl_cb->lmp_subversion, p);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BLE_INCLUDED == TRUE
|
2020-07-01 14:35:54 -04:00
|
|
|
if (p_acl_cb->transport == BT_TRANSPORT_LE) {
|
|
|
|
if(p_acl_cb->link_role == HCI_ROLE_MASTER) {
|
|
|
|
if (HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl_cb->peer_le_features)) {
|
|
|
|
uint16_t data_length = controller_get_interface()->get_ble_default_data_packet_length();
|
|
|
|
uint16_t data_txtime = controller_get_interface()->get_ble_default_data_packet_txtime();
|
2021-09-08 07:37:25 -04:00
|
|
|
if (data_length != p_acl_cb->data_length_params.tx_len) {
|
|
|
|
p_acl_cb->data_len_updating = true;
|
|
|
|
btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime);
|
|
|
|
}
|
2017-12-07 02:00:06 -05:00
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
l2cble_notify_le_connection (p_acl_cb->remote_addr);
|
|
|
|
} else {
|
|
|
|
//slave role, read remote feature
|
|
|
|
btsnd_hcic_ble_read_remote_feat(p_acl_cb->hci_handle);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
#endif
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_process_remote_ext_features
|
|
|
|
**
|
|
|
|
** Description Local function called to process all extended features pages
|
|
|
|
** read from a remote device.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_process_remote_ext_features (tACL_CONN *p_acl_cb, UINT8 num_read_pages)
|
|
|
|
{
|
|
|
|
UINT16 handle = p_acl_cb->hci_handle;
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle);
|
|
|
|
UINT8 page_idx;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_process_remote_ext_features\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Make sure we have the record to save remote features information */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Get a new device; might be doing dedicated bonding */
|
|
|
|
p_dev_rec = btm_find_or_alloc_dev (p_acl_cb->remote_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_acl_cb->num_read_pages = num_read_pages;
|
|
|
|
p_dev_rec->num_read_pages = num_read_pages;
|
|
|
|
|
|
|
|
/* Move the pages to placeholder */
|
2016-11-24 13:10:15 -05:00
|
|
|
for (page_idx = 0; page_idx < num_read_pages; page_idx++) {
|
|
|
|
if (page_idx > HCI_EXT_FEATURES_PAGE_MAX) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("%s: page=%d unexpected\n", __FUNCTION__, page_idx);
|
2016-09-26 09:37:39 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
memcpy (p_dev_rec->features[page_idx], p_acl_cb->peer_lmp_features[page_idx],
|
|
|
|
HCI_FEATURE_BYTES_PER_PAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const UINT8 req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
|
2017-04-24 23:46:37 -04:00
|
|
|
#if (SMP_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
|
|
|
|
btm_sec_set_peer_sec_caps(p_acl_cb, p_dev_rec);
|
2017-04-24 23:46:37 -04:00
|
|
|
#endif ///SMP_INCLUDED == TRUE
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API("%s: pend:%d\n", __FUNCTION__, req_pend);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (req_pend) {
|
2017-04-25 04:55:29 -04:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Request for remaining Security Features (if any) */
|
|
|
|
l2cu_resubmit_pending_sec_req (p_dev_rec->bd_addr);
|
2017-04-25 04:55:29 -04:00
|
|
|
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_remote_features
|
|
|
|
**
|
|
|
|
** Description Local function called to send a read remote supported features/
|
|
|
|
** remote extended features page[0].
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_remote_features (UINT16 handle)
|
|
|
|
{
|
|
|
|
tACL_CONN *p_acl_cb;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("btm_read_remote_features() handle: %d\n", handle);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb == NULL) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("btm_read_remote_features handle=%d invalid\n", handle);
|
2020-07-01 14:35:54 -04:00
|
|
|
return;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
p_acl_cb->num_read_pages = 0;
|
|
|
|
memset (p_acl_cb->peer_lmp_features, 0, sizeof(p_acl_cb->peer_lmp_features));
|
|
|
|
|
|
|
|
/* first send read remote supported features HCI command */
|
|
|
|
/* because we don't know whether the remote support extended feature command */
|
|
|
|
btsnd_hcic_rmt_features_req (handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_remote_ext_features
|
|
|
|
**
|
|
|
|
** Description Local function called to send a read remote extended features
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number)
|
|
|
|
{
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("btm_read_remote_ext_features() handle: %d page: %d\n", handle, page_number);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
btsnd_hcic_rmt_ext_features(handle, page_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_remote_features_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the remote supported features
|
|
|
|
** complete event is received from the HCI.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_remote_features_complete (UINT8 *p)
|
|
|
|
{
|
|
|
|
tACL_CONN *p_acl_cb;
|
|
|
|
UINT8 status;
|
|
|
|
UINT16 handle;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_read_remote_features_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
STREAM_TO_UINT8 (status, p);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (status != HCI_SUCCESS) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR ("btm_read_remote_features_complete failed (status 0x%02x)\n", status);
|
2016-09-26 09:37:39 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
STREAM_TO_UINT16 (handle, p);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb == NULL) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("btm_read_remote_features_complete handle=%d invalid\n", handle);
|
2020-07-01 14:35:54 -04:00
|
|
|
return;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Copy the received features page */
|
|
|
|
STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0], p,
|
|
|
|
HCI_FEATURE_BYTES_PER_PAGE);
|
|
|
|
|
|
|
|
if ((HCI_LMP_EXTENDED_SUPPORTED(p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) &&
|
2016-11-24 13:10:15 -05:00
|
|
|
(controller_get_interface()->supports_reading_remote_extended_features())) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* if the remote controller has extended features and local controller supports
|
|
|
|
** HCI_Read_Remote_Extended_Features command then start reading these feature starting
|
|
|
|
** with extended features page 1 */
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("Start reading remote extended features\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_read_remote_ext_features(handle, HCI_EXT_FEATURES_PAGE_1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remote controller has no extended features. Process remote controller supported features
|
|
|
|
(features page HCI_EXT_FEATURES_PAGE_0). */
|
|
|
|
btm_process_remote_ext_features (p_acl_cb, 1);
|
|
|
|
|
|
|
|
/* Continue with HCI connection establishment */
|
|
|
|
btm_establish_continue (p_acl_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_remote_ext_features_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the remote extended features
|
|
|
|
** complete event is received from the HCI.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_remote_ext_features_complete (UINT8 *p)
|
|
|
|
{
|
|
|
|
tACL_CONN *p_acl_cb;
|
|
|
|
UINT8 page_num, max_page;
|
|
|
|
UINT16 handle;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_read_remote_ext_features_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
++p;
|
|
|
|
STREAM_TO_UINT16 (handle, p);
|
|
|
|
STREAM_TO_UINT8 (page_num, p);
|
|
|
|
STREAM_TO_UINT8 (max_page, p);
|
|
|
|
|
|
|
|
/* Validate parameters */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb == NULL) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("btm_read_remote_ext_features_complete handle=%d invalid\n", handle);
|
2016-09-26 09:37:39 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (max_page > HCI_EXT_FEATURES_PAGE_MAX) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_TRACE_ERROR("btm_read_remote_ext_features_complete page=%d unknown", max_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Copy the received features page */
|
|
|
|
STREAM_TO_ARRAY(p_acl_cb->peer_lmp_features[page_num], p, HCI_FEATURE_BYTES_PER_PAGE);
|
|
|
|
|
|
|
|
/* If there is the next remote features page and
|
|
|
|
* we have space to keep this page data - read this page */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((page_num < max_page) && (page_num < HCI_EXT_FEATURES_PAGE_MAX)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
page_num++;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM reads next remote extended features page (%d)\n", page_num);
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_read_remote_ext_features (handle, page_num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reading of remote feature pages is complete */
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("BTM reached last remote extended features page (%d)\n", page_num);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Process the pages */
|
|
|
|
btm_process_remote_ext_features (p_acl_cb, (UINT8) (page_num + 1));
|
|
|
|
|
|
|
|
/* Continue with HCI connection establishment */
|
|
|
|
btm_establish_continue (p_acl_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_remote_ext_features_failed
|
|
|
|
**
|
|
|
|
** Description This function is called when the remote extended features
|
|
|
|
** complete event returns a failed status.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_remote_ext_features_failed (UINT8 status, UINT16 handle)
|
|
|
|
{
|
|
|
|
tACL_CONN *p_acl_cb;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_WARNING ("btm_read_remote_ext_features_failed (status 0x%02x) for handle %d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
status, handle);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb == NULL) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("btm_read_remote_ext_features_failed handle=%d invalid\n", handle);
|
2020-07-01 14:35:54 -04:00
|
|
|
return;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process supported features only */
|
|
|
|
btm_process_remote_ext_features (p_acl_cb, 1);
|
|
|
|
|
|
|
|
/* Continue HCI connection establishment */
|
|
|
|
btm_establish_continue (p_acl_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_establish_continue
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the read local link policy request.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_establish_continue (tACL_CONN *p_acl_cb)
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
tBTM_BL_EVENT_DATA evt_data;
|
|
|
|
BTM_TRACE_DEBUG ("btm_establish_continue\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
#if (!defined(BTM_BYPASS_EXTRA_ACL_SETUP) || BTM_BYPASS_EXTRA_ACL_SETUP == FALSE)
|
|
|
|
#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_acl_cb->transport == BT_TRANSPORT_BR_EDR)
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
|
|
|
/* For now there are a some devices that do not like sending */
|
|
|
|
/* commands events and data at the same time. */
|
|
|
|
/* Set the packet types to the default allowed by the device */
|
|
|
|
btm_set_packet_types (p_acl_cb, btm_cb.btm_acl_pkt_types_supported);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.btm_def_link_policy) {
|
|
|
|
BTM_SetLinkPolicy (p_acl_cb->remote_addr, &btm_cb.btm_def_link_policy);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
p_acl_cb->link_up_issued = TRUE;
|
|
|
|
|
|
|
|
/* If anyone cares, tell him database changed */
|
|
|
|
if (btm_cb.p_bl_changed_cb) {
|
|
|
|
evt_data.event = BTM_BL_CONN_EVT;
|
|
|
|
evt_data.conn.p_bda = p_acl_cb->remote_addr;
|
|
|
|
evt_data.conn.p_bdn = p_acl_cb->remote_name;
|
|
|
|
evt_data.conn.p_dc = p_acl_cb->remote_dc;
|
|
|
|
evt_data.conn.p_features = p_acl_cb->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0];
|
2020-04-28 06:24:31 -04:00
|
|
|
evt_data.conn.sc_downgrade = p_acl_cb->sc_downgrade;
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BLE_INCLUDED == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
evt_data.conn.handle = p_acl_cb->hci_handle;
|
|
|
|
evt_data.conn.transport = p_acl_cb->transport;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
(*btm_cb.p_bl_changed_cb)(&evt_data);
|
|
|
|
}
|
|
|
|
btm_acl_update_busy_level (BTM_BLI_ACL_UP_EVT);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetDefaultLinkSuperTout
|
|
|
|
**
|
|
|
|
** Description Set the default value for HCI "Write Link Supervision Timeout"
|
|
|
|
** command to use when an ACL link is created.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTM_SetDefaultLinkSuperTout (UINT16 timeout)
|
|
|
|
{
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_SetDefaultLinkSuperTout\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.btm_def_link_super_tout = timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_GetLinkSuperTout
|
|
|
|
**
|
|
|
|
** Description Read the link supervision timeout value of the connection
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_GetLinkSuperTout (BD_ADDR remote_bda, UINT16 *p_timeout)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_GetLinkSuperTout\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_timeout = p->link_super_tout;
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_SUCCESS);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetLinkSuperTout
|
|
|
|
**
|
|
|
|
** Description Create and send HCI "Write Link Supervision Timeout" command
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetLinkSuperTout (BD_ADDR remote_bda, UINT16 timeout)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_SetLinkSuperTout\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->link_super_tout = timeout;
|
|
|
|
|
|
|
|
/* Only send if current role is Master; 2.0 spec requires this */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->link_role == BTM_ROLE_MASTER) {
|
2016-09-26 09:37:39 -04:00
|
|
|
if (!btsnd_hcic_write_link_super_tout (LOCAL_BR_EDR_CONTROLLER_ID,
|
2016-11-24 13:10:15 -05:00
|
|
|
p->hci_handle, timeout)) {
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_CMD_STARTED);
|
|
|
|
} else {
|
|
|
|
return (BTM_SUCCESS);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_IsAclConnectionUp
|
|
|
|
**
|
|
|
|
** Description This function is called to check if an ACL connection exists
|
|
|
|
** to a specific remote BD Address.
|
|
|
|
**
|
|
|
|
** Returns TRUE if connection is up, else FALSE.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN BTM_IsAclConnectionUp (BD_ADDR remote_bda, tBT_TRANSPORT transport)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_IsAclConnectionUp: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
remote_bda[0], remote_bda[1], remote_bda[2],
|
|
|
|
remote_bda[3], remote_bda[4], remote_bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p = btm_bda_to_acl(remote_bda, transport);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
|
|
|
return (TRUE);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (FALSE);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_GetNumAclLinks
|
|
|
|
**
|
|
|
|
** Description This function is called to count the number of
|
|
|
|
** ACL links that are active.
|
|
|
|
**
|
|
|
|
** Returns UINT16 Number of active ACL links
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT16 BTM_GetNumAclLinks (void)
|
|
|
|
{
|
|
|
|
uint16_t num_acl = 0;
|
|
|
|
|
2020-07-01 14:35:54 -04:00
|
|
|
num_acl = list_length(btm_cb.p_acl_db_list);
|
2016-09-26 09:37:39 -04:00
|
|
|
return num_acl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_get_acl_disc_reason_code
|
|
|
|
**
|
|
|
|
** Description This function is called to get the disconnection reason code
|
|
|
|
** returned by the HCI at disconnection complete event.
|
|
|
|
**
|
|
|
|
** Returns TRUE if connection is up, else FALSE.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT16 btm_get_acl_disc_reason_code (void)
|
|
|
|
{
|
|
|
|
UINT8 res = btm_cb.acl_disc_reason;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_get_acl_disc_reason_code\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
return (res);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_GetHCIConnHandle
|
|
|
|
**
|
|
|
|
** Description This function is called to get the handle for an ACL connection
|
|
|
|
** to a specific remote BD Address.
|
|
|
|
**
|
|
|
|
** Returns the handle of the connection, or 0xFFFF if none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT16 BTM_GetHCIConnHandle (BD_ADDR remote_bda, tBT_TRANSPORT transport)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_GetHCIConnHandle\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
p = btm_bda_to_acl(remote_bda, transport);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
|
|
|
return (p->hci_handle);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (0xFFFF);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_process_clk_off_comp_evt
|
|
|
|
**
|
|
|
|
** Description This function is called when clock offset command completes.
|
|
|
|
**
|
|
|
|
** Input Parms hci_handle - connection handle associated with the change
|
|
|
|
** clock offset
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_process_clk_off_comp_evt (UINT16 hci_handle, UINT16 clock_offset)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_process_clk_off_comp_evt\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Look up the connection by handle and set the current mode */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(hci_handle);
|
|
|
|
if (p_acl_cb) {
|
|
|
|
p_acl_cb->clock_offset = clock_offset;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_role_changed
|
|
|
|
**
|
|
|
|
** Description This function is called whan a link's master/slave role change
|
|
|
|
** event or command status event (with error) is received.
|
|
|
|
** It updates the link control block, and calls
|
|
|
|
** the registered callback with status and role (if registered).
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_role_changed (UINT8 hci_status, BD_ADDR bd_addr, UINT8 new_role)
|
|
|
|
{
|
|
|
|
UINT8 *p_bda = (bd_addr) ? bd_addr :
|
2016-11-24 13:10:15 -05:00
|
|
|
btm_cb.devcb.switch_role_ref_data.remote_bd_addr;
|
2016-09-26 09:37:39 -04:00
|
|
|
tACL_CONN *p = btm_bda_to_acl(p_bda, BT_TRANSPORT_BR_EDR);
|
|
|
|
tBTM_ROLE_SWITCH_CMPL *p_data = &btm_cb.devcb.switch_role_ref_data;
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec;
|
|
|
|
tBTM_BL_ROLE_CHG_DATA evt;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_role_changed\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Ignore any stray events */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p == NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* it could be a failure */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (hci_status != HCI_SUCCESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_acl_report_role_change(hci_status, bd_addr);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_data->hci_status = hci_status;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (hci_status == HCI_SUCCESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_data->role = new_role;
|
|
|
|
memcpy(p_data->remote_bd_addr, p_bda, BD_ADDR_LEN);
|
|
|
|
|
|
|
|
/* Update cached value */
|
|
|
|
p->link_role = new_role;
|
|
|
|
|
|
|
|
/* Reload LSTO: link supervision timeout is reset in the LM after a role switch */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (new_role == BTM_ROLE_MASTER) {
|
2016-09-26 09:37:39 -04:00
|
|
|
BTM_SetLinkSuperTout (p->remote_addr, p->link_super_tout);
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* so the BTM_BL_ROLE_CHG_EVT uses the old role */
|
|
|
|
new_role = p->link_role;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if any SCO req is pending for role change */
|
|
|
|
btm_sco_chk_pend_rolechange (p->hci_handle);
|
|
|
|
|
|
|
|
/* if switching state is switching we need to turn encryption on */
|
|
|
|
/* if idle, we did not change encryption */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) {
|
|
|
|
if (btsnd_hcic_set_conn_encrypt (p->hci_handle, TRUE)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON;
|
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the switch_role_state to IDLE since the reply received from HCI */
|
|
|
|
/* regardless of its result either success or failed. */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
|
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if role switch complete is needed, report it now */
|
|
|
|
btm_acl_report_role_change(hci_status, bd_addr);
|
|
|
|
|
|
|
|
/* if role change event is registered, report it now */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.p_bl_changed_cb && (btm_cb.bl_evt_mask & BTM_BL_ROLE_CHG_MASK)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
evt.event = BTM_BL_ROLE_CHG_EVT;
|
|
|
|
evt.new_role = new_role;
|
|
|
|
evt.p_bda = p_bda;
|
|
|
|
evt.hci_status = hci_status;
|
|
|
|
(*btm_cb.p_bl_changed_cb)((tBTM_BL_EVENT_DATA *)&evt);
|
|
|
|
}
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG("Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
p_data->role, p_data->hci_status, p->switch_role_state);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#if BTM_DISC_DURING_RS == TRUE
|
|
|
|
/* If a disconnect is pending, issue it now that role switch has completed */
|
2016-11-24 13:10:15 -05:00
|
|
|
if ((p_dev_rec = btm_find_dev (p_bda)) != NULL) {
|
|
|
|
if (p_dev_rec->rs_disc_pending == BTM_SEC_DISC_PENDING) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_WARNING("btm_acl_role_changed -> Issuing delayed HCI_Disconnect!!!\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btsnd_hcic_disconnect(p_dev_rec->hci_handle, HCI_ERR_PEER_USER);
|
|
|
|
}
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("tBTM_SEC_DEV:0x%x rs_disc_pending=%d\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
(UINT32)p_dev_rec, p_dev_rec->rs_disc_pending);
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_NOT_PENDING; /* reset flag */
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_AllocateSCN
|
|
|
|
**
|
|
|
|
** Description Look through the Server Channel Numbers for a free one.
|
|
|
|
**
|
|
|
|
** Returns Allocated SCN number or 0 if none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-04-24 23:46:37 -04:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
UINT8 BTM_AllocateSCN(void)
|
|
|
|
{
|
|
|
|
UINT8 x;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_AllocateSCN\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
for (x = 1; x < BTM_MAX_SCN; x++) {
|
2018-09-13 08:17:37 -04:00
|
|
|
if (!btm_cb.btm_scn[x - 1]) {
|
|
|
|
btm_cb.btm_scn[x - 1] = TRUE;
|
|
|
|
return x;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
return (0); /* No free ports */
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2017-04-24 23:46:37 -04:00
|
|
|
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_TryAllocateSCN
|
|
|
|
**
|
|
|
|
** Description Try to allocate a fixed server channel
|
|
|
|
**
|
|
|
|
** Returns Returns TRUE if server channel was available
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-04-24 23:46:37 -04:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
|
|
|
|
{
|
2018-09-13 08:17:37 -04:00
|
|
|
if (scn >= BTM_MAX_SCN) {
|
2016-09-26 09:37:39 -04:00
|
|
|
return FALSE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* check if this port is available */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!btm_cb.btm_scn[scn - 1]) {
|
|
|
|
btm_cb.btm_scn[scn - 1] = TRUE;
|
2016-09-26 09:37:39 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (FALSE); /* Port was busy */
|
|
|
|
}
|
|
|
|
|
2017-04-24 23:46:37 -04:00
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_FreeSCN
|
|
|
|
**
|
|
|
|
** Description Free the specified SCN.
|
|
|
|
**
|
|
|
|
** Returns TRUE or FALSE
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN BTM_FreeSCN(UINT8 scn)
|
|
|
|
{
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_FreeSCN \n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (scn <= BTM_MAX_SCN) {
|
|
|
|
btm_cb.btm_scn[scn - 1] = FALSE;
|
|
|
|
return (TRUE);
|
|
|
|
} else {
|
|
|
|
return (FALSE); /* Illegal SCN passed in */
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2017-04-17 22:53:43 -04:00
|
|
|
return (FALSE);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2017-04-24 23:46:37 -04:00
|
|
|
#endif ///CLASSIC_BT_INCLUDED == TRUE
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_set_packet_types
|
|
|
|
**
|
|
|
|
** Description This function sets the packet types used for a specific
|
|
|
|
** ACL connection. It is called internally by btm_acl_created
|
|
|
|
** or by an application/profile by BTM_SetPacketTypes.
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS btm_set_packet_types (tACL_CONN *p, UINT16 pkt_types)
|
|
|
|
{
|
|
|
|
UINT16 temp_pkt_types;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_set_packet_types\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Save in the ACL control blocks, types that we support */
|
|
|
|
temp_pkt_types = (pkt_types & BTM_ACL_SUPPORTED_PKTS_MASK &
|
|
|
|
btm_cb.btm_acl_pkt_types_supported);
|
|
|
|
|
|
|
|
/* OR in any exception packet types if at least 2.0 version of spec */
|
|
|
|
temp_pkt_types |= ((pkt_types & BTM_ACL_EXCEPTION_PKTS_MASK) |
|
|
|
|
(btm_cb.btm_acl_pkt_types_supported & BTM_ACL_EXCEPTION_PKTS_MASK));
|
|
|
|
|
|
|
|
/* Exclude packet types not supported by the peer */
|
|
|
|
btm_acl_chk_peer_pkt_type_support (p, &temp_pkt_types);
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("SetPacketType Mask -> 0x%04x\n", temp_pkt_types);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!btsnd_hcic_change_conn_type (p->hci_handle, temp_pkt_types)) {
|
|
|
|
return (BTM_NO_RESOURCES);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
p->pkt_types_mask = temp_pkt_types;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_CMD_STARTED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_get_max_packet_size
|
|
|
|
**
|
|
|
|
** Returns Returns maximum packet size that can be used for current
|
|
|
|
** connection, 0 if connection is not established
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT16 btm_get_max_packet_size (BD_ADDR addr)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
|
|
|
|
UINT16 pkt_types = 0;
|
|
|
|
UINT16 pkt_size = 0;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_get_max_packet_size\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_types = p->pkt_types_mask;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Special case for when info for the local device is requested */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (memcmp (controller_get_interface()->get_address(), addr, BD_ADDR_LEN) == 0) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_types = btm_cb.btm_acl_pkt_types_supported;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (pkt_types) {
|
|
|
|
if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH5)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_EDR3_DH5_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH5)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_EDR2_DH5_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH3)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_EDR3_DH3_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH5) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_DH5_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH3)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_EDR2_DH3_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM5) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_DM5_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH3) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_DH3_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM3) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_DM3_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_3_DH1)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_EDR3_DH1_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (!(pkt_types & BTM_ACL_PKT_TYPES_MASK_NO_2_DH1)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_EDR2_DH1_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DH1) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_DH1_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (pkt_types & BTM_ACL_PKT_TYPES_MASK_DM1) {
|
2016-09-26 09:37:39 -04:00
|
|
|
pkt_size = HCI_DM1_PACKET_SIZE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (pkt_size);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadRemoteVersion
|
|
|
|
**
|
|
|
|
** Returns If connected report peer device info
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_ReadRemoteVersion (BD_ADDR addr, UINT8 *lmp_version,
|
|
|
|
UINT16 *manufacturer, UINT16 *lmp_sub_version)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_ReadRemoteVersion\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p == NULL) {
|
|
|
|
return (BTM_UNKNOWN_ADDR);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (lmp_version) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*lmp_version = p->lmp_version;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (manufacturer) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*manufacturer = p->manufacturer;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (lmp_sub_version) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*lmp_sub_version = p->lmp_subversion;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_SUCCESS);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadRemoteFeatures
|
|
|
|
**
|
|
|
|
** Returns pointer to the remote supported features mask (8 bytes)
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 *BTM_ReadRemoteFeatures (BD_ADDR addr)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_ReadRemoteFeatures\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p == NULL) {
|
|
|
|
return (NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadRemoteExtendedFeatures
|
|
|
|
**
|
|
|
|
** Returns pointer to the remote extended features mask (8 bytes)
|
|
|
|
** or NULL if bad page
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 *BTM_ReadRemoteExtendedFeatures (BD_ADDR addr, UINT8 page_number)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_ReadRemoteExtendedFeatures\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p == NULL) {
|
|
|
|
return (NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (page_number > HCI_EXT_FEATURES_PAGE_MAX) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_ERROR("Warning: BTM_ReadRemoteExtendedFeatures page %d unknown\n", page_number);
|
2016-09-26 09:37:39 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (p->peer_lmp_features[page_number]);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadNumberRemoteFeaturesPages
|
|
|
|
**
|
|
|
|
** Returns number of features pages read from the remote device.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 BTM_ReadNumberRemoteFeaturesPages (BD_ADDR addr)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_ReadNumberRemoteFeaturesPages\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p == NULL) {
|
|
|
|
return (0);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (p->num_read_pages);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadAllRemoteFeatures
|
|
|
|
**
|
|
|
|
** Returns pointer to all features of the remote (24 bytes).
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 *BTM_ReadAllRemoteFeatures (BD_ADDR addr)
|
|
|
|
{
|
|
|
|
tACL_CONN *p = btm_bda_to_acl(addr, BT_TRANSPORT_BR_EDR);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_ReadAllRemoteFeatures\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p == NULL) {
|
|
|
|
return (NULL);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_RegBusyLevelNotif
|
|
|
|
**
|
|
|
|
** Description This function is called to register a callback to receive
|
|
|
|
** busy level change events.
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if successfully registered, otherwise error
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_RegBusyLevelNotif (tBTM_BL_CHANGE_CB *p_cb, UINT8 *p_level,
|
|
|
|
tBTM_BL_EVENT_MASK evt_mask)
|
|
|
|
{
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_RegBusyLevelNotif\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_level) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_level = btm_cb.busy_level;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
btm_cb.bl_evt_mask = evt_mask;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.p_bl_changed_cb = NULL;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else if (btm_cb.p_bl_changed_cb) {
|
|
|
|
return (BTM_BUSY);
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.p_bl_changed_cb = p_cb;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_SUCCESS);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
2022-07-28 00:32:56 -04:00
|
|
|
|
|
|
|
tBTM_STATUS BTM_RegAclLinkStatNotif(tBTM_ACL_LINK_STAT_CB *p_cb)
|
|
|
|
{
|
|
|
|
BTM_TRACE_DEBUG ("BTM_RegAclLinkStatNotif\n");
|
|
|
|
|
|
|
|
if (!p_cb) {
|
|
|
|
btm_cb.p_acl_link_stat_cb = NULL;
|
|
|
|
} else if (btm_cb.p_acl_link_stat_cb) {
|
|
|
|
return BTM_BUSY;
|
|
|
|
} else {
|
|
|
|
btm_cb.p_acl_link_stat_cb = p_cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BTM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetQoS
|
|
|
|
**
|
|
|
|
** Description This function is called to setup QoS
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetQoS (BD_ADDR bd, FLOW_SPEC *p_flow, tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p = NULL;
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_SetQoS: BdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
bd[0], bd[1], bd[2],
|
|
|
|
bd[3], bd[4], bd[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* If someone already waiting on the version, do not allow another */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.devcb.p_qossu_cmpl_cb) {
|
|
|
|
return (BTM_BUSY);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if ( (p = btm_bda_to_acl(bd, BT_TRANSPORT_BR_EDR)) != NULL) {
|
2021-01-04 21:32:47 -05:00
|
|
|
btu_start_timer (&btm_cb.devcb.qossu_timer, BTU_TTYPE_BTM_QOS, BTM_DEV_REPLY_TIMEOUT);
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.devcb.p_qossu_cmpl_cb = p_cb;
|
|
|
|
|
|
|
|
if (!btsnd_hcic_qos_setup (p->hci_handle, p_flow->qos_flags, p_flow->service_type,
|
|
|
|
p_flow->token_rate, p_flow->peak_bandwidth,
|
2016-11-24 13:10:15 -05:00
|
|
|
p_flow->latency, p_flow->delay_variation)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.devcb.p_qossu_cmpl_cb = NULL;
|
|
|
|
btu_stop_timer(&btm_cb.devcb.qossu_timer);
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
} else {
|
|
|
|
return (BTM_CMD_STARTED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_qos_setup_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the qos setup request.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_qos_setup_complete (UINT8 status, UINT16 handle, FLOW_SPEC *p_flow)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_qossu_cmpl_cb;
|
|
|
|
tBTM_QOS_SETUP_CMPL qossu;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_qos_setup_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_stop_timer (&btm_cb.devcb.qossu_timer);
|
|
|
|
|
|
|
|
btm_cb.devcb.p_qossu_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
memset(&qossu, 0, sizeof(tBTM_QOS_SETUP_CMPL));
|
|
|
|
qossu.status = status;
|
|
|
|
qossu.handle = handle;
|
2021-01-04 21:32:47 -05:00
|
|
|
tACL_CONN *p = btm_handle_to_acl(handle);
|
|
|
|
if (p != NULL) {
|
|
|
|
memcpy (qossu.rem_bda, p->remote_addr, BD_ADDR_LEN);
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_flow != NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
qossu.flow.qos_flags = p_flow->qos_flags;
|
|
|
|
qossu.flow.service_type = p_flow->service_type;
|
|
|
|
qossu.flow.token_rate = p_flow->token_rate;
|
|
|
|
qossu.flow.peak_bandwidth = p_flow->peak_bandwidth;
|
|
|
|
qossu.flow.latency = p_flow->latency;
|
|
|
|
qossu.flow.delay_variation = p_flow->delay_variation;
|
|
|
|
}
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM: p_flow->delay_variation: 0x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
qossu.flow.delay_variation);
|
2016-09-26 09:37:39 -04:00
|
|
|
(*p_cb)(&qossu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 21:32:47 -05:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_qos_setup_timeout
|
|
|
|
**
|
|
|
|
** Description This function processes a timeout.
|
|
|
|
** Currently, we just report an error log
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_qos_setup_timeout (void *p_tle)
|
|
|
|
{
|
|
|
|
BTM_TRACE_DEBUG ("%s\n", __func__);
|
|
|
|
|
|
|
|
btm_qos_setup_complete (HCI_ERR_HOST_TIMEOUT, 0, NULL);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadRSSI
|
|
|
|
**
|
|
|
|
** Description This function is called to read the link policy settings.
|
|
|
|
** The address of link policy results are returned in the callback.
|
|
|
|
** (tBTM_RSSI_RESULTS)
|
|
|
|
**
|
|
|
|
** Returns BTM_CMD_STARTED if successfully initiated or error code
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2018-06-21 09:43:46 -04:00
|
|
|
tBTM_STATUS BTM_ReadRSSI (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
2018-06-21 09:43:46 -04:00
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_ReadRSSI: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
remote_bda[0], remote_bda[1], remote_bda[2],
|
|
|
|
remote_bda[3], remote_bda[4], remote_bda[5]);
|
2017-08-14 23:24:36 -04:00
|
|
|
tBTM_RSSI_RESULTS result;
|
2016-09-26 09:37:39 -04:00
|
|
|
/* If someone already waiting on the version, do not allow another */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.devcb.p_rssi_cmpl_cb) {
|
2017-08-14 23:24:36 -04:00
|
|
|
result.status = BTM_BUSY;
|
|
|
|
(*p_cb)(&result);
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_BUSY);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p = btm_bda_to_acl(remote_bda, transport);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_start_timer (&btm_cb.devcb.rssi_timer, BTU_TTYPE_BTM_ACL,
|
|
|
|
BTM_DEV_REPLY_TIMEOUT);
|
|
|
|
|
|
|
|
btm_cb.devcb.p_rssi_cmpl_cb = p_cb;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!btsnd_hcic_read_rssi (p->hci_handle)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.devcb.p_rssi_cmpl_cb = NULL;
|
|
|
|
btu_stop_timer (&btm_cb.devcb.rssi_timer);
|
2017-08-14 23:24:36 -04:00
|
|
|
result.status = BTM_NO_RESOURCES;
|
|
|
|
(*p_cb)(&result);
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
} else {
|
|
|
|
return (BTM_CMD_STARTED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadLinkQuality
|
|
|
|
**
|
|
|
|
** Description This function is called to read the link qulaity.
|
|
|
|
** The value of the link quality is returned in the callback.
|
|
|
|
** (tBTM_LINK_QUALITY_RESULTS)
|
|
|
|
**
|
|
|
|
** Returns BTM_CMD_STARTED if successfully initiated or error code
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_ReadLinkQuality (BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_ReadLinkQuality: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
remote_bda[0], remote_bda[1], remote_bda[2],
|
|
|
|
remote_bda[3], remote_bda[4], remote_bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* If someone already waiting on the version, do not allow another */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.devcb.p_lnk_qual_cmpl_cb) {
|
|
|
|
return (BTM_BUSY);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_start_timer (&btm_cb.devcb.lnk_quality_timer, BTU_TTYPE_BTM_ACL,
|
|
|
|
BTM_DEV_REPLY_TIMEOUT);
|
|
|
|
btm_cb.devcb.p_lnk_qual_cmpl_cb = p_cb;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!btsnd_hcic_get_link_quality (p->hci_handle)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
|
|
|
|
btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
} else {
|
|
|
|
return (BTM_CMD_STARTED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_UNKNOWN_ADDR);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadTxPower
|
|
|
|
**
|
|
|
|
** Description This function is called to read the current
|
|
|
|
** TX power of the connection. The tx power level results
|
|
|
|
** are returned in the callback.
|
|
|
|
** (tBTM_RSSI_RESULTS)
|
|
|
|
**
|
|
|
|
** Returns BTM_CMD_STARTED if successfully initiated or error code
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_ReadTxPower (BD_ADDR remote_bda, tBT_TRANSPORT transport, tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
tACL_CONN *p;
|
|
|
|
BOOLEAN ret;
|
|
|
|
#define BTM_READ_RSSI_TYPE_CUR 0x00
|
|
|
|
#define BTM_READ_RSSI_TYPE_MAX 0X01
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_API ("BTM_ReadTxPower: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
remote_bda[0], remote_bda[1], remote_bda[2],
|
|
|
|
remote_bda[3], remote_bda[4], remote_bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* If someone already waiting on the version, do not allow another */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.devcb.p_tx_power_cmpl_cb) {
|
|
|
|
return (BTM_BUSY);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
p = btm_bda_to_acl(remote_bda, transport);
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p != (tACL_CONN *)NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
|
|
|
|
BTM_DEV_REPLY_TIMEOUT);
|
|
|
|
|
|
|
|
btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
|
|
|
|
|
|
|
|
#if BLE_INCLUDED == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->transport == BT_TRANSPORT_LE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
memcpy(btm_cb.devcb.read_tx_pwr_addr, remote_bda, BD_ADDR_LEN);
|
|
|
|
ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
|
2016-11-24 13:10:15 -05:00
|
|
|
} else
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ret = btsnd_hcic_read_tx_power (p->hci_handle, BTM_READ_RSSI_TYPE_CUR);
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!ret) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
|
|
|
|
btu_stop_timer (&btm_cb.devcb.tx_power_timer);
|
2016-11-24 13:10:15 -05:00
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
} else {
|
|
|
|
return (BTM_CMD_STARTED);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If here, no BD Addr found */
|
|
|
|
return (BTM_UNKNOWN_ADDR);
|
|
|
|
}
|
2018-11-11 22:08:19 -05:00
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2017-08-14 23:24:36 -04:00
|
|
|
tBTM_STATUS BTM_BleReadAdvTxPower(tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
BOOLEAN ret;
|
|
|
|
tBTM_TX_POWER_RESULTS result;
|
|
|
|
/* If someone already waiting on the version, do not allow another */
|
|
|
|
if (btm_cb.devcb.p_tx_power_cmpl_cb) {
|
|
|
|
result.status = BTM_BUSY;
|
|
|
|
(*p_cb)(&result);
|
|
|
|
return (BTM_BUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
btm_cb.devcb.p_tx_power_cmpl_cb = p_cb;
|
|
|
|
btu_start_timer (&btm_cb.devcb.tx_power_timer, BTU_TTYPE_BTM_ACL,
|
|
|
|
BTM_DEV_REPLY_TIMEOUT);
|
|
|
|
ret = btsnd_hcic_ble_read_adv_chnl_tx_power();
|
|
|
|
|
|
|
|
if(!ret) {
|
|
|
|
btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
|
|
|
|
btu_stop_timer (&btm_cb.devcb.tx_power_timer);
|
|
|
|
result.status = BTM_NO_RESOURCES;
|
|
|
|
(*p_cb)(&result);
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
} else {
|
|
|
|
return BTM_CMD_STARTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BTM_BleGetWhiteListSize(uint16_t *length)
|
|
|
|
{
|
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
|
|
|
if (p_cb->white_list_avail_size == 0) {
|
2019-12-09 02:21:49 -05:00
|
|
|
BTM_TRACE_WARNING("%s Whitelist full.", __func__);
|
2017-08-14 23:24:36 -04:00
|
|
|
}
|
|
|
|
*length = p_cb->white_list_avail_size;
|
|
|
|
return;
|
|
|
|
}
|
2018-11-11 22:08:19 -05:00
|
|
|
#endif ///BLE_INCLUDED == TRUE
|
2017-08-14 23:24:36 -04:00
|
|
|
|
2016-09-26 09:37:39 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_tx_power_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the read tx power request.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_tx_power_complete (UINT8 *p, BOOLEAN is_ble)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_tx_power_cmpl_cb;
|
|
|
|
tBTM_TX_POWER_RESULTS results;
|
|
|
|
UINT16 handle;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_read_tx_power_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_stop_timer (&btm_cb.devcb.tx_power_timer);
|
|
|
|
|
|
|
|
/* If there was a callback registered for read rssi, call it */
|
|
|
|
btm_cb.devcb.p_tx_power_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
STREAM_TO_UINT8 (results.hci_status, p);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (results.hci_status == HCI_SUCCESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
results.status = BTM_SUCCESS;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!is_ble) {
|
2016-09-26 09:37:39 -04:00
|
|
|
STREAM_TO_UINT16 (handle, p);
|
|
|
|
STREAM_TO_UINT8 (results.tx_power, p);
|
|
|
|
|
|
|
|
/* Search through the list of active channels for the correct BD Addr */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb) {
|
|
|
|
memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
#if BLE_INCLUDED == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
else {
|
2016-09-26 09:37:39 -04:00
|
|
|
STREAM_TO_UINT8 (results.tx_power, p);
|
|
|
|
memcpy(results.rem_bda, btm_cb.devcb.read_tx_pwr_addr, BD_ADDR_LEN);
|
|
|
|
}
|
|
|
|
#endif
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM TX power Complete: tx_power %d, hci status 0x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
results.tx_power, results.hci_status);
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
results.status = BTM_ERR_PROCESSING;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
(*p_cb)(&results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_rssi_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the read rssi request.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_rssi_complete (UINT8 *p)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
|
|
|
|
tBTM_RSSI_RESULTS results;
|
|
|
|
UINT16 handle;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_read_rssi_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_stop_timer (&btm_cb.devcb.rssi_timer);
|
|
|
|
|
|
|
|
/* If there was a callback registered for read rssi, call it */
|
|
|
|
btm_cb.devcb.p_rssi_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
STREAM_TO_UINT8 (results.hci_status, p);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (results.hci_status == HCI_SUCCESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
results.status = BTM_SUCCESS;
|
|
|
|
|
|
|
|
STREAM_TO_UINT16 (handle, p);
|
|
|
|
|
|
|
|
STREAM_TO_UINT8 (results.rssi, p);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM RSSI Complete: rssi %d, hci status 0x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
results.rssi, results.hci_status);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Search through the list of active channels for the correct BD Addr */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb) {
|
|
|
|
memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
results.status = BTM_ERR_PROCESSING;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
(*p_cb)(&results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_link_quality_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the read link quality.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_link_quality_complete (UINT8 *p)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_lnk_qual_cmpl_cb;
|
|
|
|
tBTM_LINK_QUALITY_RESULTS results;
|
|
|
|
UINT16 handle;
|
2020-07-01 14:35:54 -04:00
|
|
|
tACL_CONN *p_acl_cb = NULL;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_read_link_quality_complete\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_stop_timer (&btm_cb.devcb.lnk_quality_timer);
|
|
|
|
|
|
|
|
/* If there was a callback registered for read rssi, call it */
|
|
|
|
btm_cb.devcb.p_lnk_qual_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_cb) {
|
2016-09-26 09:37:39 -04:00
|
|
|
STREAM_TO_UINT8 (results.hci_status, p);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (results.hci_status == HCI_SUCCESS) {
|
2016-09-26 09:37:39 -04:00
|
|
|
results.status = BTM_SUCCESS;
|
|
|
|
|
|
|
|
STREAM_TO_UINT16 (handle, p);
|
|
|
|
|
|
|
|
STREAM_TO_UINT8 (results.link_quality, p);
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM Link Quality Complete: Link Quality %d, hci status 0x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
results.link_quality, results.hci_status);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* Search through the list of active channels for the correct BD Addr */
|
2020-07-01 14:35:54 -04:00
|
|
|
p_acl_cb = btm_handle_to_acl(handle);
|
|
|
|
if (p_acl_cb) {
|
|
|
|
memcpy (results.rem_bda, p_acl_cb->remote_addr, BD_ADDR_LEN);
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
results.status = BTM_ERR_PROCESSING;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
(*p_cb)(&results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_remove_acl
|
|
|
|
**
|
|
|
|
** Description This function is called to disconnect an ACL connection
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if successfully initiated, otherwise BTM_NO_RESOURCES.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS btm_remove_acl (BD_ADDR bd_addr, tBT_TRANSPORT transport)
|
|
|
|
{
|
|
|
|
UINT16 hci_handle = BTM_GetHCIConnHandle(bd_addr, transport);
|
|
|
|
tBTM_STATUS status = BTM_SUCCESS;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_remove_acl\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
#if BTM_DISC_DURING_RS == TRUE
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
|
|
|
|
|
|
|
|
/* Role Switch is pending, postpone until completed */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec && (p_dev_rec->rs_disc_pending == BTM_SEC_RS_PENDING)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->rs_disc_pending = BTM_SEC_DISC_PENDING;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else /* otherwise can disconnect right away */
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (hci_handle != 0xFFFF && p_dev_rec &&
|
2016-11-24 13:10:15 -05:00
|
|
|
p_dev_rec->sec_state != BTM_SEC_STATE_DISCONNECTING) {
|
|
|
|
if (!btsnd_hcic_disconnect (hci_handle, HCI_ERR_PEER_USER)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
status = BTM_NO_RESOURCES;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
status = BTM_UNKNOWN_ADDR;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetTraceLevel
|
|
|
|
**
|
|
|
|
** Description This function sets the trace level for BTM. If called with
|
|
|
|
** a value of 0xFF, it simply returns the current trace level.
|
|
|
|
**
|
|
|
|
** Returns The new or current trace level
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 BTM_SetTraceLevel (UINT8 new_level)
|
|
|
|
{
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("BTM_SetTraceLevel\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
if (new_level != 0xFF) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.trace_level = new_level;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return (btm_cb.trace_level);
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_cont_rswitch
|
|
|
|
**
|
|
|
|
** Description This function is called to continue processing an active
|
|
|
|
** role switch. It first disables encryption if enabled and
|
|
|
|
** EPR is not supported
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_cont_rswitch (tACL_CONN *p, tBTM_SEC_DEV_REC *p_dev_rec,
|
2016-11-24 13:10:15 -05:00
|
|
|
UINT8 hci_status)
|
2016-09-26 09:37:39 -04:00
|
|
|
{
|
|
|
|
BOOLEAN sw_ok = TRUE;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_cont_rswitch\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Check to see if encryption needs to be turned off if pending
|
|
|
|
change of link key or role switch */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Must turn off Encryption first if necessary */
|
|
|
|
/* Some devices do not support switch or change of link key while encryption is on */
|
|
|
|
if (p_dev_rec != NULL && ((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0)
|
2016-11-24 13:10:15 -05:00
|
|
|
&& !BTM_EPR_AVAILABLE(p)) {
|
|
|
|
if (btsnd_hcic_set_conn_encrypt (p->hci_handle, FALSE)) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->encrypt_state = BTM_ACL_ENCRYPT_STATE_ENCRYPT_OFF;
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Error occurred; set states back to Idle */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
sw_ok = FALSE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
} else /* Encryption not used or EPR supported, continue with switch
|
2016-09-26 09:37:39 -04:00
|
|
|
and/or change of link key */
|
|
|
|
{
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
|
|
|
|
#if BTM_DISC_DURING_RS == TRUE
|
2016-11-24 13:10:15 -05:00
|
|
|
if (p_dev_rec) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
sw_ok = btsnd_hcic_switch_role (p->remote_addr, (UINT8)!p->link_role);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!sw_ok) {
|
2016-09-26 09:37:39 -04:00
|
|
|
p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
|
|
|
|
btm_acl_report_role_change(hci_status, p->remote_addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_resubmit_page
|
|
|
|
**
|
|
|
|
** Description send pending page request
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_resubmit_page (void)
|
|
|
|
{
|
2017-04-19 03:44:01 -04:00
|
|
|
#if (SMP_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec;
|
|
|
|
BT_HDR *p_buf;
|
|
|
|
UINT8 *pp;
|
|
|
|
BD_ADDR bda;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_resubmit_page\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
/* If there were other page request schedule can start the next one */
|
2019-04-17 23:57:28 -04:00
|
|
|
if ((p_buf = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* skip 3 (2 bytes opcode and 1 byte len) to get to the bd_addr
|
|
|
|
* for both create_conn and rmt_name */
|
|
|
|
pp = (UINT8 *)(p_buf + 1) + p_buf->offset + 3;
|
|
|
|
|
|
|
|
STREAM_TO_BDADDR (bda, pp);
|
|
|
|
|
|
|
|
p_dev_rec = btm_find_or_alloc_dev (bda);
|
|
|
|
|
|
|
|
memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
|
|
|
|
memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
|
|
|
|
|
|
|
|
btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p_buf);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.paging = FALSE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2017-04-19 03:44:01 -04:00
|
|
|
#endif ///SMP_INCLUDED == TRUE
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_reset_paging
|
|
|
|
**
|
|
|
|
** Description set paging to FALSE and free the page queue - called at hci_reset
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_reset_paging (void)
|
|
|
|
{
|
|
|
|
BT_HDR *p;
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_reset_paging\n");
|
2016-09-26 09:37:39 -04:00
|
|
|
/* If we sent reset we are definitely not paging any more */
|
2019-04-17 23:57:28 -04:00
|
|
|
while ((p = (BT_HDR *)fixed_queue_dequeue(btm_cb.page_queue, 0)) != NULL) {
|
2017-08-17 09:13:45 -04:00
|
|
|
osi_free (p);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
btm_cb.paging = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_paging
|
|
|
|
**
|
|
|
|
** Description send a paging command or queue it in btm_cb
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-04-24 23:46:37 -04:00
|
|
|
#if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
void btm_acl_paging (BT_HDR *p, BD_ADDR bda)
|
|
|
|
{
|
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec;
|
|
|
|
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_paging discing:%d, paging:%d BDA: %06x%06x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
btm_cb.discing, btm_cb.paging,
|
|
|
|
(bda[0] << 16) + (bda[1] << 8) + bda[2], (bda[3] << 16) + (bda[4] << 8) + bda[5]);
|
|
|
|
if (btm_cb.discing) {
|
2016-09-26 09:37:39 -04:00
|
|
|
btm_cb.paging = TRUE;
|
2019-04-17 23:57:28 -04:00
|
|
|
fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
|
|
|
if (!BTM_ACL_IS_CONNECTED (bda)) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("connecting_bda: %06x%06x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
(btm_cb.connecting_bda[0] << 16) + (btm_cb.connecting_bda[1] << 8) +
|
|
|
|
btm_cb.connecting_bda[2],
|
|
|
|
(btm_cb.connecting_bda[3] << 16) + (btm_cb.connecting_bda[4] << 8) +
|
|
|
|
btm_cb.connecting_bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
if (btm_cb.paging &&
|
2016-11-24 13:10:15 -05:00
|
|
|
memcmp (bda, btm_cb.connecting_bda, BD_ADDR_LEN) != 0) {
|
2019-04-17 23:57:28 -04:00
|
|
|
fixed_queue_enqueue(btm_cb.page_queue, p, FIXED_QUEUE_MAX_TIMEOUT);
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
p_dev_rec = btm_find_or_alloc_dev (bda);
|
|
|
|
memcpy (btm_cb.connecting_bda, p_dev_rec->bd_addr, BD_ADDR_LEN);
|
|
|
|
memcpy (btm_cb.connecting_dc, p_dev_rec->dev_class, DEV_CLASS_LEN);
|
|
|
|
|
|
|
|
btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
btm_cb.paging = TRUE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else { /* ACL is already up */
|
2016-09-26 09:37:39 -04:00
|
|
|
btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-24 23:46:37 -04:00
|
|
|
#endif ///SMP_INCLUDED == TRUE
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_notif_conn_collision
|
|
|
|
**
|
|
|
|
** Description Send connection collision event to upper layer if registered
|
|
|
|
**
|
|
|
|
** Returns TRUE if sent out to upper layer,
|
|
|
|
** FALSE if no one needs the notification.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_acl_notif_conn_collision (BD_ADDR bda)
|
|
|
|
{
|
|
|
|
tBTM_BL_EVENT_DATA evt_data;
|
|
|
|
|
|
|
|
/* Report possible collision to the upper layer. */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (btm_cb.p_bl_changed_cb) {
|
2016-10-24 04:17:55 -04:00
|
|
|
BTM_TRACE_DEBUG ("btm_acl_notif_conn_collision: RemBdAddr: %02x%02x%02x%02x%02x%02x\n",
|
2016-11-24 13:10:15 -05:00
|
|
|
bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
evt_data.event = BTM_BL_COLLISION_EVT;
|
|
|
|
evt_data.conn.p_bda = bda;
|
|
|
|
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
evt_data.conn.transport = BT_TRANSPORT_BR_EDR;
|
|
|
|
evt_data.conn.handle = BTM_INVALID_HCI_HANDLE;
|
|
|
|
#endif
|
|
|
|
(*btm_cb.p_bl_changed_cb)(&evt_data);
|
|
|
|
return TRUE;
|
2016-11-24 13:10:15 -05:00
|
|
|
} else {
|
2016-09-26 09:37:39 -04:00
|
|
|
return FALSE;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_chk_peer_pkt_type_support
|
|
|
|
**
|
|
|
|
** Description Check if peer supports requested packets
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_chk_peer_pkt_type_support (tACL_CONN *p, UINT16 *p_pkt_type)
|
|
|
|
{
|
|
|
|
/* 3 and 5 slot packets? */
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!HCI_3_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
|
|
|
|
*p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3);
|
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
if (!HCI_5_SLOT_PACKETS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_pkt_type &= ~(BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* 2 and 3 MPS support? */
|
2019-03-26 02:37:37 -04:00
|
|
|
if (!HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Not supported. Add 'not_supported' mask for all 2MPS packet types */
|
|
|
|
*p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
|
2016-11-24 13:10:15 -05:00
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
|
2019-03-26 02:37:37 -04:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2019-03-26 02:37:37 -04:00
|
|
|
if (!HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
|
2016-09-26 09:37:39 -04:00
|
|
|
/* Not supported. Add 'not_supported' mask for all 3MPS packet types */
|
|
|
|
*p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
|
2016-11-24 13:10:15 -05:00
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
|
2019-03-26 02:37:37 -04:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* EDR 3 and 5 slot support? */
|
|
|
|
if (HCI_EDR_ACL_2MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])
|
2016-11-24 13:10:15 -05:00
|
|
|
|| HCI_EDR_ACL_3MPS_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0])) {
|
2016-09-26 09:37:39 -04:00
|
|
|
if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
|
|
|
|
/* Not supported. Add 'not_supported' mask for all 3-slot EDR packet types */
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
|
|
|
|
/* Not supported. Add 'not_supported' mask for all 5-slot EDR packet types */
|
2016-11-24 13:10:15 -05:00
|
|
|
{
|
2016-09-26 09:37:39 -04:00
|
|
|
*p_pkt_type |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 + BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
}
|
2020-07-01 14:35:54 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_free
|
|
|
|
**
|
|
|
|
** Description Free acl specific lists from btm control block
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_free(void)
|
|
|
|
{
|
|
|
|
list_free(btm_cb.p_acl_db_list);
|
|
|
|
list_free(btm_cb.p_pm_mode_db_list);
|
|
|
|
}
|
2022-07-28 00:32:56 -04:00
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_connected
|
|
|
|
**
|
|
|
|
** Description Handle ACL connection complete event
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_connected(BD_ADDR bda, UINT16 handle, UINT8 link_type, UINT8 enc_mode, UINT8 status)
|
|
|
|
{
|
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
|
|
|
tBTM_ESCO_DATA esco_data;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (link_type == HCI_LINK_TYPE_ACL) {
|
|
|
|
#if SMP_INCLUDED == TRUE
|
|
|
|
btm_sec_connected (bda, handle, status, enc_mode);
|
|
|
|
#endif /* SMP_INCLUDED == TRUE */
|
|
|
|
/* report acl connection result to upper layer */
|
|
|
|
do {
|
|
|
|
tBTM_ACL_LINK_STAT_EVENT_DATA evt_data = {
|
|
|
|
.event = BTM_ACL_CONN_CMPL_EVT,
|
|
|
|
.link_act.conn_cmpl.status = status,
|
|
|
|
.link_act.conn_cmpl.handle = handle,
|
|
|
|
};
|
|
|
|
bdcpy(evt_data.link_act.conn_cmpl.bd_addr, bda);
|
|
|
|
btm_acl_link_stat_report(&evt_data);
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
l2c_link_hci_conn_comp(status, handle, bda);
|
|
|
|
}
|
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
|
|
|
else {
|
|
|
|
memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
|
|
|
|
esco_data.link_type = HCI_LINK_TYPE_SCO;
|
|
|
|
memcpy (esco_data.bd_addr, bda, BD_ADDR_LEN);
|
|
|
|
btm_sco_connected(status, bda, handle, &esco_data);
|
|
|
|
}
|
|
|
|
#endif /* BTM_SCO_INCLUDED == TRUE */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_acl_disconnected
|
|
|
|
**
|
|
|
|
** Description Handle ACL disconnection complete event
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_acl_disconnected(UINT16 handle, UINT8 reason)
|
|
|
|
{
|
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
|
|
|
/* If L2CAP doesn't know about it, send it to SCO */
|
|
|
|
if (!l2c_link_hci_disc_comp (handle, reason)) {
|
|
|
|
btm_sco_removed (handle, reason);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Report BR/EDR ACL disconnection result to upper layer */
|
|
|
|
tACL_CONN *conn = btm_handle_to_acl(handle);
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
if (conn->transport == BT_TRANSPORT_BR_EDR)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
tBTM_ACL_LINK_STAT_EVENT_DATA evt_data = {
|
|
|
|
.event = BTM_ACL_DISCONN_CMPL_EVT,
|
|
|
|
.link_act.disconn_cmpl.reason = reason,
|
|
|
|
.link_act.disconn_cmpl.handle = handle,
|
|
|
|
};
|
|
|
|
bdcpy(evt_data.link_act.disconn_cmpl.bd_addr, conn->remote_addr);
|
|
|
|
btm_acl_link_stat_report(&evt_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
l2c_link_hci_disc_comp(handle, reason);
|
|
|
|
#endif /* BTM_SCO_INCLUDED */
|
|
|
|
#if (SMP_INCLUDED == TRUE)
|
|
|
|
/* Notify security manager */
|
|
|
|
btm_sec_disconnected(handle, reason);
|
|
|
|
#endif /* SMP_INCLUDED == TRUE */
|
|
|
|
}
|