From ffce16f9b0c4b9a0e9fae98b7e4664b8e6aea883 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sat, 21 Nov 2015 22:08:49 +0100 Subject: [PATCH] hfp: allow to simulate call answered on remote side --- src/hfp.h | 4 +++- src/hfp_ag.c | 38 ++++++++++++++++++++++++++++++++++++-- test/pts/hfp_ag_test.c | 6 ++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index 236324f18..362c2f948 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -306,7 +306,9 @@ typedef enum { HFP_CALL_W4_AUDIO_CONNECTION_FOR_IN_BAND_RING, HFP_CALL_RINGING, HFP_CALL_W4_AUDIO_CONNECTION_FOR_ACTIVE, - HFP_CALL_ACTIVE + HFP_CALL_ACTIVE, + HFP_CALL_OUTGOING_DIALING, + HFP_CALL_OUTGOING_RINGING } hfp_call_state_t; typedef enum{ diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 23f082ab0..afdd768f5 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -741,7 +741,6 @@ static void hfp_ag_transfer_callsetup_state(void){ } } -#if 0 static void hfp_ag_transfer_call_state(void){ int indicator_index = get_ag_indicator_index_for_name("call"); if (indicator_index < 0) return; @@ -755,7 +754,6 @@ static void hfp_ag_transfer_call_state(void){ hfp_run_for_context(connection); } } -#endif static void hfp_ag_hf_accept_call(hfp_connection_t * source){ @@ -867,6 +865,16 @@ static void hfp_ag_set_call_state(hfp_call_status_t state){ indicator->status = state; } +static hfp_connection_t * hfp_ag_connection_for_call_state(hfp_call_state_t call_state){ + linked_list_iterator_t it; + linked_list_iterator_init(&it, hfp_get_connections()); + while (linked_list_iterator_has_next(&it)){ + hfp_connection_t * connection = (hfp_connection_t *)linked_list_iterator_next(&it); + if (connection->call_state == call_state) return connection; + } + return NULL; +} + // connection is used to identify originating HF static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connection){ switch (event){ @@ -988,14 +996,40 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect } break; case HFP_AG_OUTGOING_CALL_INITIATED: + connection->call_state = HFP_CALL_OUTGOING_DIALING; hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE); hfp_ag_transfer_callsetup_state(); break; case HFP_AG_OUTGOING_CALL_RINGING: + connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_DIALING); + if (!connection){ + log_info("hfp_ag_call_sm: did not find outgoing connection in dialing state"); + break; + } + connection->call_state = HFP_CALL_OUTGOING_RINGING; hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE); hfp_ag_transfer_callsetup_state(); break; case HFP_AG_OUTGOING_CALL_ESTABLISHED: + switch (hfp_ag_call_state){ + case HFP_CALL_STATUS_NO_HELD_OR_ACTIVE_CALLS: + connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_RINGING); + if (!connection){ + connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_DIALING); + } + if (!connection){ + log_info("hfp_ag_call_sm: did not find outgoing connection"); + break; + } + connection->call_state = HFP_CALL_ACTIVE; + hfp_ag_set_callsetup_state(HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS); + hfp_ag_set_call_state(HFP_CALL_STATUS_ACTIVE_OR_HELD_CALL_IS_PRESENT); + hfp_ag_transfer_call_state(); + hfp_ag_transfer_callsetup_state(); + break; + default: + break; + } break; default: break; diff --git a/test/pts/hfp_ag_test.c b/test/pts/hfp_ag_test.c index 8ae282593..2c3e85670 100644 --- a/test/pts/hfp_ag_test.c +++ b/test/pts/hfp_ag_test.c @@ -138,6 +138,8 @@ static void show_usage(void){ printf("i - Set battery level to 3\n"); printf("I - Set battery level to 5\n"); + + printf("j - Answering call on remote side\n"); printf("t - terminate connection\n"); @@ -227,6 +229,10 @@ static int stdin_process(struct data_source *ds){ printf("Set battery level to 5\n"); hfp_ag_set_battery_level(5); break; + case 'j': + printf("Answering call on remote side\n"); + hfp_ag_outgoing_call_established(); + break; case 'r': printf("Disable in-band ring tone\n"); hfp_ag_set_use_in_band_ring_tone(0);