hfp ag: incoming call

This commit is contained in:
Milanka Ringwald 2015-11-12 23:29:11 +01:00
parent deb81c610f
commit 1872f8480a
7 changed files with 64 additions and 36 deletions

View File

@ -623,6 +623,11 @@ static void process_command(hfp_connection_t * context){
context->command = HFP_CMD_NONE; context->command = HFP_CMD_NONE;
int offset = 0; int offset = 0;
int isHandsFree = 1; 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){ if (strncmp((char *)context->line_buffer, "AT", 2) == 0){
offset = 2; offset = 2;
@ -745,7 +750,6 @@ static void process_command(hfp_connection_t * context){
} }
return; return;
} }
if (strncmp((char *)context->line_buffer+offset, "AT+", 3) == 0){ if (strncmp((char *)context->line_buffer+offset, "AT+", 3) == 0){
context->command = HFP_CMD_UNKNOWN; context->command = HFP_CMD_UNKNOWN;

View File

@ -89,6 +89,7 @@ extern "C" {
*/ */
#define HFP_AGSF_THREE_WAY_CALLING 0 #define HFP_AGSF_THREE_WAY_CALLING 0
#define HFP_AGSF_EC_NR_FUNCTION 1 #define HFP_AGSF_EC_NR_FUNCTION 1
#define HFP_AGSF_IN_BAND_RING_TONE 3
#define HFP_AGSF_CODEC_NEGOTIATION 9 #define HFP_AGSF_CODEC_NEGOTIATION 9
#define HFP_AGSF_HF_INDICATORS 10 #define HFP_AGSF_HF_INDICATORS 10
#define HFP_AGSF_ESCO 11 #define HFP_AGSF_ESCO 11
@ -114,6 +115,7 @@ extern "C" {
#define HFP_EXTENDED_AUDIO_GATEWAY_ERROR "+CME ERROR" #define HFP_EXTENDED_AUDIO_GATEWAY_ERROR "+CME ERROR"
#define HFP_TRIGGER_CODEC_CONNECTION_SETUP "+BCC" #define HFP_TRIGGER_CODEC_CONNECTION_SETUP "+BCC"
#define HFP_CONFIRM_COMMON_CODEC "+BCS" #define HFP_CONFIRM_COMMON_CODEC "+BCS"
#define HFP_CALL_ANSWERED "ATA"
#define HFP_OK "OK" #define HFP_OK "OK"
#define HFP_ERROR "ERROR" #define HFP_ERROR "ERROR"
@ -143,8 +145,8 @@ typedef enum {
HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR, HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR,
HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP, HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP,
HFP_CMD_AG_SUGGESTED_CODEC, HFP_CMD_AG_SUGGESTED_CODEC,
HFP_CMD_HF_CONFIRMED_CODEC HFP_CMD_HF_CONFIRMED_CODEC,
HFP_CMD_CALL_ANSWERED
} hfp_command_t; } hfp_command_t;
typedef enum { typedef enum {
@ -253,7 +255,9 @@ typedef enum {
HFP_W4_SCO_CONNECTED, HFP_W4_SCO_CONNECTED,
HFP_AUDIO_CONNECTION_ESTABLISHED, HFP_AUDIO_CONNECTION_ESTABLISHED,
HFP_RING_ALERT,
HFP_CALL_ACTIVE,
HFP_W2_DISCONNECT_SCO, HFP_W2_DISCONNECT_SCO,
HFP_W4_SCO_DISCONNECTED, // 30 HFP_W4_SCO_DISCONNECTED, // 30
@ -374,7 +378,9 @@ typedef struct hfp_connection {
uint8_t start_call; uint8_t start_call;
uint8_t terminate_call; uint8_t terminate_call;
uint8_t start_ringing; uint8_t start_ringing;
uint8_t stop_ringing; uint8_t update_call_status;
uint8_t update_callsetup_status;
} hfp_connection_t; } hfp_connection_t;
// UTILS_START : TODO move to utils // UTILS_START : TODO move to utils

View File

@ -684,6 +684,42 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
done = 1; done = 1;
return done; 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; break;
default: default:
break; break;
@ -714,16 +750,6 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
return done; 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; return done;
} }
@ -936,6 +962,7 @@ void hfp_ag_call(bd_addr_t bd_addr){
hfp_run_for_context(connection); hfp_run_for_context(connection);
} }
/** /**
* @brief * @brief
*/ */

View File

@ -167,6 +167,7 @@ void hfp_ag_release_audio_connection(bd_addr_t bd_addr);
*/ */
void hfp_ag_call(bd_addr_t bd_addr); void hfp_ag_call(bd_addr_t bd_addr);
/** /**
* @brief * @brief
*/ */

View File

@ -43,8 +43,8 @@ COMMON_OBJ = $(COMMON:.c=.o)
MOCK_OBJ = $(MOCK:.c=.o) MOCK_OBJ = $(MOCK:.c=.o)
# CC = gcc-fsf-4.9 # CC = gcc-fsf-4.9
CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include CFLAGS = -g -Wall -Wmissing-prototype -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include
# CFLAGS += -Werror CFLAGS += -Werror
VPATH += ${BTSTACK_ROOT}/src VPATH += ${BTSTACK_ROOT}/src
VPATH += ${BTSTACK_ROOT}/ble VPATH += ${BTSTACK_ROOT}/ble

View File

@ -98,7 +98,7 @@ static uint8_t service_level_connection_established = 0;
static uint8_t codecs_connection_established = 0; static uint8_t codecs_connection_established = 0;
static uint8_t audio_connection_established = 0; static uint8_t audio_connection_established = 0;
static uint8_t start_ringing = 0; static uint8_t start_ringing = 0;
static uint8_t stop_ringing = 0;
int expected_rfcomm_command(const char * expected_cmd){ int expected_rfcomm_command(const char * expected_cmd){
char * ag_cmd = (char *)get_rfcomm_payload(); char * ag_cmd = (char *)get_rfcomm_payload();
@ -171,6 +171,7 @@ void packet_handler(uint8_t * event, uint16_t event_size){
break; break;
case HFP_SUBEVENT_STOP_RINGINIG: case HFP_SUBEVENT_STOP_RINGINIG:
printf("\n** Stop ringing **\n\n"); printf("\n** Stop ringing **\n\n");
stop_ringing = 1;
start_ringing = 0; start_ringing = 0;
break; break;
default: default:
@ -221,7 +222,7 @@ TEST(HFPClient, HFAnswerIncomingCallWithInBandRingTone){
CHECK_EQUAL(audio_connection_established, 1); CHECK_EQUAL(audio_connection_established, 1);
simulate_test_sequence(alert_ic_setup(), alert_ic_setup_size()); simulate_test_sequence(alert_ic_setup(), alert_ic_setup_size());
CHECK_EQUAL(start_ringing, 1); CHECK_EQUAL(stop_ringing, 1);
} }

View File

@ -155,23 +155,12 @@ const char * ic_test1[] = {
const char * ic_alert_test1[] = { const char * ic_alert_test1[] = {
"NOP", "NOP",
// //"RING", "ATA",
// "NOP", "OK",
// "+CLIP:\"1234\",128", "NOP",
// "NOP", "+CIEV:2,1", // call = 1
// "InBandRingTone", "NOP",
// "NOP", "+CIEV:3,0"
// "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"
}; };
hfp_test_item_t ic_tests[] = { hfp_test_item_t ic_tests[] = {