hci: disable parts of classic code if ENABLE_CLASSIC is not defined

This commit is contained in:
Matthias Ringwald 2016-10-19 16:06:11 +02:00
parent 5b9c6aad2e
commit 3545469685
5 changed files with 145 additions and 47 deletions

View File

@ -3,7 +3,9 @@ BTSTACK_ROOT = ../..
CORE += main.c stdin_support.c
COMMON += hci_transport_h2_libusb.c btstack_run_loop_posix.c btstack_link_key_db_fs.c le_device_db_fs.c
CLASSIC += btstack_link_key_db_fs.c
SM += le_device_db_fs.c
COMMON += hci_transport_h2_libusb.c btstack_run_loop_posix.c
include ${BTSTACK_ROOT}/example/Makefile.inc

View File

@ -136,8 +136,11 @@ int main(int argc, const char * argv[]){
// init HCI
hci_init(hci_transport_usb_instance(), NULL);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_fs_instance());
#endif
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);

View File

@ -1453,10 +1453,14 @@ static void sm_sc_cmac_done(uint8_t * hash){
link_key_type = sm_conn->sm_connection_authenticated ?
AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256 : UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256;
if (sm_conn->sm_role){
#ifdef ENABLE_CLASSIC
gap_store_link_key_for_bd_addr(setup->sm_m_address, setup->sm_t, link_key_type);
#endif
sm_conn->sm_engine_state = SM_RESPONDER_IDLE;
} else {
#ifdef ENABLE_CLASSIC
gap_store_link_key_for_bd_addr(setup->sm_s_address, setup->sm_t, link_key_type);
#endif
sm_conn->sm_engine_state = SM_INITIATOR_CONNECTED;
}
sm_done_for_handle(sm_conn->sm_handle);

173
src/hci.c
View File

@ -76,29 +76,31 @@
#define HCI_RESET_RESEND_TIMEOUT_MS 200
// prototypes
#ifdef ENABLE_CLASSIC
static void hci_update_scan_enable(void);
static void hci_emit_discoverable_enabled(uint8_t enabled);
static int hci_local_ssp_activated(void);
static int hci_remote_ssp_supported(hci_con_handle_t con_handle);
static void hci_notify_if_sco_can_send_now(void);
static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status);
static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection);
static void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level);
#endif
static void hci_connection_timeout_handler(btstack_timer_source_t *timer);
static void hci_connection_timestamp(hci_connection_t *connection);
static int hci_power_control_on(void);
static void hci_power_control_off(void);
static void hci_state_reset(void);
static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status);
static void hci_emit_l2cap_check_timeout(hci_connection_t *conn);
static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason);
static void hci_emit_nr_connections_changed(void);
static void hci_emit_hci_open_failed(void);
static void hci_emit_discoverable_enabled(uint8_t enabled);
static void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level);
static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status);
static void hci_emit_event(uint8_t * event, uint16_t size, int dump);
static void hci_emit_acl_packet(uint8_t * packet, uint16_t size);
static void hci_notify_if_sco_can_send_now(void);
static void hci_run(void);
static int hci_is_le_connection(hci_connection_t * connection);
static int hci_number_free_acl_slots_for_connection_type( bd_addr_type_t address_type);
static int hci_local_ssp_activated(void);
static int hci_remote_ssp_supported(hci_con_handle_t con_handle);
#ifdef ENABLE_BLE
// called from test/ble_client/advertising_data_parser.c
@ -230,15 +232,17 @@ static void hci_connection_timestamp(hci_connection_t *connection){
}
#ifdef ENABLE_CLASSIC
inline static void connectionSetAuthenticationFlags(hci_connection_t * conn, hci_authentication_flags_t flags){
conn->authentication_flags = (hci_authentication_flags_t)(conn->authentication_flags | flags);
}
inline static void connectionClearAuthenticationFlags(hci_connection_t * conn, hci_authentication_flags_t flags){
conn->authentication_flags = (hci_authentication_flags_t)(conn->authentication_flags & ~flags);
}
/**
* add authentication flags and reset timer
* @note: assumes classic connection
@ -273,6 +277,7 @@ void gap_store_link_key_for_bd_addr(bd_addr_t addr, link_key_t link_key, link_ke
log_info("gap_store_link_key_for_bd_addr: %s, type %u", bd_addr_to_str(addr), type);
hci_stack->link_key_db->put_link_key(addr, link_key, type);
}
#endif
static int hci_is_le_connection(hci_connection_t * connection){
return connection->address_type == BD_ADDR_TYPE_LE_PUBLIC ||
@ -354,6 +359,7 @@ int hci_number_free_acl_slots_for_handle(hci_con_handle_t con_handle){
return hci_number_free_acl_slots_for_connection_type(connection->address_type);
}
#ifdef ENABLE_CLASSIC
static int hci_number_free_sco_slots(void){
unsigned int num_sco_packets_sent = 0;
btstack_linked_item_t *it;
@ -368,6 +374,7 @@ static int hci_number_free_sco_slots(void){
// log_info("hci_number_free_sco_slots u", handle, num_sco_packets_sent);
return hci_stack->sco_packets_total_num - num_sco_packets_sent;
}
#endif
// new functions replacing hci_can_send_packet_now[_using_packet_buffer]
int hci_can_send_command_packet_now(void){
@ -394,11 +401,6 @@ static int hci_can_send_prepared_acl_packet_for_address_type(bd_addr_type_t addr
return hci_number_free_acl_slots_for_connection_type(address_type) > 0;
}
int hci_can_send_acl_classic_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return 0;
return hci_can_send_prepared_acl_packet_for_address_type(BD_ADDR_TYPE_CLASSIC);
}
int hci_can_send_acl_le_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return 0;
return hci_can_send_prepared_acl_packet_for_address_type(BD_ADDR_TYPE_LE_PUBLIC);
@ -414,6 +416,12 @@ int hci_can_send_acl_packet_now(hci_con_handle_t con_handle){
return hci_can_send_prepared_acl_packet_now(con_handle);
}
#ifdef ENABLE_CLASSIC
int hci_can_send_acl_classic_packet_now(void){
if (hci_stack->hci_packet_buffer_reserved) return 0;
return hci_can_send_prepared_acl_packet_for_address_type(BD_ADDR_TYPE_CLASSIC);
}
int hci_can_send_prepared_sco_packet_now(void){
if (!hci_transport_can_send_prepared_packet_now(HCI_SCO_DATA_PACKET)) return 0;
if (!hci_stack->synchronous_flow_control_enabled) return 1;
@ -429,6 +437,7 @@ void hci_request_sco_can_send_now_event(void){
hci_stack->sco_waiting_for_can_send_now = 1;
hci_notify_if_sco_can_send_now();
}
#endif
// used for internal checks in l2cap.c
int hci_is_packet_buffer_reserved(void){
@ -575,6 +584,7 @@ int hci_send_acl_packet_buffer(int size){
return hci_send_acl_packet_fragments(connection);
}
#ifdef ENABLE_CLASSIC
// pre: caller has reserved the packet buffer
int hci_send_sco_packet_buffer(int size){
@ -620,6 +630,7 @@ int hci_send_sco_packet_buffer(int size){
return err;
}
#endif
static void acl_handler(uint8_t *packet, int size){
@ -734,6 +745,8 @@ static void hci_shutdown_connection(hci_connection_t *conn){
hci_emit_nr_connections_changed();
}
#ifdef ENABLE_CLASSIC
static const uint16_t packet_type_sizes[] = {
0, HCI_ACL_2DH1_SIZE, HCI_ACL_3DH1_SIZE, HCI_ACL_DM1_SIZE,
HCI_ACL_DH1_SIZE, 0, 0, 0,
@ -783,6 +796,7 @@ static uint16_t hci_acl_packet_types_for_buffer_size_and_local_features(uint16_t
uint16_t hci_usable_acl_packet_types(void){
return hci_stack->packet_types;
}
#endif
uint8_t* hci_get_outgoing_packet_buffer(void){
// hci packet buffer is >= acl data packet length
@ -809,8 +823,12 @@ static int gap_ssp_supported(void){
}
static int hci_classic_supported(void){
#ifdef ENABLE_CLASSIC
// No. 37, byte 4, bit 5, = No BR/EDR Support
return (hci_stack->local_supported_features[4] & (1 << 5)) == 0;
#else
return 0;
#endif
}
static int hci_le_supported(void){
@ -1055,6 +1073,7 @@ static void hci_initializing_run(void){
hci_send_cmd(&hci_set_event_mask,0xffffffff, 0x1FFFFFFF);
}
break;
#ifdef ENABLE_CLASSIC
case HCI_INIT_WRITE_SIMPLE_PAIRING_MODE:
hci_stack->substate = HCI_INIT_W4_WRITE_SIMPLE_PAIRING_MODE;
hci_send_cmd(&hci_write_simple_pairing_mode, hci_stack->ssp_enable);
@ -1102,6 +1121,7 @@ static void hci_initializing_run(void){
hci_stack->substate = HCI_INIT_W4_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING;
hci_send_cmd(&hci_write_default_erroneous_data_reporting, 1);
break;
#endif
#ifdef ENABLE_BLE
// LE INIT
case HCI_INIT_LE_READ_BUFFER_SIZE:
@ -1338,8 +1358,6 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){
return;
}
break;
case HCI_INIT_W4_WRITE_PAGE_TIMEOUT:
break;
case HCI_INIT_W4_LE_READ_BUFFER_SIZE:
// skip write le host if not supported (e.g. on LE only EM9301)
if (hci_stack->local_supported_commands[0] & 0x02) break;
@ -1408,6 +1426,9 @@ static void event_handler(uint8_t *packet, int size){
hci_connection_t * conn;
int i;
// warnings
(void) link_type;
// log_info("HCI:EVENT:%02x", hci_event_packet_get_type(packet));
switch (hci_event_packet_get_type(packet)) {
@ -1461,17 +1482,21 @@ static void event_handler(uint8_t *packet, int size){
hci_stack->link_key_db->set_local_bd_addr(hci_stack->local_bd_addr);
}
}
#ifdef ENABLE_CLASSIC
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_write_scan_enable)){
hci_emit_discoverable_enabled(hci_stack->discoverable);
}
#endif
// Note: HCI init checks
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_features)){
memcpy(hci_stack->local_supported_features, &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1], 8);
#ifdef ENABLE_CLASSIC
// determine usable ACL packet types based on host buffer size and supported features
hci_stack->packet_types = hci_acl_packet_types_for_buffer_size_and_local_features(HCI_ACL_PAYLOAD_SIZE, &hci_stack->local_supported_features[0]);
log_info("Packet types %04x, eSCO %u", hci_stack->packet_types, hci_extended_sco_link_supported());
#endif
// Classic/LE
log_info("BR/EDR support %u, LE support %u", hci_classic_supported(), hci_le_supported());
}
@ -1523,6 +1548,7 @@ static void event_handler(uint8_t *packet, int size){
}
if (conn->address_type == BD_ADDR_TYPE_SCO){
#ifdef ENABLE_CLASSIC
if (conn->num_sco_packets_sent >= num_packets){
conn->num_sco_packets_sent -= num_packets;
} else {
@ -1530,6 +1556,7 @@ static void event_handler(uint8_t *packet, int size){
conn->num_sco_packets_sent = 0;
}
hci_notify_if_sco_can_send_now();
#endif
} else {
if (conn->num_acl_packets_sent >= num_packets){
conn->num_acl_packets_sent -= num_packets;
@ -1542,6 +1569,8 @@ static void event_handler(uint8_t *packet, int size){
}
break;
}
#ifdef ENABLE_CLASSIC
case HCI_EVENT_CONNECTION_REQUEST:
reverse_bd_addr(&packet[2], addr);
// TODO: eval COD 8-10
@ -1703,6 +1732,7 @@ static void event_handler(uint8_t *packet, int size){
if (!hci_stack->ssp_auto_accept) break;
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_USER_PASSKEY_REPLY);
break;
#endif
case HCI_EVENT_ENCRYPTION_CHANGE:
handle = little_endian_read_16(packet, 3);
@ -1715,9 +1745,12 @@ static void event_handler(uint8_t *packet, int size){
conn->authentication_flags &= ~CONNECTION_ENCRYPTED;
}
}
#ifdef ENABLE_CLASSIC
hci_emit_security_level(handle, gap_security_level_for_connection(conn));
#endif
break;
#ifdef ENABLE_CLASSIC
case HCI_EVENT_AUTHENTICATION_COMPLETE_EVENT:
handle = little_endian_read_16(packet, 3);
conn = hci_connection_for_handle(handle);
@ -1739,6 +1772,7 @@ static void event_handler(uint8_t *packet, int size){
// not enough
hci_emit_security_level(handle, gap_security_level_for_connection(conn));
break;
#endif
// HCI_EVENT_DISCONNECTION_COMPLETE
// has been split, to first notify stack before shutting connection down
@ -1754,12 +1788,15 @@ static void event_handler(uint8_t *packet, int size){
hci_stack->acl_fragmentation_pos = 0;
}
}
// re-enable advertisements for le connections if active
conn = hci_connection_for_handle(handle);
if (!conn) break;
#ifdef ENABLE_BLE
if (hci_is_le_connection(conn) && hci_stack->le_advertisements_enabled){
hci_stack->le_advertisements_todo |= LE_ADVERTISEMENT_TASKS_ENABLE;
}
#endif
conn->state = RECEIVED_DISCONNECTION_COMPLETE;
break;
@ -1793,14 +1830,18 @@ static void event_handler(uint8_t *packet, int size){
// L2CAP receives this event via the hci_emit_event below
#ifdef ENABLE_CLASSIC
// For SCO, we do the can_send_now_check here
hci_notify_if_sco_can_send_now();
#endif
break;
#ifdef ENABLE_CLASSIC
case HCI_EVENT_SCO_CAN_SEND_NOW:
// For SCO, we do the can_send_now_check here
hci_notify_if_sco_can_send_now();
return;
#endif
#ifdef ENABLE_BLE
case HCI_EVENT_LE_META:
@ -1912,10 +1953,12 @@ static void event_handler(uint8_t *packet, int size){
hci_run();
}
#ifdef ENABLE_CLASSIC
static void sco_handler(uint8_t * packet, uint16_t size){
if (!hci_stack->sco_packet_handler) return;
hci_stack->sco_packet_handler(HCI_SCO_DATA_PACKET, 0, packet, size);
}
#endif
static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
hci_dump_packet(packet_type, 1, packet, size);
@ -1926,9 +1969,11 @@ static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
case HCI_ACL_DATA_PACKET:
acl_handler(packet, size);
break;
#ifdef ENABLE_CLASSIC
case HCI_SCO_DATA_PACKET:
sco_handler(packet, size);
break;
#endif
default:
break;
}
@ -1947,12 +1992,14 @@ void hci_register_acl_packet_handler(btstack_packet_handler_t handler){
hci_stack->acl_packet_handler = handler;
}
#ifdef ENABLE_CLASSIC
/**
* @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
*/
void hci_register_sco_packet_handler(btstack_packet_handler_t handler){
hci_stack->sco_packet_handler = handler;
}
#endif
static void hci_state_reset(void){
// no connections yet
@ -1986,6 +2033,7 @@ static void hci_state_reset(void){
hci_stack->le_connection_parameter_range.le_supervision_timeout_max = 3200;
}
#ifdef ENABLE_CLASSIC
/**
* @brief Configure Bluetooth hardware control. Has to be called before power on.
*/
@ -1996,6 +2044,7 @@ void hci_set_link_key_db(btstack_link_key_db_t const * link_key_db){
hci_stack->link_key_db->open();
}
}
#endif
void hci_init(const hci_transport_t *transport, const void *config){
@ -2088,9 +2137,11 @@ void hci_close(void){
hci_stack = NULL;
}
#ifdef ENABLE_CLASSIC
void gap_set_class_of_device(uint32_t class_of_device){
hci_stack->class_of_device = class_of_device;
}
#endif
// Set Public BD ADDR - passed on to Bluetooth chipset if supported in bt_control_h
void hci_set_bd_addr(bd_addr_t addr){
@ -2352,6 +2403,9 @@ int hci_power_control(HCI_POWER_MODE power_mode){
return 0;
}
#ifdef ENABLE_CLASSIC
static void hci_update_scan_enable(void){
// 2 = page scan, 1 = inq scan
hci_stack->new_scan_enable_value = hci_stack->connectable << 1 | hci_stack->discoverable;
@ -2379,6 +2433,7 @@ void gap_connectable_control(uint8_t enable){
hci_stack->connectable = enable;
hci_update_scan_enable();
}
#endif
void gap_local_bd_addr(bd_addr_t address_buffer){
memcpy(address_buffer, hci_stack->local_bd_addr, 6);
@ -2409,7 +2464,8 @@ static void hci_run(void){
if (!hci_can_send_command_packet_now()) return;
// global/non-connection oriented commands
#ifdef ENABLE_CLASSIC
// decline incoming connections
if (hci_stack->decline_reason){
uint8_t reason = hci_stack->decline_reason;
@ -2424,7 +2480,8 @@ static void hci_run(void){
hci_stack->new_scan_enable_value = 0xff;
return;
}
#endif
#ifdef ENABLE_BLE
if (hci_stack->state == HCI_STATE_WORKING){
// handle le scan
@ -2564,10 +2621,12 @@ static void hci_run(void){
switch(connection->state){
case SEND_CREATE_CONNECTION:
switch(connection->address_type){
#ifdef ENABLE_CLASSIC
case BD_ADDR_TYPE_CLASSIC:
log_info("sending hci_create_connection");
hci_send_cmd(&hci_create_connection, connection->address, hci_usable_acl_packet_types(), 0, 0, 0, 1);
break;
#endif
default:
#ifdef ENABLE_BLE
log_info("sending hci_le_create_connection");
@ -2592,6 +2651,7 @@ static void hci_run(void){
}
return;
#ifdef ENABLE_CLASSIC
case RECEIVED_CONNECTION_REQUEST:
log_info("sending hci_accept_connection_request, remote eSCO %u", connection->remote_supported_feature_eSCO);
connection->state = ACCEPTED_CONNECTION_REQUEST;
@ -2600,6 +2660,7 @@ static void hci_run(void){
hci_send_cmd(&hci_accept_connection_request, connection->address, 1);
}
return;
#endif
#ifdef ENABLE_BLE
case SEND_CANCEL_CONNECTION:
@ -2616,6 +2677,7 @@ static void hci_run(void){
break;
}
#ifdef ENABLE_CLASSIC
if (connection->authentication_flags & HANDLE_LINK_KEY_REQUEST){
log_info("responding to link key request");
connectionClearAuthenticationFlags(connection, HANDLE_LINK_KEY_REQUEST);
@ -2669,6 +2731,7 @@ static void hci_run(void){
hci_send_cmd(&hci_user_passkey_request_reply, &connection->address, 000000);
return;
}
#endif
if (connection->bonding_flags & BONDING_REQUEST_REMOTE_FEATURES){
connection->bonding_flags &= ~BONDING_REQUEST_REMOTE_FEATURES;
@ -2827,10 +2890,16 @@ static void hci_run(void){
}
int hci_send_cmd_packet(uint8_t *packet, int size){
bd_addr_t addr;
hci_connection_t * conn;
// house-keeping
if (IS_COMMAND(packet, hci_write_loopback_mode)){
hci_stack->loopback_mode = packet[3];
}
#ifdef ENABLE_CLASSIC
bd_addr_t addr;
hci_connection_t * conn;
// create_connection?
if (IS_COMMAND(packet, hci_create_connection)){
reverse_bd_addr(&packet[3], addr);
@ -2862,6 +2931,7 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
}
conn->state = SENT_CREATE_CONNECTION;
}
if (IS_COMMAND(packet, hci_link_key_request_reply)){
hci_add_connection_flags_for_flipped_bd_addr(&packet[3], SENT_LINK_KEY_REPLY);
}
@ -2895,10 +2965,7 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
connectionClearAuthenticationFlags(conn, SSP_PAIRING_ACTIVE);
}
}
if (IS_COMMAND(packet, hci_write_loopback_mode)){
hci_stack->loopback_mode = packet[3];
}
#endif
#ifdef ENABLE_BLE
if (IS_COMMAND(packet, hci_le_set_advertising_parameters)){
@ -2954,6 +3021,8 @@ void hci_disconnect_security_block(hci_con_handle_t con_handle){
// Configure Secure Simple Pairing
#ifdef ENABLE_CLASSIC
// enable will enable SSP during init
void gap_ssp_set_enable(int enable){
hci_stack->ssp_enable = enable;
@ -2975,6 +3044,7 @@ void gap_ssp_set_authentication_requirement(int authentication_requirement){
void gap_ssp_set_auto_accept(int auto_accept){
hci_stack->ssp_auto_accept = auto_accept;
}
#endif
/**
* pre: numcmds >= 0 - it's allowed to send a command to the controller
@ -3024,6 +3094,7 @@ static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){
hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, 0, packet, size);
}
#ifdef ENABLE_CLASSIC
static void hci_notify_if_sco_can_send_now(void){
// notify SCO sender if waiting
if (!hci_stack->sco_waiting_for_can_send_now) return;
@ -3034,6 +3105,7 @@ static void hci_notify_if_sco_can_send_now(void){
hci_stack->sco_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
}
#endif
void hci_emit_state(void){
log_info("BTSTACK_EVENT_STATE %u", hci_stack->state);
@ -3044,6 +3116,7 @@ void hci_emit_state(void){
hci_emit_event(event, sizeof(event), 1);
}
#ifdef ENABLE_CLASSIC
static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){
uint8_t event[13];
event[0] = HCI_EVENT_CONNECTION_COMPLETE;
@ -3055,7 +3128,9 @@ static void hci_emit_connection_complete(bd_addr_t address, hci_con_handle_t con
event[12] = 0; // encryption disabled
hci_emit_event(event, sizeof(event), 1);
}
#endif
#ifdef ENABLE_BLE
static void hci_emit_le_connection_complete(uint8_t address_type, bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){
uint8_t event[21];
event[0] = HCI_EVENT_LE_META;
@ -3072,6 +3147,7 @@ static void hci_emit_le_connection_complete(uint8_t address_type, bd_addr_t addr
event[20] = 0; // master clock accuracy
hci_emit_event(event, sizeof(event), 1);
}
#endif
static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason){
uint8_t event[6];
@ -3110,15 +3186,20 @@ static void hci_emit_hci_open_failed(void){
hci_emit_event(event, sizeof(event), 1);
}
static void hci_emit_discoverable_enabled(uint8_t enabled){
log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled);
uint8_t event[3];
event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED;
event[1] = sizeof(event) - 2;
event[2] = enabled;
static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status){
log_info("hci_emit_dedicated_bonding_result %u ", status);
uint8_t event[9];
int pos = 0;
event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED;
event[pos++] = sizeof(event) - 2;
event[pos++] = status;
reverse_bd_addr(address, &event[pos]);
hci_emit_event(event, sizeof(event), 1);
}
#ifdef ENABLE_CLASSIC
static void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_level_t level){
log_info("hci_emit_security_level %u for handle %x", level, con_handle);
uint8_t event[5];
@ -3131,14 +3212,18 @@ static void hci_emit_security_level(hci_con_handle_t con_handle, gap_security_le
hci_emit_event(event, sizeof(event), 1);
}
static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status){
log_info("hci_emit_dedicated_bonding_result %u ", status);
uint8_t event[9];
int pos = 0;
event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED;
event[pos++] = sizeof(event) - 2;
event[pos++] = status;
reverse_bd_addr(address, &event[pos]);
static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection){
if (!connection) return LEVEL_0;
if ((connection->authentication_flags & CONNECTION_ENCRYPTED) == 0) return LEVEL_0;
return gap_security_level_for_link_key_type(connection->link_key_type);
}
static void hci_emit_discoverable_enabled(uint8_t enabled){
log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled);
uint8_t event[3];
event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED;
event[1] = sizeof(event) - 2;
event[2] = enabled;
hci_emit_event(event, sizeof(event), 1);
}
@ -3191,13 +3276,6 @@ gap_security_level_t gap_security_level_for_link_key_type(link_key_type_t link_k
}
}
static gap_security_level_t gap_security_level_for_connection(hci_connection_t * connection){
if (!connection) return LEVEL_0;
if ((connection->authentication_flags & CONNECTION_ENCRYPTED) == 0) return LEVEL_0;
return gap_security_level_for_link_key_type(connection->link_key_type);
}
int gap_mitm_protection_required_for_security_level(gap_security_level_t level){
log_info("gap_mitm_protection_required_for_security_level %u", level);
return level > LEVEL_2;
@ -3287,11 +3365,15 @@ int gap_dedicated_bonding(bd_addr_t device, int mitm_protection_required){
return 0;
}
#endif
void gap_set_local_name(const char * local_name){
hci_stack->local_name = local_name;
}
#ifdef ENABLE_BLE
void gap_start_scan(void){
if (hci_stack->le_scanning_state == LE_SCANNING) return;
hci_stack->le_scanning_state = LE_START_SCAN;
@ -3503,6 +3585,7 @@ void gap_advertisements_enable(int enabled){
hci_run();
}
#endif
uint8_t gap_disconnect(hci_con_handle_t handle){
hci_connection_t * conn = hci_connection_for_handle(handle);
@ -3611,6 +3694,7 @@ void gap_auto_connection_stop_all(void){
#endif
#ifdef ENABLE_CLASSIC
/**
* @brief Set Extended Inquiry Response data
* @param eir_data size 240 bytes, is not copied make sure memory is accessible during stack startup
@ -3652,6 +3736,7 @@ int hci_get_sco_packet_length(void){
if (hci_stack->sco_voice_setting & 0x0020) return 51;
return 27;
}
#endif
/**
* @brief Set callback for Bluetooth Hardware Error

View File

@ -1049,11 +1049,15 @@ static void l2cap_notify_channel_can_send(void){
for (i=0;i<L2CAP_FIXED_CHANNEL_TABLE_SIZE;i++){
if (!fixed_channels[i].callback) continue;
if (!fixed_channels[i].waiting_for_can_send_now) continue;
int can_send;
int can_send = 0;
if (l2cap_fixed_channel_table_index_is_le(i)){
#ifdef ENABLE_BLE
can_send = hci_can_send_acl_le_packet_now();
#endif
} else {
#ifdef ENABLE_CLASSIC
can_send = hci_can_send_acl_classic_packet_now();
#endif
}
if (!can_send) continue;
fixed_channels[i].waiting_for_can_send_now = 0;