hci: add hci_set_sco_transport, call sco_transport->open() on sco connection complete

This commit is contained in:
Matthias Ringwald 2021-02-15 16:37:32 +01:00
parent aac273849f
commit cb70c5ab8f
2 changed files with 41 additions and 4 deletions

View File

@ -954,8 +954,11 @@ static void hci_shutdown_connection(hci_connection_t *conn){
log_info("Connection closed: handle 0x%x, %s", conn->con_handle, bd_addr_to_str(conn->address));
#ifdef ENABLE_CLASSIC
#ifdef ENABLE_SCO_OVER_HCI
int addr_type = conn->address_type;
#if defined(ENABLE_SCO_OVER_HCI) || defined(HAVE_SCO_TRANSPORT)
bd_addr_type_t addr_type = conn->address_type;
#endif
#ifdef HAVE_SCO_TRANSPORT
hci_con_handle_t con_handle = conn->con_handle;
#endif
#endif
@ -970,10 +973,15 @@ static void hci_shutdown_connection(hci_connection_t *conn){
#ifdef ENABLE_CLASSIC
#ifdef ENABLE_SCO_OVER_HCI
// update SCO
if (addr_type == BD_ADDR_TYPE_SCO && hci_stack->hci_transport && hci_stack->hci_transport->set_sco_config){
if ((addr_type == BD_ADDR_TYPE_SCO) && (hci_stack->hci_transport != NULL) && (hci_stack->hci_transport->set_sco_config != NULL)){
hci_stack->hci_transport->set_sco_config(hci_stack->sco_voice_setting_active, hci_number_sco_connections());
}
#endif
#ifdef HAVE_SCO_TRANSPORT
if ((addr_type == BD_ADDR_TYPE_SCO) && (hci_stack->sco_transport != NULL)){
hci_stack->sco_transport->close(con_handle);
}
#endif
#endif
}
@ -2504,6 +2512,13 @@ static void event_handler(uint8_t *packet, uint16_t size){
if (hci_have_usb_transport()){
hci_stack->sco_can_send_now = 1;
}
#endif
#ifdef HAVE_SCO_TRANSPORT
// configure sco transport
if (hci_stack->sco_transport != NULL){
sco_format_t sco_format = ((hci_stack->sco_voice_setting_active & 0x03) == 0x03) ? SCO_FORMAT_8_BIT : SCO_FORMAT_16_BIT;
hci_stack->sco_transport->open(conn->con_handle, sco_format);
}
#endif
break;
@ -3249,6 +3264,13 @@ void hci_close(void){
hci_stack = NULL;
}
#ifdef HAVE_SCO_TRANSPORT
void hci_set_sco_transport(const btstack_sco_transport_t *sco_transport){
hci_stack->sco_transport = sco_transport;
sco_transport->register_packet_handler(&packet_handler);
}
#endif
#ifdef ENABLE_CLASSIC
void gap_set_required_encryption_key_size(uint8_t encryption_key_size){
// validate ranage and set

View File

@ -61,6 +61,10 @@
#include "ble/att_db.h"
#endif
#ifdef HAVE_SCO_TRANSPORT
#include "btstack_sco_transport.h"
#endif
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
@ -1000,6 +1004,10 @@ typedef struct {
#ifdef ENABLE_CLASSIC_PAIRING_OOB
bool classic_read_local_oob_data;
#endif
#ifdef HAVE_SCO_TRANSPORT
const btstack_sco_transport_t * sco_transport;
#endif
} hci_stack_t;
@ -1021,9 +1029,16 @@ void hci_set_chipset(const btstack_chipset_t *chipset_driver);
/**
* @brief Configure Bluetooth hardware control. Has to be called before power on.
* @[aram hardware_control implementation
*/
void hci_set_control(const btstack_control_t *hardware_control);
/**
* @brief Set SCO Transport implementation for SCO over PCM mode
* @param sco_transport that sends SCO over I2S or PCM interface
*/
void hci_set_sco_transport(const btstack_sco_transport_t *sco_transport);
/**
* @brief Configure Bluetooth hardware control. Has to be called before power on.
*/
@ -1039,7 +1054,7 @@ void hci_set_hardware_error_callback(void (*fn)(uint8_t error));
*/
void hci_set_bd_addr(bd_addr_t addr);
/**
/**
* @brief Configure Voice Setting for use with SCO data in HSP/HFP
*/
void hci_set_sco_voice_setting(uint16_t voice_setting);