2016-10-18 09:49:00 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Google, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
#include <stdbool.h>
|
2018-05-20 23:33:30 -04:00
|
|
|
#include "common/bt_target.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "common/bt_trace.h"
|
|
|
|
#include "device/bdaddr.h"
|
|
|
|
#include "stack/bt_types.h"
|
|
|
|
#include "device/controller.h"
|
|
|
|
#include "device/event_mask.h"
|
|
|
|
#include "stack/hcimsgs.h"
|
|
|
|
#include "hci/hci_layer.h"
|
|
|
|
#include "hci/hci_packet_factory.h"
|
|
|
|
#include "hci/hci_packet_parser.h"
|
|
|
|
#include "stack/btm_ble_api.h"
|
|
|
|
#include "device/version.h"
|
|
|
|
#include "osi/future.h"
|
2016-10-18 09:49:00 -04:00
|
|
|
|
|
|
|
const bt_event_mask_t BLE_EVENT_MASK = { "\x00\x00\x00\x00\x00\x00\x06\x7f" };
|
|
|
|
|
|
|
|
#if (BLE_INCLUDED)
|
|
|
|
const bt_event_mask_t CLASSIC_EVENT_MASK = { HCI_DUMO_EVENT_MASK_EXT };
|
|
|
|
#else
|
|
|
|
const bt_event_mask_t CLASSIC_EVENT_MASK = { HCI_LISBON_EVENT_MASK_EXT };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO(zachoverflow): factor out into common module
|
|
|
|
const uint8_t SCO_HOST_BUFFER_SIZE = 0xff;
|
|
|
|
|
|
|
|
#define HCI_SUPPORTED_COMMANDS_ARRAY_SIZE 64
|
|
|
|
#define MAX_FEATURES_CLASSIC_PAGE_COUNT 3
|
|
|
|
#define BLE_SUPPORTED_STATES_SIZE 8
|
|
|
|
#define BLE_SUPPORTED_FEATURES_SIZE 8
|
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
typedef struct {
|
|
|
|
const hci_t *hci;
|
|
|
|
const hci_packet_factory_t *packet_factory;
|
|
|
|
const hci_packet_parser_t *packet_parser;
|
|
|
|
|
|
|
|
bt_version_t bt_version;
|
|
|
|
bt_bdaddr_t address;
|
|
|
|
|
|
|
|
uint8_t supported_commands[HCI_SUPPORTED_COMMANDS_ARRAY_SIZE];
|
|
|
|
uint8_t last_features_classic_page_index;
|
|
|
|
bt_device_features_t features_classic[MAX_FEATURES_CLASSIC_PAGE_COUNT];
|
|
|
|
|
|
|
|
uint16_t acl_data_size_classic;
|
|
|
|
uint16_t acl_data_size_ble;
|
|
|
|
uint16_t acl_buffer_count_classic;
|
|
|
|
uint8_t acl_buffer_count_ble;
|
|
|
|
|
|
|
|
uint8_t sco_data_size;
|
|
|
|
uint16_t sco_buffer_count;
|
|
|
|
|
|
|
|
uint8_t ble_white_list_size;
|
|
|
|
uint8_t ble_resolving_list_max_size;
|
|
|
|
uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE];
|
|
|
|
bt_device_features_t features_ble;
|
|
|
|
uint16_t ble_suggested_default_data_length;
|
|
|
|
uint16_t ble_suggested_default_data_txtime;
|
|
|
|
|
|
|
|
bool readable;
|
|
|
|
bool ble_supported;
|
|
|
|
bool simple_pairing_supported;
|
|
|
|
bool secure_connections_supported;
|
|
|
|
} controller_local_param_t;
|
|
|
|
|
|
|
|
#if BT_BLE_DYNAMIC_ENV_MEMORY == FALSE
|
|
|
|
static controller_local_param_t controller_param;
|
|
|
|
#else
|
|
|
|
static controller_local_param_t *controller_param_ptr;
|
|
|
|
#define controller_param (*controller_param_ptr)
|
|
|
|
#endif
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
#define AWAIT_COMMAND(command) future_await(controller_param.hci->transmit_command_futured(command))
|
2016-10-18 09:49:00 -04:00
|
|
|
|
|
|
|
// Module lifecycle functions
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static void start_up(void)
|
|
|
|
{
|
|
|
|
BT_HDR *response;
|
|
|
|
|
|
|
|
// Send the initial reset command
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_reset());
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Request the classic buffer size next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_read_buffer_size());
|
|
|
|
controller_param.packet_parser->parse_read_buffer_size_response(
|
|
|
|
response, &controller_param.acl_data_size_classic, &controller_param.acl_buffer_count_classic,
|
|
|
|
&controller_param.sco_data_size, &controller_param.sco_buffer_count);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
2018-06-20 23:41:42 -04:00
|
|
|
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
|
|
|
|
// Enable controller to host flow control
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_set_c2h_flow_control(HCI_HOST_FLOW_CTRL_ACL_ON));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2018-06-20 23:41:42 -04:00
|
|
|
#endif ///C2H_FLOW_CONTROL_INCLUDED == TRUE
|
2019-03-01 08:59:55 -05:00
|
|
|
#if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE)
|
|
|
|
// Enable adv flow control
|
2019-06-20 23:55:45 -04:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_set_adv_report_flow_control(HCI_HOST_FLOW_CTRL_ADV_REPORT_ON, (uint16_t)BLE_ADV_REPORT_FLOW_CONTROL_NUM, (uint16_t)BLE_ADV_REPORT_DISCARD_THRSHOLD));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2019-03-01 08:59:55 -05:00
|
|
|
#endif
|
2016-11-24 13:10:15 -05:00
|
|
|
// Tell the controller about our buffer sizes and buffer counts next
|
|
|
|
// TODO(zachoverflow): factor this out. eww l2cap contamination. And why just a hardcoded 10?
|
2016-10-18 09:49:00 -04:00
|
|
|
response = AWAIT_COMMAND(
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.packet_factory->make_host_buffer_size(
|
2016-11-24 13:10:15 -05:00
|
|
|
L2CAP_MTU_SIZE,
|
|
|
|
SCO_HOST_BUFFER_SIZE,
|
|
|
|
L2CAP_HOST_FC_ACL_BUFS,
|
|
|
|
10
|
|
|
|
)
|
|
|
|
);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Read the local version info off the controller next, including
|
|
|
|
// information such as manufacturer and supported HCI version
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_version_info());
|
|
|
|
controller_param.packet_parser->parse_read_local_version_info_response(response, &controller_param.bt_version);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
// Read the bluetooth address off the controller next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_read_bd_addr());
|
|
|
|
controller_param.packet_parser->parse_read_bd_addr_response(response, &controller_param.address);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
// Request the controller's supported commands next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_supported_commands());
|
|
|
|
controller_param.packet_parser->parse_read_local_supported_commands_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.supported_commands,
|
2016-11-24 13:10:15 -05:00
|
|
|
HCI_SUPPORTED_COMMANDS_ARRAY_SIZE
|
|
|
|
);
|
|
|
|
|
|
|
|
// Read page 0 of the controller features next
|
|
|
|
uint8_t page_number = 0;
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_extended_features(page_number));
|
|
|
|
controller_param.packet_parser->parse_read_local_extended_features_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
|
|
|
&page_number,
|
2018-11-06 02:34:38 -05:00
|
|
|
&controller_param.last_features_classic_page_index,
|
|
|
|
controller_param.features_classic,
|
2016-11-24 13:10:15 -05:00
|
|
|
MAX_FEATURES_CLASSIC_PAGE_COUNT
|
2016-10-18 09:49:00 -04:00
|
|
|
);
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
assert(page_number == 0);
|
2016-10-18 09:49:00 -04:00
|
|
|
page_number++;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Inform the controller what page 0 features we support, based on what
|
|
|
|
// it told us it supports. We need to do this first before we request the
|
|
|
|
// next page, because the controller's response for page 1 may be
|
|
|
|
// dependent on what we configure from page 0
|
2018-12-07 01:19:47 -05:00
|
|
|
#if (BT_SSP_INCLUDED == TRUE)
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.simple_pairing_supported = HCI_SIMPLE_PAIRING_SUPPORTED(controller_param.features_classic[0].as_array);
|
2018-12-07 01:19:47 -05:00
|
|
|
#else
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.simple_pairing_supported = false;
|
2018-12-07 01:19:47 -05:00
|
|
|
#endif
|
2018-11-06 02:34:38 -05:00
|
|
|
|
|
|
|
if (controller_param.simple_pairing_supported) {
|
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_write_simple_pairing_mode(HCI_SP_MODE_ENABLED));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-10-18 09:49:00 -04:00
|
|
|
|
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2018-11-06 02:34:38 -05:00
|
|
|
if (HCI_LE_SPT_SUPPORTED(controller_param.features_classic[0].as_array)) {
|
|
|
|
uint8_t simultaneous_le_host = HCI_SIMUL_LE_BREDR_SUPPORTED(controller_param.features_classic[0].as_array) ? BTM_BLE_SIMULTANEOUS_HOST : 0;
|
2016-11-24 13:10:15 -05:00
|
|
|
response = AWAIT_COMMAND(
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.packet_factory->make_ble_write_host_support(BTM_BLE_HOST_SUPPORT, simultaneous_le_host)
|
2016-11-24 13:10:15 -05:00
|
|
|
);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
#endif
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Done telling the controller about what page 0 features we support
|
|
|
|
// Request the remaining feature pages
|
2018-11-06 02:34:38 -05:00
|
|
|
while (page_number <= controller_param.last_features_classic_page_index &&
|
2016-11-24 13:10:15 -05:00
|
|
|
page_number < MAX_FEATURES_CLASSIC_PAGE_COUNT) {
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_read_local_extended_features(page_number));
|
|
|
|
controller_param.packet_parser->parse_read_local_extended_features_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
|
|
|
&page_number,
|
2018-11-06 02:34:38 -05:00
|
|
|
&controller_param.last_features_classic_page_index,
|
|
|
|
controller_param.features_classic,
|
2016-11-24 13:10:15 -05:00
|
|
|
MAX_FEATURES_CLASSIC_PAGE_COUNT
|
|
|
|
);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
page_number++;
|
|
|
|
}
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
#if (SC_MODE_INCLUDED == TRUE)
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.secure_connections_supported = HCI_SC_CTRLR_SUPPORTED(controller_param.features_classic[2].as_array);
|
|
|
|
if (controller_param.secure_connections_supported) {
|
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_write_secure_connections_host_support(HCI_SC_MODE_ENABLED));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
#endif
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
#if (BLE_INCLUDED == TRUE)
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.ble_supported = controller_param.last_features_classic_page_index >= 1 && HCI_LE_HOST_SUPPORTED(controller_param.features_classic[1].as_array);
|
|
|
|
if (controller_param.ble_supported) {
|
2016-11-24 13:10:15 -05:00
|
|
|
// Request the ble white list size next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_white_list_size());
|
|
|
|
controller_param.packet_parser->parse_ble_read_white_list_size_response(response, &controller_param.ble_white_list_size);
|
2016-11-24 13:10:15 -05:00
|
|
|
|
|
|
|
// Request the ble buffer size next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_buffer_size());
|
|
|
|
controller_param.packet_parser->parse_ble_read_buffer_size_response(
|
2016-10-18 09:49:00 -04:00
|
|
|
response,
|
2018-11-06 02:34:38 -05:00
|
|
|
&controller_param.acl_data_size_ble,
|
|
|
|
&controller_param.acl_buffer_count_ble
|
2016-11-24 13:10:15 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// Response of 0 indicates ble has the same buffer size as classic
|
2018-11-06 02:34:38 -05:00
|
|
|
if (controller_param.acl_data_size_ble == 0) {
|
|
|
|
controller_param.acl_data_size_ble = controller_param.acl_data_size_classic;
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Request the ble supported states next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_supported_states());
|
|
|
|
controller_param.packet_parser->parse_ble_read_supported_states_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.ble_supported_states,
|
|
|
|
sizeof(controller_param.ble_supported_states)
|
2016-11-24 13:10:15 -05:00
|
|
|
);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
// Request the ble supported features next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_local_supported_features());
|
|
|
|
controller_param.packet_parser->parse_ble_read_local_supported_features_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
2018-11-06 02:34:38 -05:00
|
|
|
&controller_param.features_ble
|
2016-11-24 13:10:15 -05:00
|
|
|
);
|
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
if (HCI_LE_ENHANCED_PRIVACY_SUPPORTED(controller_param.features_ble.as_array)) {
|
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_resolving_list_size());
|
|
|
|
controller_param.packet_parser->parse_ble_read_resolving_list_size_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
2018-11-06 02:34:38 -05:00
|
|
|
&controller_param.ble_resolving_list_max_size);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
if (HCI_LE_DATA_LEN_EXT_SUPPORTED(controller_param.features_ble.as_array)) {
|
2017-02-16 01:10:44 -05:00
|
|
|
/* set default tx data length to MAX 251 */
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_write_suggested_default_data_length(BTM_BLE_DATA_SIZE_MAX, BTM_BLE_DATA_TX_TIME_MAX));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2017-02-16 01:10:44 -05:00
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_read_suggested_default_data_length());
|
|
|
|
controller_param.packet_parser->parse_ble_read_suggested_default_data_length_response(
|
2016-11-24 13:10:15 -05:00
|
|
|
response,
|
2018-11-06 02:34:38 -05:00
|
|
|
&controller_param.ble_suggested_default_data_length,
|
|
|
|
&controller_param.ble_suggested_default_data_txtime);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the ble event mask next
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_ble_set_event_mask(&BLE_EVENT_MASK));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-10-18 09:49:00 -04:00
|
|
|
#endif
|
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_set_event_mask(&CLASSIC_EVENT_MASK));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2018-05-20 23:33:30 -04:00
|
|
|
#if (BTM_SCO_HCI_INCLUDED == TRUE)
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_write_sync_flow_control_enable(1));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2018-07-05 03:22:44 -04:00
|
|
|
|
2018-11-06 02:34:38 -05:00
|
|
|
response = AWAIT_COMMAND(controller_param.packet_factory->make_write_default_erroneous_data_report(1));
|
|
|
|
controller_param.packet_parser->parse_generic_command_complete(response);
|
2018-05-20 23:33:30 -04:00
|
|
|
#endif
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.readable = true;
|
2016-11-24 13:10:15 -05:00
|
|
|
// return future_new_immediate(FUTURE_SUCCESS);
|
|
|
|
return;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static void shut_down(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
controller_param.readable = false;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool get_is_ready(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
return controller_param.readable;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static const bt_bdaddr_t *get_address(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return &controller_param.address;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static const bt_version_t *get_bt_version(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return &controller_param.bt_version;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(zachoverflow): hide inside, move decoder inside too
|
2016-11-24 13:10:15 -05:00
|
|
|
static const bt_device_features_t *get_features_classic(int index)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
2016-11-24 13:10:15 -05:00
|
|
|
assert(index < MAX_FEATURES_CLASSIC_PAGE_COUNT);
|
2018-11-06 02:34:38 -05:00
|
|
|
return &controller_param.features_classic[index];
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint8_t get_last_features_classic_index(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.last_features_classic_page_index;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static const bt_device_features_t *get_features_ble(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return &controller_param.features_ble;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static const uint8_t *get_ble_supported_states(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.ble_supported_states;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_simple_pairing(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.simple_pairing_supported;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_secure_connections(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.secure_connections_supported;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_simultaneous_le_bredr(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return HCI_SIMUL_LE_BREDR_SUPPORTED(controller_param.features_classic[0].as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_reading_remote_extended_features(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(controller_param.supported_commands);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_interlaced_inquiry_scan(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(controller_param.features_classic[0].as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_rssi_with_inquiry_results(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return HCI_LMP_INQ_RSSI_SUPPORTED(controller_param.features_classic[0].as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_extended_inquiry_response(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return HCI_EXT_INQ_RSP_SUPPORTED(controller_param.features_classic[0].as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_master_slave_role_switch(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return HCI_SWITCH_SUPPORTED(controller_param.features_classic[0].as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_ble(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.ble_supported;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_ble_privacy(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(controller_param.features_ble.as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_ble_packet_extension(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return HCI_LE_DATA_LEN_EXT_SUPPORTED(controller_param.features_ble.as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static bool supports_ble_connection_parameters_request(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_param.features_ble.as_array);
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint16_t get_acl_data_size_classic(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.acl_data_size_classic;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint16_t get_acl_data_size_ble(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.acl_data_size_ble;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint16_t get_acl_packet_size_classic(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.acl_data_size_classic + HCI_DATA_PREAMBLE_SIZE;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint16_t get_acl_packet_size_ble(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.acl_data_size_ble + HCI_DATA_PREAMBLE_SIZE;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint16_t get_ble_suggested_default_data_length(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.ble_suggested_default_data_length;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2017-12-07 02:00:06 -05:00
|
|
|
static uint16_t get_ble_suggested_default_data_txtime(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.ble_suggested_default_data_txtime;
|
2017-12-07 02:00:06 -05:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint16_t get_acl_buffer_count_classic(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.acl_buffer_count_classic;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint8_t get_acl_buffer_count_ble(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.acl_buffer_count_ble;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint8_t get_ble_white_list_size(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.ble_white_list_size;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static uint8_t get_ble_resolving_list_max_size(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
return controller_param.ble_resolving_list_max_size;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
static void set_ble_resolving_list_max_size(int resolving_list_max_size)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
assert(controller_param.ble_supported);
|
|
|
|
controller_param.ble_resolving_list_max_size = resolving_list_max_size;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|
2018-05-20 23:33:30 -04:00
|
|
|
#if (BTM_SCO_HCI_INCLUDED == TRUE)
|
|
|
|
static uint8_t get_sco_data_size(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.sco_data_size;
|
2018-05-20 23:33:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t get_sco_buffer_count(void)
|
|
|
|
{
|
2018-11-06 02:34:38 -05:00
|
|
|
assert(controller_param.readable);
|
|
|
|
return controller_param.sco_buffer_count;
|
2018-05-20 23:33:30 -04:00
|
|
|
}
|
|
|
|
#endif /* (BTM_SCO_HCI_INCLUDED == TRUE) */
|
|
|
|
|
2016-10-18 09:49:00 -04:00
|
|
|
static const controller_t interface = {
|
2016-11-24 13:10:15 -05:00
|
|
|
start_up,
|
|
|
|
shut_down,
|
|
|
|
get_is_ready,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_address,
|
|
|
|
get_bt_version,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_features_classic,
|
|
|
|
get_last_features_classic_index,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_features_ble,
|
|
|
|
get_ble_supported_states,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
supports_simple_pairing,
|
|
|
|
supports_secure_connections,
|
|
|
|
supports_simultaneous_le_bredr,
|
|
|
|
supports_reading_remote_extended_features,
|
|
|
|
supports_interlaced_inquiry_scan,
|
|
|
|
supports_rssi_with_inquiry_results,
|
|
|
|
supports_extended_inquiry_response,
|
|
|
|
supports_master_slave_role_switch,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
supports_ble,
|
|
|
|
supports_ble_packet_extension,
|
|
|
|
supports_ble_connection_parameters_request,
|
|
|
|
supports_ble_privacy,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_acl_data_size_classic,
|
|
|
|
get_acl_data_size_ble,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_acl_packet_size_classic,
|
|
|
|
get_acl_packet_size_ble,
|
|
|
|
get_ble_suggested_default_data_length,
|
2017-12-07 02:00:06 -05:00
|
|
|
get_ble_suggested_default_data_txtime,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_acl_buffer_count_classic,
|
|
|
|
get_acl_buffer_count_ble,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_ble_white_list_size,
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
get_ble_resolving_list_max_size,
|
2018-05-20 23:33:30 -04:00
|
|
|
set_ble_resolving_list_max_size,
|
|
|
|
#if (BTM_SCO_HCI_INCLUDED == TRUE)
|
|
|
|
get_sco_data_size,
|
|
|
|
get_sco_buffer_count,
|
|
|
|
#endif /* (BTM_SCO_HCI_INCLUDED == TRUE) */
|
2016-10-18 09:49:00 -04:00
|
|
|
};
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
const controller_t *controller_get_interface()
|
|
|
|
{
|
|
|
|
static bool loaded = false;
|
|
|
|
if (!loaded) {
|
|
|
|
loaded = true;
|
2018-11-06 02:34:38 -05:00
|
|
|
#if BT_BLE_DYNAMIC_ENV_MEMORY == TRUE
|
|
|
|
controller_param_ptr = (controller_local_param_t *)osi_calloc(sizeof(controller_local_param_t));
|
|
|
|
assert(controller_param_ptr);
|
|
|
|
#endif
|
|
|
|
controller_param.hci = hci_layer_get_interface();
|
|
|
|
controller_param.packet_factory = hci_packet_factory_get_interface();
|
|
|
|
controller_param.packet_parser = hci_packet_parser_get_interface();
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
2016-10-18 09:49:00 -04:00
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
return &interface;
|
2016-10-18 09:49:00 -04:00
|
|
|
}
|
|
|
|
|