diff --git a/src/hci.c b/src/hci.c index b19dcda48..01075b44c 100644 --- a/src/hci.c +++ b/src/hci.c @@ -558,23 +558,27 @@ int hci_send_sco_packet_buffer(int size){ } uint8_t * packet = hci_stack->hci_packet_buffer; - hci_con_handle_t con_handle = READ_ACL_CONNECTION_HANDLE(packet); // same for ACL and SCO - // check for free places on Bluetooth module - if (!hci_can_send_prepared_sco_packet_now(con_handle)) { - log_error("hci_send_sco_packet_buffer called but no free ACL buffers on controller"); - hci_release_packet_buffer(); - return BTSTACK_ACL_BUFFERS_FULL; - } + // skip checks in loopback mode + if (!hci_stack->loopback_mode){ + hci_con_handle_t con_handle = READ_ACL_CONNECTION_HANDLE(packet); // same for ACL and SCO - // track send packet in connection struct - hci_connection_t *connection = hci_connection_for_handle( con_handle); - if (!connection) { - log_error("hci_send_sco_packet_buffer called but no connection for handle 0x%04x", con_handle); - hci_release_packet_buffer(); - return 0; + // check for free places on Bluetooth module + if (!hci_can_send_prepared_sco_packet_now(con_handle)) { + log_error("hci_send_sco_packet_buffer called but no free ACL buffers on controller"); + hci_release_packet_buffer(); + return BTSTACK_ACL_BUFFERS_FULL; + } + + // track send packet in connection struct + hci_connection_t *connection = hci_connection_for_handle( con_handle); + if (!connection) { + log_error("hci_send_sco_packet_buffer called but no connection for handle 0x%04x", con_handle); + hci_release_packet_buffer(); + return 0; + } + connection->num_sco_packets_sent++; } - connection->num_sco_packets_sent++; hci_dump_packet( HCI_SCO_DATA_PACKET, 0, packet, size); return hci_stack->hci_transport->send_packet(HCI_SCO_DATA_PACKET, packet, size); @@ -2610,6 +2614,10 @@ int hci_send_cmd_packet(uint8_t *packet, int size){ } } + if (IS_COMMAND(packet, hci_write_loopback_mode)){ + hci_stack->loopback_mode = packet[3]; + } + #ifdef HAVE_BLE if (IS_COMMAND(packet, hci_le_set_advertising_parameters)){ hci_stack->adv_addr_type = packet[8]; diff --git a/src/hci.h b/src/hci.h index 1b17d42c9..69b1a1276 100644 --- a/src/hci.h +++ b/src/hci.h @@ -131,6 +131,7 @@ extern "C" { #define OGF_CONTROLLER_BASEBAND 0x03 #define OGF_INFORMATIONAL_PARAMETERS 0x04 #define OGF_STATUS_PARAMETERS 0x05 +#define OGF_TESTING 0x06 #define OGF_LE_CONTROLLER 0x08 #define OGF_BTSTACK 0x3d #define OGF_VENDOR 0x3f @@ -720,6 +721,8 @@ typedef struct { uint16_t sco_voice_setting; + uint8_t loopback_mode; + // buffer for single connection decline uint8_t decline_reason; bd_addr_t decline_addr;