mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-29 03:32:49 +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"
|
#include "btstack_stdin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// uncomment to temp disable mSBC codec
|
||||||
|
// #undef ENABLE_HFP_WIDE_BAND_SPEECH
|
||||||
|
|
||||||
uint8_t hfp_service_buffer[150];
|
uint8_t hfp_service_buffer[150];
|
||||||
const uint8_t rfcomm_channel_nr = 1;
|
const uint8_t rfcomm_channel_nr = 1;
|
||||||
const char hfp_ag_service_name[] = "HFP AG Demo";
|
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 uint8_t negotiated_codec = HFP_CODEC_CVSD;
|
||||||
|
|
||||||
static hci_con_handle_t acl_handle = -1;
|
static hci_con_handle_t acl_handle = HCI_CON_HANDLE_INVALID;
|
||||||
static hci_con_handle_t sco_handle;
|
static hci_con_handle_t sco_handle = HCI_CON_HANDLE_INVALID;
|
||||||
static int memory_1_enabled = 1;
|
static int memory_1_enabled = 1;
|
||||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
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;
|
break;
|
||||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
||||||
printf("Service level connection released.\n");
|
printf("Service level connection released.\n");
|
||||||
sco_handle = 0;
|
acl_handle = HCI_CON_HANDLE_INVALID;
|
||||||
break;
|
break;
|
||||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
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));
|
printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||||
sco_handle = 0;
|
|
||||||
} else {
|
} else {
|
||||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
||||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
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;
|
break;
|
||||||
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
||||||
printf("Audio connection released\n");
|
printf("Audio connection released\n");
|
||||||
sco_handle = 0;
|
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||||
sco_demo_close();
|
sco_demo_close();
|
||||||
break;
|
break;
|
||||||
case HFP_SUBEVENT_START_RINGINIG:
|
case HFP_SUBEVENT_START_RINGINIG:
|
||||||
@ -534,6 +536,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HCI_SCO_DATA_PACKET:
|
case HCI_SCO_DATA_PACKET:
|
||||||
|
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||||
sco_demo_receive(event, event_size);
|
sco_demo_receive(event, event_size);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -77,8 +77,8 @@ static bd_addr_t device_addr;
|
|||||||
// prototypes
|
// prototypes
|
||||||
static void show_usage(void);
|
static void show_usage(void);
|
||||||
#endif
|
#endif
|
||||||
static hci_con_handle_t acl_handle = -1;
|
static hci_con_handle_t acl_handle = HCI_CON_HANDLE_INVALID;
|
||||||
static hci_con_handle_t sco_handle;
|
static hci_con_handle_t sco_handle = HCI_CON_HANDLE_INVALID;
|
||||||
#ifdef ENABLE_HFP_WIDE_BAND_SPEECH
|
#ifdef ENABLE_HFP_WIDE_BAND_SPEECH
|
||||||
static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC};
|
static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC};
|
||||||
#else
|
#else
|
||||||
@ -441,6 +441,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
|||||||
switch (packet_type){
|
switch (packet_type){
|
||||||
|
|
||||||
case HCI_SCO_DATA_PACKET:
|
case HCI_SCO_DATA_PACKET:
|
||||||
|
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||||
sco_demo_receive(event, event_size);
|
sco_demo_receive(event, event_size);
|
||||||
break;
|
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));
|
printf("Service level connection established %s.\n\n", bd_addr_to_str(device_addr));
|
||||||
break;
|
break;
|
||||||
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
|
||||||
|
acl_handle = HCI_CON_HANDLE_INVALID;
|
||||||
printf("Service level connection released.\n\n");
|
printf("Service level connection released.\n\n");
|
||||||
break;
|
break;
|
||||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
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));
|
printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||||
} else {
|
} else {
|
||||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
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;
|
break;
|
||||||
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
||||||
sco_handle = 0;
|
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||||
printf("Audio connection released\n");
|
printf("Audio connection released\n");
|
||||||
sco_demo_close();
|
sco_demo_close();
|
||||||
break;
|
break;
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
static uint8_t hsp_service_buffer[150];
|
static uint8_t hsp_service_buffer[150];
|
||||||
static const uint8_t rfcomm_channel_nr = 1;
|
static const uint8_t rfcomm_channel_nr = 1;
|
||||||
static const char hsp_ag_service_name[] = "Audio Gateway Test";
|
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];
|
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){
|
switch (packet_type){
|
||||||
case HCI_SCO_DATA_PACKET:
|
case HCI_SCO_DATA_PACKET:
|
||||||
|
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||||
sco_demo_receive(event, event_size);
|
sco_demo_receive(event, event_size);
|
||||||
break;
|
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:
|
case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
|
||||||
if (hsp_subevent_audio_connection_complete_get_status(event)){
|
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));
|
printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event));
|
||||||
sco_handle = 0;
|
|
||||||
} else {
|
} else {
|
||||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
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;
|
break;
|
||||||
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
||||||
if (hsp_subevent_audio_disconnection_complete_get_status(event)){
|
printf("Audio connection released.\n\n");
|
||||||
printf("Audio connection releasing failed with status %u\n", hsp_subevent_audio_disconnection_complete_get_status(event));
|
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||||
} else {
|
|
||||||
printf("Audio connection released.\n\n");
|
|
||||||
sco_handle = 0;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED:
|
case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED:
|
||||||
printf("Received microphone gain change %d\n", hsp_subevent_microphone_gain_changed_get_gain(event));
|
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 uint8_t hsp_service_buffer[150];
|
||||||
static const uint8_t rfcomm_channel_nr = 1;
|
static const uint8_t rfcomm_channel_nr = 1;
|
||||||
static const char hsp_hs_service_name[] = "Headset Test";
|
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];
|
static char hs_cmd_buffer[100];
|
||||||
// mac 2013:
|
// mac 2013:
|
||||||
@ -189,6 +189,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
|||||||
show_usage();
|
show_usage();
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||||
|
if (READ_SCO_CONNECTION_HANDLE(event) != sco_handle) break;
|
||||||
sco_demo_send(sco_handle);
|
sco_demo_send(sco_handle);
|
||||||
break;
|
break;
|
||||||
case HCI_EVENT_HSP_META:
|
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:
|
case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
|
||||||
if (hsp_subevent_audio_connection_complete_get_status(event)){
|
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));
|
printf("Audio connection establishment failed with status %u\n", hsp_subevent_audio_connection_complete_get_status(event));
|
||||||
sco_handle = 0;
|
|
||||||
} else {
|
} else {
|
||||||
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
sco_handle = hsp_subevent_audio_connection_complete_get_handle(event);
|
||||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
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;
|
break;
|
||||||
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
case HSP_SUBEVENT_AUDIO_DISCONNECTION_COMPLETE:
|
||||||
if (hsp_subevent_audio_disconnection_complete_get_status(event)){
|
printf("Audio connection released.\n\n");
|
||||||
printf("Audio connection releasing failed with status %u\n", hsp_subevent_audio_disconnection_complete_get_status(event));
|
sco_handle = HCI_CON_HANDLE_INVALID;
|
||||||
} else {
|
|
||||||
printf("Audio connection released.\n\n");
|
|
||||||
sco_handle = 0;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED:
|
case HSP_SUBEVENT_MICROPHONE_GAIN_CHANGED:
|
||||||
printf("Received microphone gain change %d\n", hsp_subevent_microphone_gain_changed_get_gain(event));
|
printf("Received microphone gain change %d\n", hsp_subevent_microphone_gain_changed_get_gain(event));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user