diff --git a/src/hfp.c b/src/hfp.c index 4d33ca07a..8e01c6347 100644 --- a/src/hfp.c +++ b/src/hfp.c @@ -623,6 +623,11 @@ static void process_command(hfp_connection_t * context){ context->command = HFP_CMD_NONE; int offset = 0; int isHandsFree = 1; + + if (strncmp((char *)context->line_buffer+offset, HFP_CALL_ANSWERED, strlen(HFP_CALL_ANSWERED)) == 0){ + context->command = HFP_CMD_CALL_ANSWERED; + return; + } if (strncmp((char *)context->line_buffer, "AT", 2) == 0){ offset = 2; @@ -745,7 +750,6 @@ static void process_command(hfp_connection_t * context){ } return; } - if (strncmp((char *)context->line_buffer+offset, "AT+", 3) == 0){ context->command = HFP_CMD_UNKNOWN; diff --git a/src/hfp.h b/src/hfp.h index dcd7f1705..8c78cb3d5 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -89,6 +89,7 @@ extern "C" { */ #define HFP_AGSF_THREE_WAY_CALLING 0 #define HFP_AGSF_EC_NR_FUNCTION 1 +#define HFP_AGSF_IN_BAND_RING_TONE 3 #define HFP_AGSF_CODEC_NEGOTIATION 9 #define HFP_AGSF_HF_INDICATORS 10 #define HFP_AGSF_ESCO 11 @@ -114,6 +115,7 @@ extern "C" { #define HFP_EXTENDED_AUDIO_GATEWAY_ERROR "+CME ERROR" #define HFP_TRIGGER_CODEC_CONNECTION_SETUP "+BCC" #define HFP_CONFIRM_COMMON_CODEC "+BCS" +#define HFP_CALL_ANSWERED "ATA" #define HFP_OK "OK" #define HFP_ERROR "ERROR" @@ -143,8 +145,8 @@ typedef enum { HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR, HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP, HFP_CMD_AG_SUGGESTED_CODEC, - HFP_CMD_HF_CONFIRMED_CODEC - + HFP_CMD_HF_CONFIRMED_CODEC, + HFP_CMD_CALL_ANSWERED } hfp_command_t; typedef enum { @@ -253,7 +255,9 @@ typedef enum { HFP_W4_SCO_CONNECTED, HFP_AUDIO_CONNECTION_ESTABLISHED, - + HFP_RING_ALERT, + HFP_CALL_ACTIVE, + HFP_W2_DISCONNECT_SCO, HFP_W4_SCO_DISCONNECTED, // 30 @@ -374,7 +378,9 @@ typedef struct hfp_connection { uint8_t start_call; uint8_t terminate_call; uint8_t start_ringing; - uint8_t stop_ringing; + uint8_t update_call_status; + uint8_t update_callsetup_status; + } hfp_connection_t; // UTILS_START : TODO move to utils diff --git a/src/hfp_ag.c b/src/hfp_ag.c index b93192d63..17ca69ff9 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -684,6 +684,42 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){ done = 1; return done; } + if (context->start_ringing){ + context->start_ringing = 0; + context->state = HFP_RING_ALERT; + hfp_emit_event(hfp_callback, HFP_SUBEVENT_START_RINGINIG, 0); + } + break; + + case HFP_RING_ALERT: + // check if ATA + if (context->command == HFP_CMD_CALL_ANSWERED){ + context->state = HFP_CALL_ACTIVE; + context->update_call_status = 1; + hfp_emit_event(hfp_callback, HFP_SUBEVENT_STOP_RINGINIG, 0); + hfp_ag_ok(context->rfcomm_cid); + done = 1; + return done; + } + break; + case HFP_CALL_ACTIVE: + if (context->update_call_status){ + context->update_call_status = 0; + context->update_callsetup_status = 1; + hfp_ag_indicator_t * indicator = get_ag_indicator_for_name(context, "call"); + indicator->status = HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT; + hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, indicator); + done = 1; + return done; + } + if (context->update_callsetup_status){ + context->update_callsetup_status = 0; + hfp_ag_indicator_t * indicator = get_ag_indicator_for_name(context, "callsetup"); + indicator->status = HFP_HELDCALL_STATUS_NO_CALLS_HELD; + hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, indicator); + done = 1; + return done; + } break; default: break; @@ -714,16 +750,6 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){ return done; } - if (context->start_ringing){ - context->start_ringing = 0; - hfp_emit_event(hfp_callback, HFP_SUBEVENT_START_RINGINIG, 0); - } - - if (context->stop_ringing){ - context->stop_ringing = 0; - hfp_emit_event(hfp_callback, HFP_SUBEVENT_STOP_RINGINIG, 0); - } - return done; } @@ -936,6 +962,7 @@ void hfp_ag_call(bd_addr_t bd_addr){ hfp_run_for_context(connection); } + /** * @brief */ diff --git a/src/hfp_ag.h b/src/hfp_ag.h index eb8231baa..003b5ba8d 100644 --- a/src/hfp_ag.h +++ b/src/hfp_ag.h @@ -167,6 +167,7 @@ void hfp_ag_release_audio_connection(bd_addr_t bd_addr); */ void hfp_ag_call(bd_addr_t bd_addr); + /** * @brief */ diff --git a/test/hfp/Makefile b/test/hfp/Makefile index 5609d6696..83e729edd 100644 --- a/test/hfp/Makefile +++ b/test/hfp/Makefile @@ -43,8 +43,8 @@ COMMON_OBJ = $(COMMON:.c=.o) MOCK_OBJ = $(MOCK:.c=.o) # CC = gcc-fsf-4.9 -CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -# CFLAGS += -Werror +CFLAGS = -g -Wall -Wmissing-prototype -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include +CFLAGS += -Werror VPATH += ${BTSTACK_ROOT}/src VPATH += ${BTSTACK_ROOT}/ble diff --git a/test/hfp/hfp_ag_client_test.c b/test/hfp/hfp_ag_client_test.c index bedfdcdbd..7e4da399b 100644 --- a/test/hfp/hfp_ag_client_test.c +++ b/test/hfp/hfp_ag_client_test.c @@ -98,7 +98,7 @@ 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; int expected_rfcomm_command(const char * expected_cmd){ char * ag_cmd = (char *)get_rfcomm_payload(); @@ -171,6 +171,7 @@ void packet_handler(uint8_t * event, uint16_t event_size){ break; case HFP_SUBEVENT_STOP_RINGINIG: printf("\n** Stop ringing **\n\n"); + stop_ringing = 1; start_ringing = 0; break; default: @@ -221,7 +222,7 @@ TEST(HFPClient, HFAnswerIncomingCallWithInBandRingTone){ CHECK_EQUAL(audio_connection_established, 1); simulate_test_sequence(alert_ic_setup(), alert_ic_setup_size()); - CHECK_EQUAL(start_ringing, 1); + CHECK_EQUAL(stop_ringing, 1); } diff --git a/test/hfp/test_sequences.c b/test/hfp/test_sequences.c index 0a84087f5..4cf4cd033 100644 --- a/test/hfp/test_sequences.c +++ b/test/hfp/test_sequences.c @@ -155,23 +155,12 @@ const char * ic_test1[] = { const char * ic_alert_test1[] = { "NOP", - // //"RING", - // "NOP", - // "+CLIP:\"1234\",128", - // "NOP", - // "InBandRingTone", - // "NOP", - // "RING", - // "NOP", - // "+CLIP:\"1234\",128", // 128-143, 144-159, 160-175 - // "NOP", - // "InBandRingTone", - // "ATA", - // "OK", - // "NOP", - // "+CIEV:2,1", // call = 1 - // "NOP", - // "+CIEV:3,0" + "ATA", + "OK", + "NOP", + "+CIEV:2,1", // call = 1 + "NOP", + "+CIEV:3,0" }; hfp_test_item_t ic_tests[] = {