mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-23 10:21:12 +00:00
hci_transport: add set_sco_config and call when nr. of SCO connections changes
This commit is contained in:
parent
d402ff8276
commit
ee752bb8db
@ -1205,6 +1205,10 @@ static int usb_send_packet(uint8_t packet_type, uint8_t * packet, int size){
|
||||
}
|
||||
}
|
||||
|
||||
static void usb_set_sco_config(uint16_t voice_setting, int num_connections){
|
||||
log_info("usb_set_sco_config: voice settings 0x04%x, num connections %u", voice_setting, num_connections);
|
||||
}
|
||||
|
||||
static void usb_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
|
||||
log_info("registering packet handler");
|
||||
packet_handler = handler;
|
||||
@ -1227,6 +1231,7 @@ const hci_transport_t * hci_transport_usb_instance(void) {
|
||||
hci_transport_usb->register_packet_handler = usb_register_packet_handler;
|
||||
hci_transport_usb->can_send_packet_now = usb_can_send_packet_now;
|
||||
hci_transport_usb->send_packet = usb_send_packet;
|
||||
hci_transport_usb->set_sco_config = usb_set_sco_config;
|
||||
}
|
||||
return hci_transport_usb;
|
||||
}
|
||||
|
@ -1292,6 +1292,7 @@ static const hci_transport_t hci_transport_usb = {
|
||||
/* int (*send_packet)(...); */ &usb_send_packet,
|
||||
/* int (*set_baudrate)(uint32_t baudrate); */ NULL,
|
||||
/* void (*reset_link)(void); */ NULL,
|
||||
/* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL,
|
||||
};
|
||||
|
||||
const hci_transport_t * hci_transport_usb_instance(void) {
|
||||
|
43
src/hci.c
43
src/hci.c
@ -219,6 +219,20 @@ hci_connection_t * hci_connection_for_bd_addr_and_type(bd_addr_t addr, bd_addr_
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
|
||||
#ifdef ENABLE_SCO_OVER_HCI
|
||||
static int hci_number_sco_connections(void){
|
||||
int connections = 0;
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &hci_stack->connections);
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
hci_connection_t * connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
|
||||
if (connection->address_type != BD_ADDR_TYPE_SCO) continue;
|
||||
connections++;
|
||||
}
|
||||
return connections;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hci_connection_timeout_handler(btstack_timer_source_t *timer){
|
||||
hci_connection_t * connection = (hci_connection_t *) btstack_run_loop_get_timer_context(timer);
|
||||
#ifdef HAVE_EMBEDDED_TICK
|
||||
@ -749,6 +763,10 @@ static void acl_handler(uint8_t *packet, int size){
|
||||
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_SCO_OVER_HCI
|
||||
int addr_type = conn->address_type;
|
||||
#endif
|
||||
|
||||
btstack_run_loop_remove_timer(&conn->timeout);
|
||||
|
||||
btstack_linked_list_remove(&hci_stack->connections, (btstack_linked_item_t *) conn);
|
||||
@ -756,6 +774,11 @@ static void hci_shutdown_connection(hci_connection_t *conn){
|
||||
|
||||
// now it's gone
|
||||
hci_emit_nr_connections_changed();
|
||||
|
||||
// update SCO
|
||||
if (addr_type == BD_ADDR_TYPE_SCO && hci_stack->hci_transport && hci_stack->hci_transport->set_sco_config){
|
||||
hci_stack->hci_transport->set_sco_config(hci_stack->sco_voice_setting_active, hci_number_sco_connections());
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
@ -1737,6 +1760,13 @@ static void event_handler(uint8_t *packet, int size){
|
||||
}
|
||||
conn->state = OPEN;
|
||||
conn->con_handle = little_endian_read_16(packet, 3);
|
||||
|
||||
#ifdef ENABLE_SCO_OVER_HCI
|
||||
// update SCO
|
||||
if (conn->address_type == BD_ADDR_TYPE_SCO && hci_stack->hci_transport && hci_stack->hci_transport->set_sco_config){
|
||||
hci_stack->hci_transport->set_sco_config(hci_stack->sco_voice_setting_active, hci_number_sco_connections());
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
|
||||
@ -3087,6 +3117,19 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
|
||||
connectionClearAuthenticationFlags(conn, SSP_PAIRING_ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SCO_OVER_HCI
|
||||
// setup_synchronous_connection? Voice setting at offset 22
|
||||
if (IS_COMMAND(packet, hci_setup_synchronous_connection)){
|
||||
// TODO: compare to current setting if sco connection already active
|
||||
hci_stack->sco_voice_setting_active = little_endian_read_16(packet, 15);
|
||||
}
|
||||
// accept_synchronus_connection? Voice setting at offset 18
|
||||
if (IS_COMMAND(packet, hci_accept_synchronous_connection)){
|
||||
// TODO: compare to current setting if sco connection already active
|
||||
hci_stack->sco_voice_setting_active = little_endian_read_16(packet, 19);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_BLE
|
||||
|
@ -698,6 +698,7 @@ typedef struct {
|
||||
uint8_t new_scan_enable_value;
|
||||
|
||||
uint16_t sco_voice_setting;
|
||||
uint16_t sco_voice_setting_active;
|
||||
|
||||
uint8_t loopback_mode;
|
||||
|
||||
|
@ -104,6 +104,11 @@ typedef struct {
|
||||
*/
|
||||
void (*reset_link)(void);
|
||||
|
||||
/**
|
||||
* extension for USB transport implementations: config SCO connections
|
||||
*/
|
||||
void (*set_sco_config)(uint16_t voice_setting, int num_connections);
|
||||
|
||||
} hci_transport_t;
|
||||
|
||||
typedef enum {
|
||||
|
@ -549,6 +549,7 @@ static const hci_transport_t hci_transport_h4 = {
|
||||
/* int (*send_packet)(...); */ &hci_transport_h4_send_packet,
|
||||
/* int (*set_baudrate)(uint32_t baudrate); */ &hci_transport_h4_set_baudrate,
|
||||
/* void (*reset_link)(void); */ NULL,
|
||||
/* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL,
|
||||
};
|
||||
|
||||
// configure and return h4 singleton
|
||||
|
@ -773,6 +773,7 @@ static const hci_transport_t hci_transport_h5 = {
|
||||
/* int (*send_packet)(...); */ &hci_transport_h5_send_packet,
|
||||
/* int (*set_baudrate)(uint32_t baudrate); */ &hci_transport_h5_set_baudrate,
|
||||
/* void (*reset_link)(void); */ &hci_transport_h5_reset_link,
|
||||
/* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL,
|
||||
};
|
||||
|
||||
// configure and return h5 singleton
|
||||
|
Loading…
x
Reference in New Issue
Block a user