From 14738cc203390643f94d76303c31e110e2208abb Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Wed, 25 Nov 2015 17:11:04 +0100 Subject: [PATCH] hfp: send current call status --- include/btstack/hci_cmds.h | 2 +- src/hfp.c | 8 ++++++++ src/hfp.h | 33 ++++++++++++++++++++++++++++++++- src/hfp_ag.c | 34 +++++++++++++++++++++++++++++++++- src/hfp_ag.h | 9 +++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) diff --git a/include/btstack/hci_cmds.h b/include/btstack/hci_cmds.h index b60c50b79..4cf2a3efe 100644 --- a/include/btstack/hci_cmds.h +++ b/include/btstack/hci_cmds.h @@ -644,7 +644,7 @@ extern "C" { #define HFP_SUBEVENT_REDIAL_LAST_NUMBER 0x0E #define HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG 0x0F #define HFP_SUBEVENT_TRANSMIT_DTMF_CODES 0x10 - +#define HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL 0x11 // ANCS Client #define ANCS_CLIENT_CONNECTED 0xF0 diff --git a/src/hfp.c b/src/hfp.c index e63c73919..157e6971a 100644 --- a/src/hfp.c +++ b/src/hfp.c @@ -621,6 +621,14 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){ int offset = isHandsFree ? 0 : 2; + if (strncmp(line_buffer+offset, HFP_LIST_CURRENT_CALLS, strlen(HFP_LIST_CURRENT_CALLS)) == 0){ + return HFP_CMD_LIST_CURRENT_CALLS; + } + + if (strncmp(line_buffer+offset, HFP_SUBSCRIBER_NUMBER_INFORMATION, strlen(HFP_SUBSCRIBER_NUMBER_INFORMATION)) == 0){ + return HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION; + } + if (strncmp(line_buffer+offset, HFP_PHONE_NUMBER_FOR_VOICE_TAG, strlen(HFP_PHONE_NUMBER_FOR_VOICE_TAG)) == 0){ if (isHandsFree) return HFP_CMD_AG_SEND_PHONE_NUMBER; return HFP_CMD_HF_REQUEST_PHONE_NUMBER; diff --git a/src/hfp.h b/src/hfp.h index 9626b0d12..23071cc62 100644 --- a/src/hfp.h +++ b/src/hfp.h @@ -131,6 +131,8 @@ extern "C" { #define HFP_PHONE_NUMBER_FOR_VOICE_TAG "+BINP" #define HFP_TRANSMIT_DTMF_CODES "+VTS" #define HFP_SUBSCRIBER_NUMBER_INFORMATION "+CNUM" +#define HFP_LIST_CURRENT_CALLS "+CLCC" + #define HFP_OK "OK" #define HFP_ERROR "ERROR" @@ -186,7 +188,9 @@ typedef enum { HFP_CMD_TRANSMIT_DTMF_CODES, HFP_CMD_SET_MICROPHONE_GAIN, HFP_CMD_SET_SPEAKER_GAIN, - HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION + HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION, + HFP_CMD_LIST_CURRENT_CALLS + } hfp_command_t; @@ -343,6 +347,32 @@ typedef enum { HFP_CALL_OUTGOING_RINGING } hfp_call_state_t; +typedef enum{ + HFP_ENHANCED_CALL_DIR_OUTGOING, + HFP_ENHANCED_CALL_DIR_INCOMING +} hfp_enhanced_call_dir_t; + +typedef enum{ + HFP_ENHANCED_CALL_STATUS_ACTIVE, + HFP_ENHANCED_CALL_STATUS_HELD, + HFP_ENHANCED_CALL_STATUS_OUTGOING_DIALING, + HFP_ENHANCED_CALL_STATUS_OUTGOING_ALERTING, + HFP_ENHANCED_CALL_STATUS_INCOMING, + HFP_ENHANCED_CALL_STATUS_INCOMING_WAITING, + HFP_ENHANCED_CALL_STATUS_CALL_HELD_BY_RESPONSE_AND_HOLD +} hfp_enhanced_call_status_t; + +typedef enum{ + HFP_ENHANCED_CALL_MODE_VOICE, + HFP_ENHANCED_CALL_MODE_DATA, + HFP_ENHANCED_CALL_MODE_FAX +} hfp_enhanced_call_mode_t; + +typedef enum{ + HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL, + HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL +} hfp_enhanced_call_mpty_t; + typedef enum{ HFP_NONE_SM, HFP_SLC_SM, @@ -468,6 +498,7 @@ typedef struct hfp_connection { uint8_t send_subscriber_number; int next_subscriber_number_to_send; + int send_status_of_current_calls; timer_source_t hfp_timeout; } hfp_connection_t; diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 03d04667a..e3cb52274 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -232,7 +232,6 @@ static int hfp_ag_send_phone_number_for_voice_tag_cmd(uint16_t cid){ return send_str_over_rfcomm(cid, buffer); } - static int hfp_ag_send_call_waiting_notification(uint16_t cid){ if (!clip_type){ clip_number[0] = 0; @@ -1239,6 +1238,11 @@ static void hfp_run_for_context(hfp_connection_t *context){ if (!context) return; if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; + if (context->send_status_of_current_calls){ + hfp_emit_event(hfp_callback, HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL, 0); + return; + } + if (context->command == HFP_CMD_UNKNOWN){ context->ok_pending = 0; context->send_error = 0; @@ -1358,6 +1362,11 @@ static void hfp_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_ hfp_parse(context, packet[pos], 0); } switch(context->command){ + case HFP_CMD_LIST_CURRENT_CALLS: + context->command = HFP_CMD_NONE; + context->send_status_of_current_calls = 1; + hfp_emit_event(hfp_callback, HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL, 0); + break; case HFP_CMD_GET_SUBSCRIBER_NUMBER_INFORMATION: if (subscriber_numbers_count == 0){ hfp_ag_ok(context->rfcomm_cid); @@ -1799,3 +1808,26 @@ void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int n subscriber_numbers = numbers; subscriber_numbers_count = numbers_count; } + +void hfp_ag_send_current_call_status(bd_addr_t bd_addr, int idx, hfp_enhanced_call_dir_t dir, + hfp_enhanced_call_status_t status, hfp_enhanced_call_mode_t mode, + hfp_enhanced_call_mpty_t mpty, uint8_t type, const char * number){ + + hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr); + + char buffer[100]; + int offset = snprintf(buffer, sizeof(buffer), "\r\n%s:%d,%d,%d,%d,%d", HFP_LIST_CURRENT_CALLS, idx, dir, status, mode, mpty); + if (number){ + offset += snprintf(buffer+offset, sizeof(buffer)-offset, "\"%s\",%u", number, type); + } + snprintf(buffer+offset, sizeof(buffer)-offset, "\r\n"); + send_str_over_rfcomm(connection->rfcomm_cid, buffer); +} + + +void hfp_ag_send_current_call_status_done(bd_addr_t bd_addr){ + hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr); + connection->ok_pending = 1; + connection->send_status_of_current_calls = 0; +} + diff --git a/src/hfp_ag.h b/src/hfp_ag.h index e59b8ad3e..22c8d2296 100644 --- a/src/hfp_ag.h +++ b/src/hfp_ag.h @@ -275,6 +275,15 @@ void hfp_ag_send_dtmf_code_done(bd_addr_t bd_addr); */ void hfp_ag_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count); +/* + * @brief + */ +void hfp_ag_send_current_call_status(bd_addr_t bd_addr, int idx, hfp_enhanced_call_dir_t dir, + hfp_enhanced_call_status_t status, hfp_enhanced_call_mode_t mode, + hfp_enhanced_call_mpty_t mpty, uint8_t type, const char * number); + +void hfp_ag_send_current_call_status_done(bd_addr_t bd_addr); + /* API_END */ #if defined __cplusplus