From 63cfbc853b958600e3b251610edae2af9f4b0339 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sat, 21 Nov 2015 22:48:52 +0100 Subject: [PATCH] hfp: test memory dialing --- src/hfp.h | 3 +++ src/hfp_ag.c | 36 +++++++++++++++++++++++++++++++++--- src/hfp_ag.h | 10 ++++++++++ test/pts/hfp_ag_test.c | 26 +++++++++++++++++++++++--- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index 362c2f948..4a5fa5563 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -224,6 +224,8 @@ typedef enum { HFP_AG_INCOMING_CALL_ACCEPTED_BY_HF, HFP_AG_AUDIO_CONNECTION_ESTABLISHED, HFP_AG_OUTGOING_CALL_INITIATED, + HFP_AG_OUTGOING_CALL_REJECTED, + HFP_AG_OUTGOING_CALL_ACCEPTED, HFP_AG_OUTGOING_CALL_RINGING, HFP_AG_OUTGOING_CALL_ESTABLISHED, HFP_AG_TERMINATE_CALL_BY_AG, @@ -307,6 +309,7 @@ typedef enum { HFP_CALL_RINGING, HFP_CALL_W4_AUDIO_CONNECTION_FOR_ACTIVE, HFP_CALL_ACTIVE, + HFP_CALL_OUTGOING_INITIATED, HFP_CALL_OUTGOING_DIALING, HFP_CALL_OUTGOING_RINGING } hfp_call_state_t; diff --git a/src/hfp_ag.c b/src/hfp_ag.c index afdd768f5..93ccf1f86 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -995,11 +995,36 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect break; } break; + case HFP_AG_OUTGOING_CALL_INITIATED: + connection->call_state = HFP_CALL_OUTGOING_INITIATED; + hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, (const char *) &connection->line_buffer[3]); + break; + + case HFP_AG_OUTGOING_CALL_REJECTED: + connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_INITIATED); + if (!connection){ + log_info("hfp_ag_call_sm: did not find outgoing connection in initiated state"); + break; + } + connection->call_state = HFP_CALL_IDLE; + connection->send_error = 1; + hfp_run_for_context(connection); + break; + + case HFP_AG_OUTGOING_CALL_ACCEPTED: + connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_INITIATED); + if (!connection){ + log_info("hfp_ag_call_sm: did not find outgoing connection in initiated state"); + break; + } + connection->ok_pending = 1; connection->call_state = HFP_CALL_OUTGOING_DIALING; + hfp_ag_establish_audio_connection(connection->remote_addr); 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){ @@ -1129,9 +1154,6 @@ static void hfp_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_ break; case HFP_CMD_CALL_PHONE_NUMBER: context->command = HFP_CMD_NONE; - context->ok_pending = 1; - hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, (const char *) &context->line_buffer[3]); - hfp_ag_establish_audio_connection(context->remote_addr); hfp_ag_call_sm(HFP_AG_OUTGOING_CALL_INITIATED, context); break; default: @@ -1306,6 +1328,14 @@ void hfp_ag_outgoing_call_established(void){ hfp_ag_call_sm(HFP_AG_OUTGOING_CALL_ESTABLISHED, NULL); } +void hfp_ag_outgoing_call_rejected(void){ + hfp_ag_call_sm(HFP_AG_OUTGOING_CALL_REJECTED, NULL); +} + +void hfp_ag_outgoing_call_accepted(void){ + hfp_ag_call_sm(HFP_AG_OUTGOING_CALL_ACCEPTED, NULL); +} + void hfp_ag_place_a_call_with_phone_number(void){ // linked_list_iterator_t it; // linked_list_iterator_init(&it, hfp_get_connections()); diff --git a/src/hfp_ag.h b/src/hfp_ag.h index 1e9334b8d..ead08d727 100644 --- a/src/hfp_ag.h +++ b/src/hfp_ag.h @@ -175,6 +175,16 @@ void hfp_ag_set_use_in_band_ring_tone(int use_in_band_ring_tone); */ void hfp_ag_incoming_call(void); +/** + * @brief + */ +void hfp_ag_outgoing_call_rejected(void); + +/** + * @brief + */ +void hfp_ag_outgoing_call_accepted(void); + /** * @brief */ diff --git a/test/pts/hfp_ag_test.c b/test/pts/hfp_ag_test.c index 2c3e85670..c765f4b11 100644 --- a/test/pts/hfp_ag_test.c +++ b/test/pts/hfp_ag_test.c @@ -76,6 +76,7 @@ static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF}; static bd_addr_t speaker_addr = {0x00, 0x21, 0x3C, 0xAC, 0xF7, 0x38}; static uint8_t codecs[1] = {HFP_CODEC_CVSD}; static uint16_t handle = -1; +static int memory_1_enabled = 1; static int ag_indicators_nr = 7; static hfp_ag_indicator_t ag_indicators[] = { @@ -141,6 +142,9 @@ static void show_usage(void){ printf("j - Answering call on remote side\n"); + printf("k - Clear memory #0\n"); + printf("K - Set memory #0\n"); + printf("t - terminate connection\n"); printf("---\n"); @@ -229,6 +233,14 @@ static int stdin_process(struct data_source *ds){ printf("Set battery level to 5\n"); hfp_ag_set_battery_level(5); break; + case 'k': + printf("Memory 1 cleared\n"); + memory_1_enabled = 0; + break; + case 'K': + printf("Memory 1 set\n"); + memory_1_enabled = 1; + break; case 'j': printf("Answering call on remote side\n"); hfp_ag_outgoing_call_established(); @@ -288,9 +300,17 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ break; case HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER: printf("\n** Outgoing call '%s' **\n", &event[3]); - // directly start ringing - printf("Simulate outgoing call ringing\n"); - hfp_ag_outgoing_call_ringing(); + // validate number + if ( strcmp("1234567", (char*) &event[3]) == 0 + || strcmp("7654321", (char*) &event[3]) == 0 + || (memory_1_enabled && strcmp(">1", (char*) &event[3]) == 0)){ + printf("Dialstring valid: accept call\n"); + hfp_ag_outgoing_call_accepted(); + // hfp_ag_outgoing_call_ringing(); + break; + } + printf("Dialstring invalid: reject call\n"); + hfp_ag_outgoing_call_rejected(); break; default: // printf("event not handled %u\n", event[2]);