hfp: simulate incoming call, send RING command

This commit is contained in:
Matthias Ringwald 2015-11-18 23:48:12 +01:00
parent 7f01e2eed8
commit 2c1d941a0c
4 changed files with 37 additions and 12 deletions

View File

@ -284,6 +284,7 @@ typedef enum {
HFP_CALL_IDLE,
HFP_CALL_TRIGGER_AUDIO_CONNECTION,
HFP_CALL_W4_AUDIO_CONNECTION,
HFP_CALL_RING,
HFP_CALL_W4_ANSWER,
HFP_CALL_TRANSFER_CALL_STATUS,

View File

@ -175,6 +175,10 @@ static int hfp_ag_ok(uint16_t cid){
return send_str_over_rfcomm(cid, buffer);
}
static int hfp_ag_ring(uint16_t cid){
return send_str_over_rfcomm(cid, "\r\nRING\r\n");
}
static int hfp_ag_error(uint16_t cid){
char buffer[10];
sprintf(buffer, "\r\nERROR\r\n");
@ -634,18 +638,23 @@ static int incoming_call_state_machine(hfp_connection_t * context){
indicator = get_ag_indicator_for_name(context, "callsetup");
if (!indicator) break;
if (use_in_band_tone(context)){
context->call_state = HFP_CALL_TRIGGER_AUDIO_CONNECTION;
} else {
context->call_state = HFP_CALL_W4_ANSWER;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_START_RINGINIG, 0);
}
indicator->status = HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS;
hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, indicator);
done = 1;
if (use_in_band_tone(context)){
context->call_state = HFP_CALL_TRIGGER_AUDIO_CONNECTION;
} else {
context->call_state = HFP_CALL_RING;;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_START_RINGINIG, 0);
}
break;
case HFP_CALL_RING:
context->call_state = HFP_CALL_W4_ANSWER;
hfp_ag_ring(context->rfcomm_cid);
return 1;
case HFP_CALL_W4_ANSWER:
//printf(" HFP_CALL_W4_ANSWER \n");
context->call_state = HFP_CALL_TRANSFER_CALL_STATUS;
@ -715,7 +724,6 @@ static void hfp_run_for_context(hfp_connection_t *context){
return;
}
if (context->ok_pending){
context->ok_pending = 0;
context->command = HFP_CMD_NONE;
@ -785,7 +793,7 @@ static void packet_handler(void * connection, uint8_t packet_type, uint16_t chan
break;
case HCI_EVENT_PACKET:
hfp_handle_hci_event(hfp_callback, packet_type, packet, size);
return;
break;
default:
break;
}
@ -893,7 +901,7 @@ void hfp_ag_release_audio_connection(bd_addr_t bd_addr){
/**
* @brief
*/
void hfp_ag_call(bd_addr_t bd_addr, uint8_t use_in_band_ring_tone){
void hfp_ag_incoming_call(bd_addr_t bd_addr, uint8_t use_in_band_ring_tone){
hfp_ag_establish_service_level_connection(bd_addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);

View File

@ -165,7 +165,7 @@ void hfp_ag_release_audio_connection(bd_addr_t bd_addr);
/**
* @brief
*/
void hfp_ag_call(bd_addr_t bd_addr, uint8_t use_in_band_ring_tone);
void hfp_ag_incoming_call(bd_addr_t bd_addr, uint8_t use_in_band_ring_tone);

View File

@ -97,7 +97,7 @@ static hfp_generic_status_indicator_t hf_indicators[] = {
{1, 1},
{2, 1},
};
static int inband_ringing = 0;
char cmd;
// prototypes
@ -118,6 +118,8 @@ static void show_usage(void){
printf("B - release AUDIO connection\n");
printf("d - report AG failure\n");
printf("c - simulate incoming call\n");
printf("C - simulate terminage call\n");
printf("t - terminate connection\n");
@ -155,6 +157,14 @@ static int stdin_process(struct data_source *ds){
printf("Release Audio connection.\n");
hfp_ag_release_audio_connection(device_addr);
break;
case 'c':
printf("Simulate incoming call\n");
hfp_ag_incoming_call(device_addr, inband_ringing);
break;
case 'C':
printf("Simulate terminate call\n");
hfp_ag_terminate_call(device_addr);
break;
case 'd':
printf("Report AG failure\n");
hfp_ag_report_extended_audio_gateway_error_result_code(device_addr, HFP_CME_ERROR_AG_FAILURE);
@ -197,6 +207,12 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
printf("\n** Audio connection released **\n\n");
break;
case HFP_SUBEVENT_START_RINGINIG:
printf("\n** Start Ringing **\n\n");
break;
case HFP_SUBEVENT_STOP_RINGINIG:
printf("\n** Stop Ringing **\n\n");
break;
default:
printf("event not handled %u\n", event[2]);
break;