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 for BLE whitelist operation.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "common/bt_trace.h"
|
|
|
|
#include "device/controller.h"
|
|
|
|
#include "osi/allocator.h"
|
|
|
|
#include "osi/hash_map.h"
|
|
|
|
#include "stack/bt_types.h"
|
|
|
|
#include "stack/btu.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
#include "btm_int.h"
|
|
|
|
#include "l2c_int.h"
|
2018-04-08 04:10:50 +00:00
|
|
|
#include "stack/hcimsgs.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
//#include "bt_utils.h"
|
|
|
|
|
|
|
|
#ifndef BTM_BLE_SCAN_PARAM_TOUT
|
|
|
|
#define BTM_BLE_SCAN_PARAM_TOUT 50 /* 50 seconds */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
|
|
|
|
|
|
|
static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state);
|
2017-09-27 07:29:42 +00:00
|
|
|
static void btm_wl_update_to_controller(void);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
// Unfortunately (for now?) we have to maintain a copy of the device whitelist
|
|
|
|
// on the host to determine if a device is pending to be connected or not. This
|
|
|
|
// controls whether the host should keep trying to scan for whitelisted
|
|
|
|
// peripherals or not.
|
|
|
|
// TODO: Move all of this to controller/le/background_list or similar?
|
|
|
|
static const size_t background_connection_buckets = 42;
|
|
|
|
static hash_map_t *background_connections = NULL;
|
|
|
|
|
|
|
|
typedef struct background_connection_t {
|
2016-11-24 18:10:15 +00:00
|
|
|
bt_bdaddr_t address;
|
2016-09-26 13:37:39 +00:00
|
|
|
} background_connection_t;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
static bool bdaddr_equality_fn(const void *x, const void *y)
|
|
|
|
{
|
|
|
|
return bdaddr_equals((bt_bdaddr_t *)x, (bt_bdaddr_t *)y);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void background_connections_lazy_init()
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!background_connections) {
|
|
|
|
background_connections = hash_map_new(background_connection_buckets,
|
2017-08-17 13:13:45 +00:00
|
|
|
hash_function_bdaddr, NULL, osi_free_func, bdaddr_equality_fn);
|
2016-11-24 18:10:15 +00:00
|
|
|
assert(background_connections);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-02 09:20:34 +00:00
|
|
|
static BOOLEAN background_connection_add(bt_bdaddr_t *address)
|
2016-11-24 18:10:15 +00:00
|
|
|
{
|
|
|
|
assert(address);
|
|
|
|
background_connections_lazy_init();
|
|
|
|
background_connection_t *connection = hash_map_get(background_connections, address);
|
|
|
|
if (!connection) {
|
|
|
|
connection = osi_calloc(sizeof(background_connection_t));
|
|
|
|
connection->address = *address;
|
|
|
|
hash_map_set(background_connections, &(connection->address), connection);
|
2018-01-02 09:20:34 +00:00
|
|
|
return TRUE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2018-01-02 09:20:34 +00:00
|
|
|
return FALSE;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2018-01-02 09:20:34 +00:00
|
|
|
static BOOLEAN background_connection_remove(bt_bdaddr_t *address)
|
2016-11-24 18:10:15 +00:00
|
|
|
{
|
|
|
|
if (address && background_connections) {
|
2018-01-02 09:20:34 +00:00
|
|
|
return hash_map_erase(background_connections, address);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2018-01-02 09:20:34 +00:00
|
|
|
return FALSE;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
static void background_connections_clear()
|
|
|
|
{
|
|
|
|
if (background_connections) {
|
|
|
|
hash_map_clear(background_connections);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
static bool background_connections_pending_cb(hash_map_entry_t *hash_entry, void *context)
|
|
|
|
{
|
|
|
|
bool *pending_connections = context;
|
|
|
|
background_connection_t *connection = hash_entry->data;
|
|
|
|
const bool connected = BTM_IsAclConnectionUp(connection->address.address, BT_TRANSPORT_LE);
|
|
|
|
if (!connected) {
|
|
|
|
*pending_connections = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
static bool background_connections_pending()
|
|
|
|
{
|
|
|
|
bool pending_connections = false;
|
|
|
|
if (background_connections) {
|
|
|
|
hash_map_foreach(background_connections, background_connections_pending_cb, &pending_connections);
|
|
|
|
}
|
|
|
|
return pending_connections;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_update_scanner_filter_policy
|
|
|
|
**
|
|
|
|
** Description This function updates the filter policy of scanner
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)
|
|
|
|
{
|
|
|
|
tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
|
|
|
|
|
|
|
|
UINT32 scan_interval = !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval;
|
|
|
|
UINT32 scan_window = !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window;
|
|
|
|
|
2016-10-25 09:07:36 +00:00
|
|
|
BTM_TRACE_EVENT ("%s\n", __func__);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_inq->sfp = scan_policy;
|
|
|
|
p_inq->scan_type = p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE ? BTM_BLE_SCAN_MODE_ACTI : p_inq->scan_type;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btsnd_hcic_ble_set_scan_params(p_inq->scan_type, (UINT16)scan_interval,
|
|
|
|
(UINT16)scan_window,
|
|
|
|
btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,
|
|
|
|
scan_policy);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_send_extended_scan_params(p_inq->scan_type, scan_interval, scan_window,
|
|
|
|
btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type,
|
|
|
|
scan_policy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_add_dev_to_controller
|
|
|
|
**
|
|
|
|
** Description This function load the device into controller white list
|
|
|
|
*******************************************************************************/
|
2019-03-14 06:03:36 +00:00
|
|
|
BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE wl_addr_type)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2019-03-14 06:03:36 +00:00
|
|
|
/*
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
|
|
|
|
tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
|
|
|
|
BOOLEAN started = FALSE;
|
|
|
|
BD_ADDR dummy_bda = {0};
|
|
|
|
tBT_DEVICE_TYPE dev_type;
|
|
|
|
|
|
|
|
if (p_dev_rec != NULL &&
|
2016-11-24 18:10:15 +00:00
|
|
|
p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) {
|
|
|
|
if (to_add) {
|
|
|
|
if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
started = btsnd_hcic_ble_add_white_list (p_dev_rec->ble.ble_addr_type, bd_addr);
|
|
|
|
p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0 &&
|
|
|
|
memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
started = btsnd_hcic_ble_add_white_list (p_dev_rec->ble.static_addr_type,
|
2016-11-24 18:10:15 +00:00
|
|
|
p_dev_rec->ble.static_addr);
|
2016-09-26 13:37:39 +00:00
|
|
|
p_dev_rec->ble.in_controller_list |= BTM_WHITE_LIST_BIT;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
started = btsnd_hcic_ble_remove_from_white_list (p_dev_rec->ble.ble_addr_type, bd_addr);
|
|
|
|
}
|
|
|
|
if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0 &&
|
2016-11-24 18:10:15 +00:00
|
|
|
memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
started = btsnd_hcic_ble_remove_from_white_list (p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr);
|
|
|
|
}
|
|
|
|
p_dev_rec->ble.in_controller_list &= ~BTM_WHITE_LIST_BIT;
|
|
|
|
}
|
2019-03-14 06:03:36 +00:00
|
|
|
} // if not a known device, shall we add it?
|
2016-11-24 18:10:15 +00:00
|
|
|
else {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (to_add) {
|
2016-09-26 13:37:39 +00:00
|
|
|
started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr);
|
2017-09-27 07:29:42 +00:00
|
|
|
}else{
|
|
|
|
started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return started;
|
2019-03-14 06:03:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Controller do not support resolvable address now, only support public address and static random address */
|
|
|
|
BOOLEAN started = FALSE;
|
|
|
|
if(wl_addr_type > BLE_ADDR_RANDOM) {
|
|
|
|
BTM_TRACE_ERROR("wl_addr_type is error\n");
|
|
|
|
return started;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to_add) {
|
|
|
|
started = btsnd_hcic_ble_add_white_list (wl_addr_type, bd_addr);
|
|
|
|
}else{
|
|
|
|
started = btsnd_hcic_ble_remove_from_white_list (wl_addr_type, bd_addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return started;
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_execute_wl_dev_operation
|
|
|
|
**
|
|
|
|
** Description execute the pending whitelist device operation(loading or removing)
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_execute_wl_dev_operation(void)
|
|
|
|
{
|
|
|
|
tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q;
|
|
|
|
UINT8 i = 0;
|
|
|
|
BOOLEAN rt = TRUE;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && rt; i ++, p_dev_op ++) {
|
|
|
|
if (p_dev_op->in_use) {
|
2019-03-14 06:03:36 +00:00
|
|
|
rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr, p_dev_op->addr_type);
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_dev_op, 0, sizeof(tBTM_BLE_WL_OP));
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
break;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_enq_wl_dev_operation
|
|
|
|
**
|
|
|
|
** Description enqueue the pending whitelist device operation(loading or removing).
|
|
|
|
*******************************************************************************/
|
2019-03-14 06:03:36 +00:00
|
|
|
void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q;
|
|
|
|
UINT8 i = 0;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_dev_op ++) {
|
2019-03-14 06:03:36 +00:00
|
|
|
if (p_dev_op->in_use && p_dev_op->addr_type == addr_type && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_dev_op->to_add = to_add;
|
|
|
|
return;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (!p_dev_op->in_use) {
|
2016-09-26 13:37:39 +00:00
|
|
|
break;
|
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 (i != BTM_BLE_MAX_BG_CONN_DEV_NUM) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_dev_op->in_use = TRUE;
|
|
|
|
p_dev_op->to_add = to_add;
|
2019-03-14 06:03:36 +00:00
|
|
|
p_dev_op->addr_type = addr_type;
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_TRACE_ERROR("max pending WL operation reached, discard");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_update_dev_to_white_list
|
|
|
|
**
|
|
|
|
** Description This function adds or removes a device into/from
|
|
|
|
** the white list.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2019-03-14 06:03:36 +00:00
|
|
|
BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBTM_ADD_WHITELIST_CBACK *add_wl_cb)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2019-03-14 06:03:36 +00:00
|
|
|
if(addr_type > BLE_ADDR_RANDOM) {
|
|
|
|
BTM_TRACE_ERROR("%s address type is error, unable to add device", __func__);
|
|
|
|
if (add_wl_cb){
|
|
|
|
add_wl_cb(HCI_ERR_ILLEGAL_PARAMETER_FMT,to_add);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(addr_type == BLE_ADDR_RANDOM) {
|
|
|
|
/*
|
|
|
|
A static address is a 48-bit randomly generated address and shall meet the following requirements:
|
|
|
|
• The two most significant bits of the address shall be equal to 1
|
|
|
|
• All bits of the random part of the address shall not be equal to 1
|
|
|
|
• All bits of the random part of the address shall not be equal to 0
|
|
|
|
*/
|
|
|
|
BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b;
|
|
|
|
memset(invalid_rand_addr_a, 0xff, sizeof(BD_ADDR));
|
|
|
|
memset(invalid_rand_addr_b, 0x00, sizeof(BD_ADDR));
|
|
|
|
invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK;
|
|
|
|
if((bd_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK
|
|
|
|
&& memcmp(invalid_rand_addr_a, bd_addr, BD_ADDR_LEN) != 0
|
|
|
|
&& memcmp(invalid_rand_addr_b, bd_addr, BD_ADDR_LEN) != 0){
|
|
|
|
// do nothing
|
|
|
|
} else {
|
|
|
|
BTC_TRACE_ERROR(" controller not support resolvable address");
|
|
|
|
if (add_wl_cb){
|
|
|
|
add_wl_cb(HCI_ERR_ILLEGAL_PARAMETER_FMT,to_add);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (to_add && p_cb->white_list_avail_size == 0) {
|
2017-12-19 08:41:07 +00:00
|
|
|
BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__);
|
|
|
|
if (add_wl_cb){
|
|
|
|
add_wl_cb(HCI_ERR_MEMORY_FULL,to_add);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (to_add) {
|
2017-08-15 03:24:36 +00:00
|
|
|
/* added the bd_addr to the connection hash map queue */
|
2018-01-02 09:20:34 +00:00
|
|
|
if(!background_connection_add((bt_bdaddr_t *)bd_addr)) {
|
|
|
|
/* if the bd_addr already exist in whitelist, just callback return TRUE */
|
|
|
|
if (add_wl_cb){
|
|
|
|
add_wl_cb(HCI_SUCCESS,to_add);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2017-08-15 03:24:36 +00:00
|
|
|
/* remove the bd_addr to the connection hash map queue */
|
2018-01-02 09:20:34 +00:00
|
|
|
if(!background_connection_remove((bt_bdaddr_t *)bd_addr)){
|
|
|
|
/* if the bd_addr don't exist in whitelist, just callback return TRUE */
|
|
|
|
if (add_wl_cb){
|
|
|
|
add_wl_cb(HCI_SUCCESS,to_add);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (add_wl_cb){
|
|
|
|
//save add whitelist complete callback
|
|
|
|
p_cb->add_wl_cb = add_wl_cb;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2017-08-15 03:24:36 +00:00
|
|
|
/* stop the auto connect */
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_suspend_wl_activity(p_cb->wl_state);
|
2017-08-15 03:24:36 +00:00
|
|
|
/* save the bd_addr to the btm_cb env */
|
2019-03-14 06:03:36 +00:00
|
|
|
btm_enq_wl_dev_operation(to_add, bd_addr, addr_type);
|
2017-09-27 07:29:42 +00:00
|
|
|
/* save the ba_addr to the controller white list */
|
|
|
|
btm_wl_update_to_controller();
|
2016-09-26 13:37:39 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_clear_white_list
|
|
|
|
**
|
|
|
|
** Description This function clears the white list.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_clear_white_list (void)
|
|
|
|
{
|
|
|
|
BTM_TRACE_EVENT ("btm_ble_clear_white_list");
|
|
|
|
btsnd_hcic_ble_clear_white_list();
|
|
|
|
background_connections_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_clear_white_list_complete
|
|
|
|
**
|
|
|
|
** Description Indicates white list cleared.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_clear_white_list_complete(UINT8 *p_data, UINT16 evt_len)
|
|
|
|
{
|
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
|
|
|
UINT8 status;
|
|
|
|
UNUSED(evt_len);
|
|
|
|
|
|
|
|
BTM_TRACE_EVENT ("btm_ble_clear_white_list_complete");
|
|
|
|
STREAM_TO_UINT8 (status, p_data);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (status == HCI_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_cb->white_list_avail_size = controller_get_interface()->get_ble_white_list_size();
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_white_list_init
|
|
|
|
**
|
|
|
|
** Description Initialize white list size
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_white_list_init(UINT8 white_list_size)
|
|
|
|
{
|
|
|
|
BTM_TRACE_DEBUG("%s white_list_size = %d", __func__, white_list_size);
|
|
|
|
btm_cb.ble_ctr_cb.white_list_avail_size = white_list_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_add_2_white_list_complete
|
|
|
|
**
|
|
|
|
** Description White list element added
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_add_2_white_list_complete(UINT8 status)
|
|
|
|
{
|
|
|
|
BTM_TRACE_EVENT("%s status=%d", __func__, status);
|
2017-09-27 07:29:42 +00:00
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (status == HCI_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
--btm_cb.ble_ctr_cb.white_list_avail_size;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2017-09-27 07:29:42 +00:00
|
|
|
// add whitelist complete callback
|
|
|
|
if (p_cb->add_wl_cb)
|
|
|
|
{
|
|
|
|
(*p_cb->add_wl_cb)(status, BTM_WHITELIST_ADD);
|
|
|
|
}
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_remove_from_white_list_complete
|
|
|
|
**
|
|
|
|
** Description White list element removal complete
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len)
|
|
|
|
{
|
2017-09-27 07:29:42 +00:00
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
2016-09-26 13:37:39 +00:00
|
|
|
UNUSED(evt_len);
|
|
|
|
BTM_TRACE_EVENT ("%s status=%d", __func__, *p);
|
2016-11-24 18:10:15 +00:00
|
|
|
if (*p == HCI_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
++btm_cb.ble_ctr_cb.white_list_avail_size;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2017-09-27 07:29:42 +00:00
|
|
|
if (p_cb->add_wl_cb)
|
|
|
|
{
|
|
|
|
(*p_cb->add_wl_cb)(*p, BTM_WHITELIST_REMOVE);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_start_auto_conn
|
|
|
|
**
|
|
|
|
** Description This function is to start/stop auto connection procedure.
|
|
|
|
**
|
|
|
|
** Parameters start: TRUE to start; FALSE to stop.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_ble_start_auto_conn(BOOLEAN start)
|
|
|
|
{
|
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
|
|
|
BD_ADDR dummy_bda = {0};
|
|
|
|
BOOLEAN exec = TRUE;
|
|
|
|
UINT16 scan_int;
|
|
|
|
UINT16 scan_win;
|
|
|
|
UINT8 own_addr_type = p_cb->addr_mgnt_cb.own_addr_type;
|
|
|
|
UINT8 peer_addr_type = BLE_ADDR_PUBLIC;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (start) {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (p_cb->conn_state == BLE_CONN_IDLE && background_connections_pending()
|
2016-11-24 18:10:15 +00:00
|
|
|
&& btm_ble_topology_check(BTM_BLE_STATE_INIT)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_cb->wl_state |= BTM_BLE_WL_INIT;
|
|
|
|
|
|
|
|
btm_execute_wl_dev_operation();
|
|
|
|
|
|
|
|
#if BLE_PRIVACY_SPT == TRUE
|
|
|
|
btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT);
|
|
|
|
#endif
|
|
|
|
scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF) ?
|
2016-11-24 18:10:15 +00:00
|
|
|
BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int;
|
2016-09-26 13:37:39 +00:00
|
|
|
scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ?
|
2016-11-24 18:10:15 +00:00
|
|
|
BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#if BLE_PRIVACY_SPT == TRUE
|
|
|
|
if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE
|
2016-11-24 18:10:15 +00:00
|
|
|
&& controller_get_interface()->supports_ble_privacy()) {
|
2016-09-26 13:37:39 +00:00
|
|
|
own_addr_type |= BLE_ADDR_TYPE_ID_BIT;
|
|
|
|
peer_addr_type |= BLE_ADDR_TYPE_ID_BIT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */
|
|
|
|
scan_win, /* UINT16 scan_win */
|
|
|
|
0x01, /* UINT8 white_list */
|
|
|
|
peer_addr_type, /* UINT8 addr_type_peer */
|
|
|
|
dummy_bda, /* BD_ADDR bda_peer */
|
|
|
|
own_addr_type, /* UINT8 addr_type_own */
|
|
|
|
BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */
|
|
|
|
BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */
|
|
|
|
BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */
|
|
|
|
BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */
|
|
|
|
0, /* UINT16 min_len */
|
2016-11-24 18:10:15 +00:00
|
|
|
0)) { /* UINT16 max_len */
|
2016-09-26 13:37:39 +00:00
|
|
|
/* start auto connection failed */
|
|
|
|
exec = FALSE;
|
|
|
|
p_cb->wl_state &= ~BTM_BLE_WL_INIT;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_set_conn_st (BLE_BG_CONN);
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
exec = FALSE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
if (p_cb->conn_state == BLE_BG_CONN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btsnd_hcic_ble_create_conn_cancel();
|
|
|
|
btm_ble_set_conn_st (BLE_CONN_CANCEL);
|
|
|
|
p_cb->wl_state &= ~BTM_BLE_WL_INIT;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop", p_cb->conn_state);
|
|
|
|
exec = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exec;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_start_select_conn
|
|
|
|
**
|
|
|
|
** Description This function is to start/stop selective connection procedure.
|
|
|
|
**
|
|
|
|
** Parameters start: TRUE to start; FALSE to stop.
|
|
|
|
** p_select_cback: callback function to return application
|
|
|
|
** selection.
|
|
|
|
**
|
2016-11-28 06:58:30 +00:00
|
|
|
** Returns BOOLEAN: selective connection procedure is started.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cback)
|
|
|
|
{
|
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
|
|
|
UINT32 scan_int = p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
|
|
|
|
UINT32 scan_win = p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
|
|
|
|
|
|
|
|
BTM_TRACE_EVENT ("%s", __func__);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (start) {
|
|
|
|
if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) {
|
|
|
|
if (p_select_cback != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_cb.ble_ctr_cb.p_select_cback = p_select_cback;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
btm_execute_wl_dev_operation();
|
|
|
|
|
|
|
|
btm_update_scanner_filter_policy(SP_ADV_WL);
|
|
|
|
btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS;
|
|
|
|
|
|
|
|
/* Process advertising packets only from devices in the white list */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.cmn_ble_vsc_cb.extended_scan_support == 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* use passive scan by default */
|
|
|
|
if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS,
|
|
|
|
scan_int,
|
|
|
|
scan_win,
|
|
|
|
p_cb->addr_mgnt_cb.own_addr_type,
|
2016-11-24 18:10:15 +00:00
|
|
|
SP_ADV_WL)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (!btm_ble_send_extended_scan_params(BTM_BLE_SCAN_MODE_PASS,
|
|
|
|
scan_int,
|
|
|
|
scan_win,
|
|
|
|
p_cb->addr_mgnt_cb.own_addr_type,
|
2016-11-24 18:10:15 +00:00
|
|
|
SP_ADV_WL)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!btm_ble_topology_check(BTM_BLE_STATE_PASSIVE_SCAN)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_TRACE_ERROR("peripheral device cannot initiate passive scan for a selective connection");
|
|
|
|
return FALSE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (background_connections_pending()) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if BLE_PRIVACY_SPT == TRUE
|
|
|
|
btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN);
|
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) { /* duplicate filtering enabled */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* mark up inquiry status flag */
|
|
|
|
p_cb->scan_activity |= BTM_LE_SELECT_CONN_ACTIVE;
|
|
|
|
p_cb->wl_state |= BTM_BLE_WL_SCAN;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_TRACE_ERROR("scan active, can not start selective connection procedure");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* disable selective connection mode */
|
2016-09-26 13:37:39 +00:00
|
|
|
p_cb->scan_activity &= ~BTM_LE_SELECT_CONN_ACTIVE;
|
|
|
|
p_cb->p_select_cback = NULL;
|
|
|
|
p_cb->wl_state &= ~BTM_BLE_WL_SCAN;
|
|
|
|
|
|
|
|
/* stop scanning */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!BTM_BLE_IS_SCAN_ACTIVE(p_cb->scan_activity)) {
|
|
|
|
btm_ble_stop_scan(); /* duplicate filtering enabled */
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_initiate_select_conn
|
|
|
|
**
|
|
|
|
** Description This function is to start/stop selective connection procedure.
|
|
|
|
**
|
|
|
|
** Parameters start: TRUE to start; FALSE to stop.
|
|
|
|
** p_select_cback: callback function to return application
|
|
|
|
** selection.
|
|
|
|
**
|
2016-11-28 06:58:30 +00:00
|
|
|
** Returns BOOLEAN: selective connection procedure is started.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_initiate_select_conn(BD_ADDR bda)
|
|
|
|
{
|
|
|
|
BTM_TRACE_EVENT ("btm_ble_initiate_select_conn");
|
|
|
|
|
|
|
|
/* use direct connection procedure to initiate connection */
|
2018-03-23 03:08:03 +00:00
|
|
|
if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda, BLE_ADDR_UNKNOWN_TYPE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
BTM_TRACE_ERROR("btm_ble_initiate_select_conn failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_suspend_bg_conn
|
|
|
|
**
|
|
|
|
** Description This function is to suspend an active background connection
|
|
|
|
** procedure.
|
|
|
|
**
|
|
|
|
** Parameters none.
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_ble_suspend_bg_conn(void)
|
|
|
|
{
|
2016-11-02 06:05:30 +00:00
|
|
|
BTM_TRACE_EVENT ("%s\n", __func__);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_AUTO) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return btm_ble_start_auto_conn(FALSE);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (btm_cb.ble_ctr_cb.bg_conn_type == BTM_BLE_CONN_SELECTIVE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return btm_ble_start_select_conn(FALSE, NULL);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_suspend_wl_activity
|
|
|
|
**
|
|
|
|
** Description This function is to suspend white list related activity
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
if (wl_state & BTM_BLE_WL_INIT) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_start_auto_conn(FALSE);
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (wl_state & BTM_BLE_WL_SCAN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_start_select_conn(FALSE, NULL);
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (wl_state & BTM_BLE_WL_ADV) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_stop_adv();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_resume_wl_activity
|
|
|
|
**
|
|
|
|
** Description This function is to resume white list related activity
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-09-27 07:29:42 +00:00
|
|
|
void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
btm_ble_resume_bg_conn();
|
2016-11-24 18:10:15 +00:00
|
|
|
if (wl_state & BTM_BLE_WL_ADV) {
|
|
|
|
btm_ble_start_adv();
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 07:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_wl_update_to_controller
|
|
|
|
**
|
|
|
|
** Description This function is to update white list to controller
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void btm_wl_update_to_controller(void)
|
|
|
|
{
|
|
|
|
/* whitelist will be added in the btm_ble_resume_bg_conn(), we do not
|
|
|
|
support background connection now, so we nedd to use btm_execute_wl_dev_operation
|
|
|
|
to add whitelist directly ,if we support background connection in the future,
|
|
|
|
please delete btm_execute_wl_dev_operation(). */
|
|
|
|
btm_execute_wl_dev_operation();
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_resume_bg_conn
|
|
|
|
**
|
|
|
|
** Description This function is to resume a background auto connection
|
|
|
|
** procedure.
|
|
|
|
**
|
|
|
|
** Parameters none.
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_ble_resume_bg_conn(void)
|
|
|
|
{
|
|
|
|
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
|
|
|
BOOLEAN ret = FALSE;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE) {
|
|
|
|
if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO) {
|
2016-09-26 13:37:39 +00:00
|
|
|
ret = btm_ble_start_auto_conn(TRUE);
|
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 (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
ret = btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_get_conn_st
|
|
|
|
**
|
|
|
|
** Description This function get BLE connection state
|
|
|
|
**
|
|
|
|
** Returns connection state
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTM_BLE_CONN_ST btm_ble_get_conn_st(void)
|
|
|
|
{
|
|
|
|
return btm_cb.ble_ctr_cb.conn_state;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_set_conn_st
|
|
|
|
**
|
|
|
|
** Description This function set BLE connection state
|
|
|
|
**
|
|
|
|
** Returns None.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st)
|
|
|
|
{
|
|
|
|
btm_cb.ble_ctr_cb.conn_state = new_st;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (new_st == BLE_BG_CONN || new_st == BLE_DIR_CONN) {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_ble_enqueue_direct_conn_req
|
|
|
|
**
|
|
|
|
** Description This function enqueue the direct connection request
|
|
|
|
**
|
|
|
|
** Returns None.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void btm_ble_enqueue_direct_conn_req(void *p_param)
|
|
|
|
{
|
2017-08-17 13:13:45 +00:00
|
|
|
tBTM_BLE_CONN_REQ *p = (tBTM_BLE_CONN_REQ *)osi_malloc(sizeof(tBTM_BLE_CONN_REQ));
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p->p_param = p_param;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
fixed_queue_enqueue(btm_cb.ble_ctr_cb.conn_pending_q, p);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function btm_send_pending_direct_conn
|
|
|
|
**
|
|
|
|
** Description This function send the pending direct connection request in queue
|
|
|
|
**
|
|
|
|
** Returns TRUE if started, FALSE otherwise
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN btm_send_pending_direct_conn(void)
|
|
|
|
{
|
|
|
|
tBTM_BLE_CONN_REQ *p_req;
|
|
|
|
BOOLEAN rt = FALSE;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
p_req = (tBTM_BLE_CONN_REQ*)fixed_queue_try_dequeue(btm_cb.ble_ctr_cb.conn_pending_q);
|
|
|
|
if (p_req != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param));
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free((void *)p_req);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|