2016-09-26 13:37:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999-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.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This file contains functions that handle BTM interface functions for the
|
|
|
|
* Bluetooth device including Rest, HCI buffer size and others
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
//#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "common/bt_trace.h"
|
|
|
|
#include "stack/bt_types.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
//#include "bt_utils.h"
|
|
|
|
#include "btm_int.h"
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "stack/btu.h"
|
|
|
|
#include "device/controller.h"
|
|
|
|
#include "hci/hci_layer.h"
|
|
|
|
#include "stack/hcimsgs.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
#include "l2c_int.h"
|
|
|
|
//#include "btcore/include/module.h"
|
2018-04-08 04:10:50 +00:00
|
|
|
//#include "osi/include/osi/thread.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#if BLE_INCLUDED == TRUE
|
|
|
|
#include "gatt_int.h"
|
|
|
|
#endif /* BLE_INCLUDED */
|
|
|
|
|
|
|
|
//extern thread_t *bt_workqueue_thread;
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/* L O C A L D A T A D E F I N I T I O N S */
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
#ifndef BTM_DEV_RESET_TIMEOUT
|
|
|
|
#define BTM_DEV_RESET_TIMEOUT 4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BTM_DEV_REPLY_TIMEOUT 2 /* 1 second expiration time is not good. Timer may start between 0 and 1 second. */
|
2016-11-24 18:10:15 +00:00
|
|
|
/* if it starts at the very end of the 0 second, timer will expire really easily. */
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#define BTM_INFO_TIMEOUT 5 /* 5 seconds for info response */
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
/* L O C A L F U N C T I O N P R O T O T Y P E S */
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
static void btm_decode_ext_features_page (UINT8 page_number, const BD_FEATURES p_features);
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_dev_init
|
|
|
|
**
|
|
|
|
** Description This function is on the BTM startup
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_dev_init (void)
|
|
|
|
{
|
|
|
|
#if 0 /* cleared in btm_init; put back in if called from anywhere else! */
|
|
|
|
memset (&btm_cb.devcb, 0, sizeof (tBTM_DEVCB));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize nonzero defaults */
|
|
|
|
#if (BTM_MAX_LOC_BD_NAME_LEN > 0)
|
|
|
|
memset(btm_cb.cfg.bd_name, 0, sizeof(tBTM_LOC_BD_NAME));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
btm_cb.devcb.reset_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RESET;
|
|
|
|
btm_cb.devcb.rln_timer.param = (TIMER_PARAM_TYPE)TT_DEV_RLN;
|
|
|
|
|
|
|
|
btm_cb.btm_acl_pkt_types_supported = BTM_ACL_PKT_TYPES_MASK_DH1 + BTM_ACL_PKT_TYPES_MASK_DM1 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_DH3 + BTM_ACL_PKT_TYPES_MASK_DM3 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_DH5 + BTM_ACL_PKT_TYPES_MASK_DM5;
|
|
|
|
|
|
|
|
btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_HV2 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_HV3 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_EV3 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_EV4 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_EV5;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_db_reset
|
|
|
|
**
|
|
|
|
** Description This function is called by BTM_DeviceReset and clears out any
|
|
|
|
** pending callbacks for inquiries, discoveries, other pending
|
|
|
|
** functions that may be in progress.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void btm_db_reset (void)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb;
|
|
|
|
tBTM_STATUS status = BTM_DEV_RESET;
|
|
|
|
|
|
|
|
btm_inq_db_reset();
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.devcb.p_rln_cmpl_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_cb = btm_cb.devcb.p_rln_cmpl_cb;
|
|
|
|
btm_cb.devcb.p_rln_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_cb)((void *) NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.devcb.p_rssi_cmpl_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_cb = btm_cb.devcb.p_rssi_cmpl_cb;
|
|
|
|
btm_cb.devcb.p_rssi_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_cb)((tBTM_RSSI_RESULTS *) &status);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
static void reset_complete(void)
|
|
|
|
{
|
|
|
|
const controller_t *controller = controller_get_interface();
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
/* Tell L2CAP that all connections are gone */
|
|
|
|
l2cu_device_reset ();
|
2017-04-19 07:44:01 +00:00
|
|
|
#if (SMP_INCLUDED == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
/* Clear current security state */
|
|
|
|
for (int devinx = 0; devinx < BTM_SEC_MAX_DEVICE_RECORDS; devinx++) {
|
|
|
|
btm_cb.sec_dev_rec[devinx].sec_state = BTM_SEC_STATE_IDLE;
|
|
|
|
}
|
2017-04-19 07:44:01 +00:00
|
|
|
#endif ///SMP_INCLUDED == TRUE
|
2016-11-24 18:10:15 +00:00
|
|
|
/* After the reset controller should restore all parameters to defaults. */
|
|
|
|
btm_cb.btm_inq_vars.inq_counter = 1;
|
|
|
|
btm_cb.btm_inq_vars.inq_scan_window = HCI_DEF_INQUIRYSCAN_WINDOW;
|
|
|
|
btm_cb.btm_inq_vars.inq_scan_period = HCI_DEF_INQUIRYSCAN_INTERVAL;
|
|
|
|
btm_cb.btm_inq_vars.inq_scan_type = HCI_DEF_SCAN_TYPE;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
btm_cb.btm_inq_vars.page_scan_window = HCI_DEF_PAGESCAN_WINDOW;
|
|
|
|
btm_cb.btm_inq_vars.page_scan_period = HCI_DEF_PAGESCAN_INTERVAL;
|
|
|
|
btm_cb.btm_inq_vars.page_scan_type = HCI_DEF_SCAN_TYPE;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
btm_cb.ble_ctr_cb.conn_state = BLE_CONN_IDLE;
|
|
|
|
btm_cb.ble_ctr_cb.bg_conn_type = BTM_BLE_CONN_NONE;
|
|
|
|
btm_cb.ble_ctr_cb.p_select_cback = NULL;
|
|
|
|
gatt_reset_bgdev_list();
|
|
|
|
btm_ble_multi_adv_init();
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
btm_pm_reset();
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
l2c_link_processs_num_bufs(controller->get_acl_buffer_count_classic());
|
2018-05-21 03:33:30 +00:00
|
|
|
#if BTM_SCO_HCI_INCLUDED == TRUE
|
|
|
|
btm_sco_process_num_bufs(controller->get_sco_buffer_count());
|
|
|
|
#endif
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (BLE_INCLUDED == TRUE)
|
|
|
|
|
|
|
|
#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
/* Set up the BLE privacy settings */
|
|
|
|
if (controller->supports_ble() && controller->supports_ble_privacy() &&
|
|
|
|
controller->get_ble_resolving_list_max_size() > 0) {
|
|
|
|
btm_ble_resolving_list_init(controller->get_ble_resolving_list_max_size());
|
|
|
|
/* set the default random private address timeout */
|
|
|
|
btsnd_hcic_ble_set_rand_priv_addr_timeout(BTM_BLE_PRIVATE_ADDR_INT);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (controller->supports_ble()) {
|
|
|
|
btm_ble_white_list_init(controller->get_ble_white_list_size());
|
|
|
|
l2c_link_processs_ble_num_bufs(controller->get_acl_buffer_count_ble());
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
2018-11-12 03:08:19 +00:00
|
|
|
#if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
BTM_SetPinType (btm_cb.cfg.pin_type, btm_cb.cfg.pin_code, btm_cb.cfg.pin_code_len);
|
2018-11-12 03:08:19 +00:00
|
|
|
#endif ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE
|
2016-11-24 18:10:15 +00:00
|
|
|
for (int i = 0; i <= controller->get_last_features_classic_index(); i++) {
|
|
|
|
btm_decode_ext_features_page(i, controller->get_features_classic(i)->as_array);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
btm_report_device_status(BTM_DEV_STATUS_UP);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(zachoverflow): remove this function
|
2016-11-24 18:10:15 +00:00
|
|
|
void BTM_DeviceReset (UNUSED_ATTR tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
/* Flush all ACL connections */
|
|
|
|
btm_acl_device_down();
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
/* Clear the callback, so application would not hang on reset */
|
|
|
|
btm_db_reset();
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
/* todo: review the below logic; start_up executes under another task context
|
|
|
|
* reset_complete runs in btu task */
|
|
|
|
controller_get_interface()->start_up();
|
|
|
|
reset_complete();
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_IsDeviceUp
|
|
|
|
**
|
|
|
|
** Description This function is called to check if the device is up.
|
|
|
|
**
|
|
|
|
** Returns TRUE if device is up, else FALSE
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN BTM_IsDeviceUp (void)
|
|
|
|
{
|
|
|
|
return controller_get_interface()->get_is_ready();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_dev_timeout
|
|
|
|
**
|
|
|
|
** Description This function is called when a timer list entry expires.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_dev_timeout (TIMER_LIST_ENT *p_tle)
|
|
|
|
{
|
|
|
|
TIMER_PARAM_TYPE timer_type = (TIMER_PARAM_TYPE)p_tle->param;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (timer_type == (TIMER_PARAM_TYPE)TT_DEV_RLN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
|
|
|
|
|
|
|
|
btm_cb.devcb.p_rln_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_cb)((void *) NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_decode_ext_features_page
|
|
|
|
**
|
|
|
|
** Description This function is decodes a features page.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void btm_decode_ext_features_page (UINT8 page_number, const UINT8 *p_features)
|
|
|
|
{
|
|
|
|
BTM_TRACE_DEBUG ("btm_decode_ext_features_page page: %d", page_number);
|
2016-11-24 18:10:15 +00:00
|
|
|
switch (page_number) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* Extended (Legacy) Page 0 */
|
|
|
|
case HCI_EXT_FEATURES_PAGE_0:
|
|
|
|
|
|
|
|
/* Create ACL supported packet types mask */
|
|
|
|
btm_cb.btm_acl_pkt_types_supported = (BTM_ACL_PKT_TYPES_MASK_DH1 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_DM1);
|
|
|
|
|
2019-03-26 06:37:37 +00:00
|
|
|
if (HCI_3_SLOT_PACKETS_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH3 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_DM3);
|
2019-03-26 06:37:37 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2019-03-26 06:37:37 +00:00
|
|
|
if (HCI_5_SLOT_PACKETS_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_DH5 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_DM5);
|
2019-03-26 06:37:37 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Add in EDR related ACL types */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!HCI_EDR_ACL_2MPS_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH1 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_2_DH5);
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_3_DH1 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_3_DH3 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check to see if 3 and 5 slot packets are available */
|
|
|
|
if (HCI_EDR_ACL_2MPS_SUPPORTED(p_features) ||
|
2016-11-24 18:10:15 +00:00
|
|
|
HCI_EDR_ACL_3MPS_SUPPORTED(p_features)) {
|
2019-03-26 06:37:37 +00:00
|
|
|
if (!HCI_3_SLOT_EDR_ACL_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH3 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_3_DH3);
|
2019-03-26 06:37:37 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2019-03-26 06:37:37 +00:00
|
|
|
if (!HCI_5_SLOT_EDR_ACL_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported |= (BTM_ACL_PKT_TYPES_MASK_NO_2_DH5 +
|
|
|
|
BTM_ACL_PKT_TYPES_MASK_NO_3_DH5);
|
2019-03-26 06:37:37 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BTM_TRACE_DEBUG("Local supported ACL packet types: 0x%04x",
|
2016-11-24 18:10:15 +00:00
|
|
|
btm_cb.btm_acl_pkt_types_supported);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Create (e)SCO supported packet types mask */
|
|
|
|
btm_cb.btm_sco_pkt_types_supported = 0;
|
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
|
|
|
btm_cb.sco_cb.esco_supported = FALSE;
|
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_SCO_LINK_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported = BTM_SCO_PKT_TYPES_MASK_HV1;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_HV2_PACKETS_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV2;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_HV3_PACKETS_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_HV3;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_ESCO_EV3_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV3;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_ESCO_EV4_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV4;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_ESCO_EV5_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_EV5;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
#if BTM_SCO_INCLUDED == TRUE
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.btm_sco_pkt_types_supported & BTM_ESCO_LINK_ONLY_MASK) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.sco_cb.esco_supported = TRUE;
|
|
|
|
|
|
|
|
/* Add in EDR related eSCO types */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_EDR_ESCO_2MPS_SUPPORTED(p_features)) {
|
|
|
|
if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_2_EV5;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_2_EV3 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_NO_2_EV5);
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_EDR_ESCO_3MPS_SUPPORTED(p_features)) {
|
|
|
|
if (!HCI_3_SLOT_EDR_ESCO_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= BTM_SCO_PKT_TYPES_MASK_NO_3_EV5;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported |= (BTM_SCO_PKT_TYPES_MASK_NO_3_EV3 +
|
|
|
|
BTM_SCO_PKT_TYPES_MASK_NO_3_EV5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BTM_TRACE_DEBUG("Local supported SCO packet types: 0x%04x",
|
2016-11-24 18:10:15 +00:00
|
|
|
btm_cb.btm_sco_pkt_types_supported);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Create Default Policy Settings */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_SWITCH_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_HOLD_MODE_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy |= HCI_ENABLE_HOLD_MODE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy &= ~HCI_ENABLE_HOLD_MODE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_SNIFF_MODE_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy |= HCI_ENABLE_SNIFF_MODE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy &= ~HCI_ENABLE_SNIFF_MODE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_PARK_MODE_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy |= HCI_ENABLE_PARK_MODE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.btm_def_link_policy &= ~HCI_ENABLE_PARK_MODE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
btm_sec_dev_reset ();
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (HCI_LMP_INQ_RSSI_SUPPORTED(p_features)) {
|
|
|
|
if (HCI_EXT_INQ_RSP_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_SetInquiryMode (BTM_INQ_RESULT_EXTENDED);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_SetInquiryMode (BTM_INQ_RESULT_WITH_RSSI);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
|
2016-11-24 18:10:15 +00:00
|
|
|
if ( HCI_NON_FLUSHABLE_PB_SUPPORTED(p_features)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
l2cu_set_non_flushable_pbf(TRUE);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
l2cu_set_non_flushable_pbf(FALSE);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
BTM_SetPageScanType (BTM_DEFAULT_SCAN_TYPE);
|
|
|
|
BTM_SetInquiryScanType (BTM_DEFAULT_SCAN_TYPE);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Extended Page 1 */
|
|
|
|
case HCI_EXT_FEATURES_PAGE_1:
|
|
|
|
/* Nothing to do for page 1 */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Extended Page 2 */
|
|
|
|
case HCI_EXT_FEATURES_PAGE_2:
|
|
|
|
/* Nothing to do for page 2 */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
BTM_TRACE_ERROR("btm_decode_ext_features_page page=%d unknown", page_number);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetLocalDeviceName
|
|
|
|
**
|
|
|
|
** Description This function is called to set the local device name.
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetLocalDeviceName (char *p_name)
|
|
|
|
{
|
|
|
|
UINT8 *p;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!p_name || !p_name[0] || (strlen ((char *)p_name) > BD_NAME_LEN)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_ILLEGAL_VALUE);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!controller_get_interface()->get_is_ready()) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_DEV_RESET);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#if BTM_MAX_LOC_BD_NAME_LEN > 0
|
|
|
|
/* Save the device name if local storage is enabled */
|
|
|
|
p = (UINT8 *)btm_cb.cfg.bd_name;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p != (UINT8 *)p_name) {
|
2020-03-12 07:17:37 +00:00
|
|
|
BCM_STRNCPY_S(btm_cb.cfg.bd_name, p_name, BTM_MAX_LOC_BD_NAME_LEN);
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.cfg.bd_name[BTM_MAX_LOC_BD_NAME_LEN] = '\0';
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
p = (UINT8 *)p_name;
|
|
|
|
#endif
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btsnd_hcic_change_name(p)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_CMD_STARTED);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadLocalDeviceName
|
|
|
|
**
|
|
|
|
** Description This function is called to read the local device name.
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
** If success, BTM_SUCCESS is returned and p_name points stored
|
|
|
|
** local device name
|
|
|
|
** If BTM doesn't store local device name, BTM_NO_RESOURCES is
|
|
|
|
** is returned and p_name is set to NULL
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_ReadLocalDeviceName (char **p_name)
|
|
|
|
{
|
|
|
|
#if BTM_MAX_LOC_BD_NAME_LEN > 0
|
|
|
|
*p_name = btm_cb.cfg.bd_name;
|
2016-11-24 18:10:15 +00:00
|
|
|
return (BTM_SUCCESS);
|
2016-09-26 13:37:39 +00:00
|
|
|
#else
|
|
|
|
*p_name = NULL;
|
2016-11-24 18:10:15 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadLocalDeviceNameFromController
|
|
|
|
**
|
|
|
|
** Description Get local device name from controller. Do not use cached
|
|
|
|
** name (used to get chip-id prior to btm reset complete).
|
|
|
|
**
|
|
|
|
** Returns BTM_CMD_STARTED if successful, otherwise an error
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_ReadLocalDeviceNameFromController (tBTM_CMPL_CB *p_rln_cmpl_cback)
|
|
|
|
{
|
|
|
|
/* Check if rln already in progress */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.devcb.p_rln_cmpl_cb) {
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Save callback */
|
|
|
|
btm_cb.devcb.p_rln_cmpl_cb = p_rln_cmpl_cback;
|
|
|
|
|
|
|
|
btsnd_hcic_read_name();
|
|
|
|
btu_start_timer (&btm_cb.devcb.rln_timer, BTU_TTYPE_BTM_DEV_CTL, BTM_DEV_REPLY_TIMEOUT);
|
|
|
|
|
|
|
|
return BTM_CMD_STARTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_read_local_name_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when local name read complete.
|
|
|
|
** message is received from the HCI.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_read_local_name_complete (UINT8 *p, UINT16 evt_len)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
|
|
|
|
UINT8 status;
|
|
|
|
UNUSED(evt_len);
|
|
|
|
|
2018-01-27 11:03:06 +00:00
|
|
|
btu_free_timer (&btm_cb.devcb.rln_timer);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* If there was a callback address for read local name, call it */
|
|
|
|
btm_cb.devcb.p_rln_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
STREAM_TO_UINT8 (status, p);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (status == HCI_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_cb)(p);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_cb)(NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_SetDeviceClass
|
|
|
|
**
|
|
|
|
** Description This function is called to set the local device class
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_SetDeviceClass (DEV_CLASS dev_class)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!memcmp (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN)) {
|
|
|
|
return (BTM_SUCCESS);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
memcpy (btm_cb.devcb.dev_class, dev_class, DEV_CLASS_LEN);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!controller_get_interface()->get_is_ready()) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_DEV_RESET);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!btsnd_hcic_write_dev_class (dev_class)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
return (BTM_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadDeviceClass
|
|
|
|
**
|
|
|
|
** Description This function is called to read the local device class
|
|
|
|
**
|
|
|
|
** Returns pointer to the device class
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 *BTM_ReadDeviceClass (void)
|
|
|
|
{
|
|
|
|
return ((UINT8 *)btm_cb.devcb.dev_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_ReadLocalFeatures
|
|
|
|
**
|
|
|
|
** Description This function is called to read the local features
|
|
|
|
**
|
|
|
|
** Returns pointer to the local features string
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
// TODO(zachoverflow): get rid of this function
|
|
|
|
UINT8 *BTM_ReadLocalFeatures (void)
|
|
|
|
{
|
|
|
|
// Discarding const modifier for now, until this function dies
|
|
|
|
return (UINT8 *)controller_get_interface()->get_features_classic(0)->as_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_RegisterForDeviceStatusNotif
|
|
|
|
**
|
|
|
|
** Description This function is called to register for device status
|
|
|
|
** change notifications.
|
|
|
|
**
|
|
|
|
** If one registration is already there calling function should
|
|
|
|
** save the pointer to the function that is return and
|
|
|
|
** call it when processing of the event is complete
|
|
|
|
**
|
|
|
|
** Returns status of the operation
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_DEV_STATUS_CB *BTM_RegisterForDeviceStatusNotif (tBTM_DEV_STATUS_CB *p_cb)
|
|
|
|
{
|
|
|
|
tBTM_DEV_STATUS_CB *p_prev = btm_cb.devcb.p_dev_status_cb;
|
|
|
|
|
|
|
|
btm_cb.devcb.p_dev_status_cb = p_cb;
|
|
|
|
return (p_prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_VendorSpecificCommand
|
|
|
|
**
|
|
|
|
** Description Send a vendor specific HCI command to the controller.
|
|
|
|
**
|
|
|
|
** Returns
|
|
|
|
** BTM_SUCCESS Command sent. Does not expect command complete
|
|
|
|
** event. (command cmpl callback param is NULL)
|
|
|
|
** BTM_CMD_STARTED Command sent. Waiting for command cmpl event.
|
|
|
|
**
|
|
|
|
** Notes
|
|
|
|
** Opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len,
|
|
|
|
UINT8 *p_param_buf, tBTM_VSC_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
void *p_buf;
|
|
|
|
|
|
|
|
BTM_TRACE_EVENT ("BTM: BTM_VendorSpecificCommand: Opcode: 0x%04X, ParamLen: %i.",
|
2016-11-24 18:10:15 +00:00
|
|
|
opcode, param_len);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Allocate a buffer to hold HCI command plus the callback function */
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = osi_malloc((UINT16)(sizeof(BT_HDR) + sizeof (tBTM_CMPL_CB *) +
|
2016-11-24 18:10:15 +00:00
|
|
|
param_len + HCIC_PREAMBLE_SIZE))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* Send the HCI command (opcode will be OR'd with HCI_GRP_VENDOR_SPECIFIC) */
|
|
|
|
btsnd_hcic_vendor_spec_cmd (p_buf, opcode, param_len, p_param_buf, (void *)p_cb);
|
|
|
|
|
|
|
|
/* Return value */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_CMD_STARTED);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_SUCCESS);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_vsc_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when local HCI Vendor Specific
|
|
|
|
** Command complete message is received from the HCI.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len,
|
|
|
|
tBTM_CMPL_CB *p_vsc_cplt_cback)
|
|
|
|
{
|
2019-06-21 03:55:45 +00:00
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2018-11-21 07:45:48 +00:00
|
|
|
tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb;
|
2018-11-09 08:11:45 +00:00
|
|
|
switch(opcode) {
|
|
|
|
case HCI_VENDOR_BLE_LONG_ADV_DATA:
|
|
|
|
BTM_TRACE_EVENT("Set long adv data complete\n");
|
|
|
|
break;
|
2018-11-21 07:45:48 +00:00
|
|
|
case HCI_VENDOR_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST: {
|
|
|
|
uint8_t subcode, status; uint32_t length;
|
|
|
|
STREAM_TO_UINT8(status, p);
|
|
|
|
STREAM_TO_UINT8(subcode, p);
|
|
|
|
STREAM_TO_UINT32(length, p);
|
|
|
|
if(ble_cb && ble_cb->update_exceptional_list_cmp_cb) {
|
|
|
|
(*ble_cb->update_exceptional_list_cmp_cb)(status, subcode, length, p);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-11-09 08:11:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTM_VSC_CMPL vcs_cplt_params;
|
|
|
|
|
|
|
|
/* If there was a callback address for vcs complete, call it */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_vsc_cplt_cback) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* Pass paramters to the callback function */
|
|
|
|
vcs_cplt_params.opcode = opcode; /* Number of bytes in return info */
|
|
|
|
vcs_cplt_params.param_len = evt_len; /* Number of bytes in return info */
|
|
|
|
vcs_cplt_params.p_param_buf = p;
|
|
|
|
(*p_vsc_cplt_cback)(&vcs_cplt_params); /* Call the VSC complete callback function */
|
|
|
|
}
|
2019-06-21 03:55:45 +00:00
|
|
|
#endif
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_RegisterForVSEvents
|
|
|
|
**
|
|
|
|
** Description This function is called to register/deregister for vendor
|
|
|
|
** specific HCI events.
|
|
|
|
**
|
|
|
|
** If is_register=TRUE, then the function will be registered;
|
|
|
|
** if is_register=FALSE, then the function will be deregistered.
|
|
|
|
**
|
|
|
|
** Returns BTM_SUCCESS if successful,
|
|
|
|
** BTM_BUSY if maximum number of callbacks have already been
|
|
|
|
** registered.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_RegisterForVSEvents (tBTM_VS_EVT_CB *p_cb, BOOLEAN is_register)
|
|
|
|
{
|
|
|
|
tBTM_STATUS retval = BTM_SUCCESS;
|
|
|
|
UINT8 i, free_idx = BTM_MAX_VSE_CALLBACKS;
|
|
|
|
|
|
|
|
/* See if callback is already registered */
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
|
|
|
|
if (btm_cb.devcb.p_vend_spec_cb[i] == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* Found a free slot. Store index */
|
|
|
|
free_idx = i;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (btm_cb.devcb.p_vend_spec_cb[i] == p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* Found callback in lookup table. If deregistering, clear the entry. */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (is_register == FALSE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.devcb.p_vend_spec_cb[i] = NULL;
|
|
|
|
BTM_TRACE_EVENT("BTM Deregister For VSEvents is successfully");
|
|
|
|
}
|
|
|
|
return (BTM_SUCCESS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Didn't find callback. Add callback to free slot if registering */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (is_register) {
|
|
|
|
if (free_idx < BTM_MAX_VSE_CALLBACKS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.devcb.p_vend_spec_cb[free_idx] = p_cb;
|
|
|
|
BTM_TRACE_EVENT("BTM Register For VSEvents is successfully");
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* No free entries available */
|
|
|
|
BTM_TRACE_ERROR ("BTM_RegisterForVSEvents: too many callbacks registered");
|
|
|
|
|
|
|
|
retval = BTM_NO_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_vendor_specific_evt
|
|
|
|
**
|
|
|
|
** Description Process event HCI_VENDOR_SPECIFIC_EVT
|
|
|
|
**
|
|
|
|
** Note: Some controllers do not send command complete, so
|
|
|
|
** the callback and busy flag are cleared here also.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_vendor_specific_evt (UINT8 *p, UINT8 evt_len)
|
|
|
|
{
|
|
|
|
UINT8 i;
|
|
|
|
|
2020-04-28 10:24:31 +00:00
|
|
|
#if (CLASSIC_BT_INCLUDED == TRUE)
|
|
|
|
UINT8 sub_event;
|
|
|
|
UINT8 *p_evt = p;
|
|
|
|
|
|
|
|
STREAM_TO_UINT8(sub_event, p_evt);
|
|
|
|
/* Check in subevent if authentication is through Legacy Authentication. */
|
|
|
|
if (sub_event == ESP_VS_REM_LEGACY_AUTH_CMP) {
|
|
|
|
UINT16 hci_handle;
|
|
|
|
STREAM_TO_UINT16(hci_handle, p_evt);
|
|
|
|
btm_sec_handle_remote_legacy_auth_cmp(hci_handle);
|
|
|
|
}
|
|
|
|
#endif /// (CLASSIC_BT_INCLUDED == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0; i < BTM_MAX_VSE_CALLBACKS; i++) {
|
|
|
|
if (btm_cb.devcb.p_vend_spec_cb[i]) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*btm_cb.devcb.p_vend_spec_cb[i])(evt_len, p);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2020-04-28 10:24:31 +00:00
|
|
|
BTM_TRACE_DEBUG ("BTM Event: Vendor Specific event from controller");
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_WritePageTimeout
|
|
|
|
**
|
|
|
|
** Description Send HCI Write Page Timeout.
|
|
|
|
**
|
|
|
|
** Returns
|
|
|
|
** BTM_SUCCESS Command sent.
|
|
|
|
** BTM_NO_RESOURCES If out of resources to send the command.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_WritePageTimeout(UINT16 timeout)
|
|
|
|
{
|
|
|
|
BTM_TRACE_EVENT ("BTM: BTM_WritePageTimeout: Timeout: %d.", timeout);
|
|
|
|
|
|
|
|
/* Send the HCI command */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btsnd_hcic_write_page_tout (timeout)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_SUCCESS);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_WriteVoiceSettings
|
|
|
|
**
|
|
|
|
** Description Send HCI Write Voice Settings command.
|
2018-04-08 04:10:50 +00:00
|
|
|
** See stack/hcidefs.h for settings bitmask values.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns
|
|
|
|
** BTM_SUCCESS Command sent.
|
|
|
|
** BTM_NO_RESOURCES If out of resources to send the command.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_WriteVoiceSettings(UINT16 settings)
|
|
|
|
{
|
|
|
|
BTM_TRACE_EVENT ("BTM: BTM_WriteVoiceSettings: Settings: 0x%04x.", settings);
|
|
|
|
|
|
|
|
/* Send the HCI command */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btsnd_hcic_write_voice_settings ((UINT16)(settings & 0x03ff))) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_SUCCESS);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_EnableTestMode
|
|
|
|
**
|
|
|
|
** Description Send HCI the enable device under test command.
|
|
|
|
**
|
|
|
|
** Note: Controller can only be taken out of this mode by
|
|
|
|
** resetting the controller.
|
|
|
|
**
|
|
|
|
** Returns
|
|
|
|
** BTM_SUCCESS Command sent.
|
|
|
|
** BTM_NO_RESOURCES If out of resources to send the command.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_EnableTestMode(void)
|
|
|
|
{
|
|
|
|
UINT8 cond;
|
|
|
|
|
|
|
|
BTM_TRACE_EVENT ("BTM: BTM_EnableTestMode");
|
|
|
|
|
|
|
|
/* set auto accept connection as this is needed during test mode */
|
|
|
|
/* Allocate a buffer to hold HCI command */
|
|
|
|
cond = HCI_DO_AUTO_ACCEPT_CONNECT;
|
|
|
|
if (!btsnd_hcic_set_event_filter(HCI_FILTER_CONNECTION_SETUP,
|
|
|
|
HCI_FILTER_COND_NEW_DEVICE,
|
2016-11-24 18:10:15 +00:00
|
|
|
&cond, sizeof(cond))) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put device to connectable mode */
|
|
|
|
if (!BTM_SetConnectability(BTM_CONNECTABLE, BTM_DEFAULT_CONN_WINDOW,
|
2016-11-24 18:10:15 +00:00
|
|
|
BTM_DEFAULT_CONN_INTERVAL) == BTM_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return BTM_NO_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put device to discoverable mode */
|
|
|
|
if (!BTM_SetDiscoverability(BTM_GENERAL_DISCOVERABLE, BTM_DEFAULT_DISC_WINDOW,
|
2016-11-24 18:10:15 +00:00
|
|
|
BTM_DEFAULT_DISC_INTERVAL) == BTM_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return BTM_NO_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mask off all of event from controller */
|
|
|
|
hci_layer_get_interface()->transmit_command(
|
2016-11-24 18:10:15 +00:00
|
|
|
hci_packet_factory_get_interface()->make_set_event_mask((const bt_event_mask_t *)("\x00\x00\x00\x00\x00\x00\x00\x00")),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Send the HCI command */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btsnd_hcic_enable_test_mode ()) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_SUCCESS);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTM_DeleteStoredLinkKey
|
|
|
|
**
|
|
|
|
** Description This function is called to delete link key for the specified
|
|
|
|
** device addresses from the NVRAM storage attached to the Bluetooth
|
|
|
|
** controller.
|
|
|
|
**
|
|
|
|
** Parameters: bd_addr - Addresses of the devices
|
|
|
|
** p_cb - Call back function to be called to return
|
|
|
|
** the results
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_STATUS BTM_DeleteStoredLinkKey(BD_ADDR bd_addr, tBTM_CMPL_CB *p_cb)
|
|
|
|
{
|
|
|
|
BD_ADDR local_bd_addr;
|
|
|
|
BOOLEAN delete_all_flag = FALSE;
|
|
|
|
|
|
|
|
/* Check if the previous command is completed */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.devcb.p_stored_link_key_cmpl_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_BUSY);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!bd_addr) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* This is to delete all link keys */
|
|
|
|
delete_all_flag = TRUE;
|
|
|
|
|
|
|
|
/* We don't care the BD address. Just pass a non zero pointer */
|
|
|
|
bd_addr = local_bd_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BTM_TRACE_EVENT ("BTM: BTM_DeleteStoredLinkKey: delete_all_flag: %s",
|
2016-11-24 18:10:15 +00:00
|
|
|
delete_all_flag ? "TRUE" : "FALSE");
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* Send the HCI command */
|
|
|
|
btm_cb.devcb.p_stored_link_key_cmpl_cb = p_cb;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!btsnd_hcic_delete_stored_key (bd_addr, delete_all_flag)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_NO_RESOURCES);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return (BTM_SUCCESS);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_delete_stored_link_key_complete
|
|
|
|
**
|
|
|
|
** Description This function is called when the command complete message
|
|
|
|
** is received from the HCI for the delete stored link key command.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_delete_stored_link_key_complete (UINT8 *p)
|
|
|
|
{
|
|
|
|
tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_stored_link_key_cmpl_cb;
|
|
|
|
tBTM_DELETE_STORED_LINK_KEY_COMPLETE result;
|
|
|
|
|
|
|
|
/* If there was a callback registered for read stored link key, call it */
|
|
|
|
btm_cb.devcb.p_stored_link_key_cmpl_cb = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* Set the call back event to indicate command complete */
|
|
|
|
result.event = BTM_CB_EVT_DELETE_STORED_LINK_KEYS;
|
|
|
|
|
|
|
|
/* Extract the result fields from the HCI event */
|
|
|
|
STREAM_TO_UINT8 (result.status, p);
|
|
|
|
STREAM_TO_UINT16 (result.num_keys, p);
|
|
|
|
|
|
|
|
/* Call the call back and pass the result */
|
|
|
|
(*p_cb)(&result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_report_device_status
|
|
|
|
**
|
|
|
|
** Description This function is called when there is a change in the device
|
|
|
|
** status. This function will report the new device status to
|
|
|
|
** the application
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_report_device_status (tBTM_DEV_STATUS status)
|
|
|
|
{
|
|
|
|
tBTM_DEV_STATUS_CB *p_cb = btm_cb.devcb.p_dev_status_cb;
|
|
|
|
|
|
|
|
/* Call the call back to pass the device status to application */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb) {
|
2016-09-26 13:37:39 +00:00
|
|
|
(*p_cb)(status);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|