From 78747ec1550cfb7e2fcc73a82f909cae01de0ddd Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 27 Nov 2015 14:08:11 +0100 Subject: [PATCH] hfp: add HF hangup call --- src/hfp.h | 1 + src/hfp_hf.c | 34 +++++++++++++++++++++++++++------- src/hfp_hf.h | 6 +++++- test/pts/hfp_hf_test.c | 5 +++++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/hfp.h b/src/hfp.h index fb76362a7..8334aded2 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -538,6 +538,7 @@ typedef struct hfp_connection { hfp_hf_query_operator_state_t hf_query_operator_state; uint8_t hf_answer_incoming_call; uint8_t hf_send_clip_enable; + uint8_t hf_send_chup; } hfp_connection_t; diff --git a/src/hfp_hf.c b/src/hfp_hf.c index 412abfcfe..17770acfa 100644 --- a/src/hfp_hf.c +++ b/src/hfp_hf.c @@ -242,6 +242,12 @@ static int hfp_hf_send_clip_enable(uint16_t cid){ return send_str_over_rfcomm(cid, buffer); } +static int hfp_hf_send_chup(uint16_t cid){ + char buffer[20]; + sprintf(buffer, "AT%s\r\n", HFP_HANG_UP_CALL); + return send_str_over_rfcomm(cid, buffer); +} + static void hfp_emit_ag_indicator_event(hfp_callback_t callback, int status, hfp_ag_indicator_t indicator){ if (!callback) return; uint8_t event[6+HFP_MAX_INDICATOR_DESC_SIZE+1]; @@ -339,13 +345,6 @@ static int hfp_hf_run_for_context_service_level_connection_queries(hfp_connectio return done; } - if (context->hf_send_clip_enable){ - context->hf_send_clip_enable = 0; - context->ok_pending = 1; - hfp_hf_send_clip_enable(context->rfcomm_cid); - return 1; - } - switch (context->hf_query_operator_state){ case HFP_HF_QUERY_OPERATOR_SET_FORMAT: context->hf_query_operator_state = HFP_HF_QUERY_OPERATOR_W4_SET_FORMAT_OK; @@ -476,6 +475,20 @@ static void hfp_run_for_context(hfp_connection_t * context){ done = call_setup_state_machine(context); } + if (context->hf_send_clip_enable){ + context->hf_send_clip_enable = 0; + context->ok_pending = 1; + hfp_hf_send_clip_enable(context->rfcomm_cid); + return; + } + + if (context->hf_send_chup){ + context->hf_send_chup = 0; + context->ok_pending = 1; + hfp_hf_send_chup(context->rfcomm_cid); + return; + } + if (done) return; // deal with disconnect switch (context->state){ @@ -834,6 +847,13 @@ void hfp_hf_answer_incoming_call(bd_addr_t bd_addr){ // } } +void hfp_hf_terminate_call(bd_addr_t bd_addr){ + hfp_hf_establish_service_level_connection(bd_addr); + hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr); + connection->hf_send_chup = 1; + hfp_run_for_context(connection); +} + void hfp_hf_enable_calling_line_identification(bd_addr_t bd_addr){ hfp_hf_establish_service_level_connection(bd_addr); hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr); diff --git a/src/hfp_hf.h b/src/hfp_hf.h index 49f0d070c..da8febfe0 100644 --- a/src/hfp_hf.h +++ b/src/hfp_hf.h @@ -84,7 +84,6 @@ void hfp_hf_register_packet_handler(hfp_callback_t callback); */ void hfp_hf_establish_service_level_connection(bd_addr_t bd_addr); - /** * @brief Release the RFCOMM channel and the audio connection between the HF and the AG. * TODO: trigger release of the audio connection @@ -155,6 +154,11 @@ void hfp_hf_release_audio_connection(bd_addr_t bd_addr); */ void hfp_hf_answer_incoming_call(bd_addr_t bd_addr); +/** + * @brief + */ +void hfp_hf_terminate_call(bd_addr_t bd_addr); + /** * @brief */ diff --git a/test/pts/hfp_hf_test.c b/test/pts/hfp_hf_test.c index 3fbd262b9..6d9781066 100644 --- a/test/pts/hfp_hf_test.c +++ b/test/pts/hfp_hf_test.c @@ -109,6 +109,7 @@ static void show_usage(void){ printf("e - disable reporting of the extended AG error result code\n"); printf("f - answer incoming call\n"); + printf("F - Hangup call\n"); printf("g - query network operator name\n"); printf("h - enable Calling Line Identification.\n"); @@ -166,6 +167,10 @@ static int stdin_process(struct data_source *ds){ printf("Answer incoming call.\n"); hfp_hf_answer_incoming_call(device_addr); break; + case 'F': + printf("Hangup call.\n"); + hfp_hf_terminate_call(device_addr); + break; case 'g': printf("Query operator.\n"); hfp_hf_query_operator_selection(device_addr);