HFP: Emit codec event after SCO connection is established, CODECS event is deleted, codec added as param in AUDIO_CONN event

This commit is contained in:
Milanka Ringwald 2016-09-19 15:53:35 +02:00
parent 249f614da0
commit d0c4aea60c
9 changed files with 40 additions and 70 deletions

View File

@ -630,11 +630,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
printf("Service level connection released.\n");
sco_handle = 0;
break;
case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE:
negotiated_codec = hfp_subevent_codecs_connection_complete_get_negotiated_codec(event);
printf("Codec connection established with codec 0x%02x.\n", negotiated_codec);
sco_demo_set_codec(negotiated_codec);
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));
@ -642,6 +637,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
} else {
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event);
printf("Using codec 0x%02x.\n", negotiated_codec);
sco_demo_set_codec(negotiated_codec);
hci_request_sco_can_send_now_event();
}
break;

View File

@ -481,11 +481,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
printf("Service level connection released.\n\n");
break;
case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE:
negotiated_codec = hfp_subevent_codecs_connection_complete_get_negotiated_codec(event);
printf("Codec connection established with codec 0x%02x.\n", negotiated_codec);
sco_demo_set_codec(negotiated_codec);
break;
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
if (hfp_subevent_audio_connection_established_get_status(event)){
sco_handle = 0;
@ -493,6 +488,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
} else {
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
negotiated_codec = hfp_subevent_audio_connection_established_get_negotiated_codec(event);
printf("Using codec 0x%02x.\n", negotiated_codec);
sco_demo_set_codec(negotiated_codec);
hci_request_sco_can_send_now_event();
}
break;

View File

@ -931,11 +931,12 @@ typedef uint8_t sm_key_t[16];
#define HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED 0x02
/**
* @format 11HB1
* @format 11HB11
* @param subevent_code
* @param status 0 == OK
* @param handle
* @param bd_addr
* @param negotiated_codec
*/
#define HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED 0x03
@ -977,14 +978,6 @@ typedef uint8_t sm_key_t[16];
*/
#define HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR 0x08
/**
* @format 111
* @param subevent_code
* @param status
* @param negotiated_codec
*/
#define HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE 0x09
/**
* @format 1
* @param subevent_code

View File

@ -2777,6 +2777,15 @@ static inline hci_con_handle_t hfp_subevent_audio_connection_established_get_han
static inline void hfp_subevent_audio_connection_established_get_bd_addr(const uint8_t * event, bd_addr_t bd_addr){
reverse_bd_addr(&event[6], bd_addr);
}
/**
* @brief Get field negotiated_codec from event HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED
* @param event packet
* @return negotiated_codec
* @note: btstack_type 1
*/
static inline uint8_t hfp_subevent_audio_connection_established_get_negotiated_codec(const uint8_t * event){
return event[12];
}
/**
@ -2855,25 +2864,6 @@ static inline uint8_t hfp_subevent_extended_audio_gateway_error_get_error(const
return event[3];
}
/**
* @brief Get field status from event HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE
* @param event packet
* @return status
* @note: btstack_type 1
*/
static inline uint8_t hfp_subevent_codecs_connection_complete_get_status(const uint8_t * event){
return event[3];
}
/**
* @brief Get field negotiated_codec from event HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE
* @param event packet
* @return negotiated_codec
* @note: btstack_type 1
*/
static inline uint8_t hfp_subevent_codecs_connection_complete_get_negotiated_codec(const uint8_t * event){
return event[4];
}

View File

@ -208,17 +208,6 @@ void hfp_emit_simple_event(btstack_packet_handler_t callback, uint8_t event_subt
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void hfp_emit_codec_event(btstack_packet_handler_t callback, uint8_t status, uint8_t codec){
if (!callback) return;
uint8_t event[5];
event[0] = HCI_EVENT_HFP_META;
event[1] = sizeof(event) - 2;
event[2] = HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE;
event[3] = status; // status 0 == OK
event[4] = codec;
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void hfp_emit_event(btstack_packet_handler_t callback, uint8_t event_subtype, uint8_t value){
if (!callback) return;
uint8_t event[4];
@ -229,13 +218,13 @@ void hfp_emit_event(btstack_packet_handler_t callback, uint8_t event_subtype, ui
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void hfp_emit_connection_event(btstack_packet_handler_t callback, uint8_t event_subtype, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr){
void hfp_emit_slc_connection_event(btstack_packet_handler_t callback, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr){
if (!callback) return;
uint8_t event[12];
int pos = 0;
event[pos++] = HCI_EVENT_HFP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = event_subtype;
event[pos++] = HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
event[pos++] = status; // status 0 == OK
little_endian_store_16(event, pos, con_handle);
pos += 2;
@ -244,6 +233,22 @@ void hfp_emit_connection_event(btstack_packet_handler_t callback, uint8_t event_
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void hfp_emit_sco_event(btstack_packet_handler_t callback, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr, uint8_t negotiated_codec){
if (!callback) return;
uint8_t event[13];
int pos = 0;
event[pos++] = HCI_EVENT_HFP_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED;
event[pos++] = status; // status 0 == OK
little_endian_store_16(event, pos, con_handle);
pos += 2;
reverse_bd_addr(addr,&event[pos]);
pos += 6;
event[pos++] = negotiated_codec;
(*callback)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
void hfp_emit_string_event(btstack_packet_handler_t callback, uint8_t event_subtype, const char * value){
if (!callback) return;
uint8_t event[40];
@ -567,7 +572,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
if (!hfp_connection || hfp_connection->state != HFP_W4_RFCOMM_CONNECTED) return;
if (status) {
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, status, rfcomm_event_channel_opened_get_con_handle(packet), event_addr);
hfp_emit_slc_connection_event(hfp_callback, status, rfcomm_event_channel_opened_get_con_handle(packet), event_addr);
remove_hfp_connection_context(hfp_connection);
} else {
hfp_connection->acl_handle = rfcomm_event_channel_opened_get_con_handle(packet);
@ -657,7 +662,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
hfp_connection->sco_handle = sco_handle;
hfp_connection->establish_audio_connection = 0;
hfp_connection->state = HFP_AUDIO_CONNECTION_ESTABLISHED;
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED, packet[2], sco_handle, event_addr);
hfp_emit_sco_event(hfp_callback, packet[2], sco_handle, event_addr, hfp_connection->negotiated_codec);
break;
}

View File

@ -638,8 +638,7 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
void hfp_emit_event(btstack_packet_handler_t callback, uint8_t event_subtype, uint8_t value);
void hfp_emit_simple_event(btstack_packet_handler_t callback, uint8_t event_subtype);
void hfp_emit_string_event(btstack_packet_handler_t callback, uint8_t event_subtype, const char * value);
void hfp_emit_connection_event(btstack_packet_handler_t callback, uint8_t event_subtype, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr);
void hfp_emit_codec_event(btstack_packet_handler_t callback, uint8_t status, uint8_t codec);
void hfp_emit_slc_connection_event(btstack_packet_handler_t callback, uint8_t status, hci_con_handle_t con_handle, bd_addr_t addr);
hfp_connection_t * get_hfp_connection_context_for_rfcomm_cid(uint16_t cid);
hfp_connection_t * get_hfp_connection_context_for_bd_addr(bd_addr_t bd_addr);

View File

@ -620,7 +620,6 @@ static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
hfp_connection->negotiated_codec = hfp_connection->codec_confirmed;
hfp_connection->codecs_state = HFP_CODECS_EXCHANGED;
log_info("hfp: codec confirmed: %s", hfp_connection->negotiated_codec == HFP_CODEC_MSBC ? "mSBC" : "CVSD");
hfp_emit_codec_event(hfp_callback, 0, hfp_connection->negotiated_codec);
hfp_ag_ok(hfp_connection->rfcomm_cid);
// now, pick link settings
hfp_init_link_settings(hfp_connection);
@ -633,7 +632,7 @@ static int codecs_exchange_state_machine(hfp_connection_t * hfp_connection){
static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){
hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0, hfp_connection->acl_handle, hfp_connection->remote_addr);
hfp_emit_slc_connection_event(hfp_callback, 0, hfp_connection->acl_handle, hfp_connection->remote_addr);
// if active call exist, set per-hfp_connection state active, too (when audio is on)
if (hfp_gsm_call_status() == HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT){
@ -2119,7 +2118,6 @@ static void hfp_ag_setup_audio_connection(hfp_connection_t * hfp_connection){
log_info("hfp_ag_establish_audio_connection - no codec negotiation feature, using CVSD");
hfp_connection->negotiated_codec = HFP_CODEC_CVSD;
hfp_connection->codecs_state = HFP_CODECS_EXCHANGED;
hfp_emit_codec_event(hfp_callback, 0, hfp_connection->negotiated_codec);
// now, pick link settings
hfp_init_link_settings(hfp_connection);
}

View File

@ -589,7 +589,6 @@ static void hfp_run_for_context(hfp_connection_t * hfp_connection){
// notify about codec selection if not done already
if (hfp_connection->negotiated_codec == 0){
hfp_connection->negotiated_codec = HFP_CODEC_CVSD;
hfp_emit_codec_event(hfp_callback, 0, hfp_connection->negotiated_codec);
}
// remote supported feature eSCO is set if link type is eSCO
@ -858,7 +857,7 @@ static void hfp_run_for_context(hfp_connection_t * hfp_connection){
static void hfp_ag_slc_established(hfp_connection_t * hfp_connection){
hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
hfp_emit_connection_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0, hfp_connection->acl_handle, hfp_connection->remote_addr);
hfp_emit_slc_connection_event(hfp_callback, 0, hfp_connection->acl_handle, hfp_connection->remote_addr);
// restore volume settings
hfp_connection->speaker_gain = hfp_hf_speaker_gain;
@ -968,7 +967,6 @@ static void hfp_hf_switch_on_ok(hfp_connection_t *hfp_connection){
hfp_connection->codecs_state = HFP_CODECS_EXCHANGED;
hfp_connection->negotiated_codec = hfp_connection->suggested_codec;
log_info("hfp: codec confirmed: %s", hfp_connection->negotiated_codec == HFP_CODEC_MSBC ? "mSBC" : "CVSD");
hfp_emit_codec_event(hfp_callback, 0, hfp_connection->negotiated_codec);
break;
default:
break;

View File

@ -74,7 +74,6 @@ static uint8_t codecs[2] = {1,2};
static uint16_t indicators[1] = {0x01};
static uint8_t service_level_connection_established = 0;
static uint8_t codecs_connection_established = 0;
static uint8_t audio_connection_established = 0;
static uint8_t start_ringing = 0;
static uint8_t stop_ringing = 0;
@ -400,12 +399,6 @@ void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint
printf("\n** SLC established **\n\n");
acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
service_level_connection_established = 1;
codecs_connection_established = 0;
audio_connection_established = 0;
break;
case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE:
printf("\n** CC established **\n\n");
codecs_connection_established = 1;
audio_connection_established = 0;
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
@ -468,7 +461,6 @@ TEST_GROUP(HFPClient){
void setup(void){
service_level_connection_established = 0;
codecs_connection_established = 0;
audio_connection_established = 0;
start_ringing = 0;
stop_ringing = 0;
@ -486,7 +478,6 @@ TEST_GROUP(HFPClient){
hfp_hf_release_service_level_connection(acl_handle);
service_level_connection_established = 0;
codecs_connection_established = 0;
audio_connection_established = 0;
}
};