mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-17 07:19:42 +00:00
example hfp/hsp: ignore SCO packets if connection handle doesn't match, use HCI_CON_HANDLE_INVALID
This commit is contained in:
parent
3a8dd2bf1e
commit
80b0ebb694
@ -62,6 +62,9 @@
|
||||
#include "btstack_stdin.h"
|
||||
#endif
|
||||
|
||||
// uncomment to temp disable mSBC codec
|
||||
// #undef ENABLE_HFP_WIDE_BAND_SPEECH
|
||||
|
||||
uint8_t hfp_service_buffer[150];
|
||||
const uint8_t rfcomm_channel_nr = 1;
|
||||
const char hfp_ag_service_name[] = "HFP AG Demo";
|
||||
@ -77,8 +80,8 @@ static uint8_t codecs[] = {HFP_CODEC_CVSD};
|
||||
|
||||
static uint8_t negotiated_codec = HFP_CODEC_CVSD;
|
||||
|
||||
static hci_con_handle_t acl_handle = -1;
|
||||
static hci_con_handle_t sco_handle;
|
||||
static hci_con_handle_t acl_handle = HCI_CON_HANDLE_INVALID;
|
||||
static hci_con_handle_t sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
static int memory_1_enabled = 1;
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
@ -467,12 +470,11 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
break;
|
||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
||||
printf("Service level connection released.\n");
|
||||
sco_handle = 0;
|
||||
acl_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
||||
printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||
sco_handle = 0;
|
||||
} else {
|
||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
@ -494,7 +496,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
||||
printf("Audio connection released\n");
|
||||
sco_handle = 0;
|
||||
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
sco_demo_close();
|
||||
break;
|
||||
case HFP_SUBEVENT_START_RINGINIG:
|
||||
@ -534,6 +536,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
}
|
||||
break;
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
default:
|
||||
|
@ -77,8 +77,8 @@ static bd_addr_t device_addr;
|
||||
// prototypes
|
||||
static void show_usage(void);
|
||||
#endif
|
||||
static hci_con_handle_t acl_handle = -1;
|
||||
static hci_con_handle_t sco_handle;
|
||||
static hci_con_handle_t acl_handle = HCI_CON_HANDLE_INVALID;
|
||||
static hci_con_handle_t sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
#ifdef ENABLE_HFP_WIDE_BAND_SPEECH
|
||||
static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC};
|
||||
#else
|
||||
@ -441,6 +441,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
switch (packet_type){
|
||||
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
|
||||
@ -464,11 +465,11 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
printf("Service level connection established %s.\n\n", bd_addr_to_str(device_addr));
|
||||
break;
|
||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
||||
acl_handle = HCI_CON_HANDLE_INVALID;
|
||||
printf("Service level connection released.\n\n");
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
||||
sco_handle = 0;
|
||||
printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||
} else {
|
||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
||||
@ -490,7 +491,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
}
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
||||
sco_handle = 0;
|
||||
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
printf("Audio connection released\n");
|
||||
sco_demo_close();
|
||||
break;
|
||||
|
@ -67,7 +67,7 @@
|
||||
static uint8_t hsp_service_buffer[150];
|
||||
static const uint8_t rfcomm_channel_nr = 1;
|
||||
static const char hsp_ag_service_name[] = "Audio Gateway Test";
|
||||
static uint16_t sco_handle = 0;
|
||||
static uint16_t sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
|
||||
static char hs_cmd_buffer[100];
|
||||
|
||||
@ -180,6 +180,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
|
||||
switch (packet_type){
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
|
||||
@ -218,7 +219,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
|
||||
if (hsp_subevent_audio_connection_complete_get_status(event)){
|
||||
printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event));
|
||||
sco_handle = 0;
|
||||
} else {
|
||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
@ -226,12 +226,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
||||
if (hsp_subevent_audio_disconnection_complete_get_status(event)){
|
||||
printf("Audio connection releasing failed with status %u\n", hsp_subevent_audio_disconnection_complete_get_status(event));
|
||||
} else {
|
||||
printf("Audio connection released.\n\n");
|
||||
sco_handle = 0;
|
||||
}
|
||||
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED:
|
||||
printf("Received microphone gain change %d\n", hsp_subevent_microphone_gain_changed_get_gain(event));
|
||||
|
@ -69,7 +69,7 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
static uint8_t hsp_service_buffer[150];
|
||||
static const uint8_t rfcomm_channel_nr = 1;
|
||||
static const char hsp_hs_service_name[] = "Headset Test";
|
||||
static hci_con_handle_t sco_handle = 0;
|
||||
static hci_con_handle_t sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
|
||||
static char hs_cmd_buffer[100];
|
||||
// mac 2013:
|
||||
@ -189,6 +189,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
show_usage();
|
||||
break;
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
@ -210,7 +211,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
|
||||
if (hsp_subevent_audio_connection_complete_get_status(event)){
|
||||
printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event));
|
||||
sco_handle = 0;
|
||||
} else {
|
||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
@ -218,12 +218,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
}
|
||||
break;
|
||||
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
||||
if (hsp_subevent_audio_disconnection_complete_get_status(event)){
|
||||
printf("Audio connection releasing failed with status %u\n", hsp_subevent_audio_disconnection_complete_get_status(event));
|
||||
} else {
|
||||
printf("Audio connection released.\n\n");
|
||||
sco_handle = 0;
|
||||
}
|
||||
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||
break;
|
||||
case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED:
|
||||
printf("Received microphone gain change %d\n", hsp_subevent_microphone_gain_changed_get_gain(event));
|
||||
|
Loading…
Reference in New Issue
Block a user