This commit is contained in:
Milanka Ringwald 2015-11-19 09:27:03 +01:00
commit c7de4f0ccc
4 changed files with 43 additions and 16 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");
@ -304,12 +308,12 @@ static int hfp_ag_list_supported_generic_status_indicators_cmd(uint16_t cid){
static int hfp_ag_retrieve_supported_generic_status_indicators_cmd(uint16_t cid){
char buffer[40];
int offset = snprintf(buffer, sizeof(buffer), "\r\n%s:", HFP_GENERIC_STATUS_INDICATOR);
int offset = snprintf(buffer, sizeof(buffer), "\r\n%s:(", HFP_GENERIC_STATUS_INDICATOR);
offset += hfp_hf_indicators_join(buffer+offset, sizeof(buffer)-offset);
buffer[offset] = 0;
offset += snprintf(buffer+offset, sizeof(buffer)-offset, "\r\n\r\nOK\r\n");
offset += snprintf(buffer+offset, sizeof(buffer)-offset, ")\r\n\r\nOK\r\n");
buffer[offset] = 0;
return send_str_over_rfcomm(cid, buffer);
}
@ -609,15 +613,20 @@ static int incoming_call_state_machine(hfp_connection_t * context){
indicator = get_ag_indicator_for_name(context, "callsetup");
if (!indicator) return 0;
indicator->status = HFP_CALLSETUP_STATUS_INCOMING_CALL_SETUP_IN_PROGRESS;
hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, indicator);
if (use_in_band_tone(context)){
context->call_state = HFP_CALL_TRIGGER_AUDIO_CONNECTION;
} else {
context->call_state = HFP_CALL_W4_ANSWER;
context->call_state = HFP_CALL_RING;;
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);
return 1;
case HFP_CALL_RING:
context->call_state = HFP_CALL_W4_ANSWER;
hfp_ag_ring(context->rfcomm_cid);
return 1;
case HFP_CALL_W4_ANSWER:
@ -686,7 +695,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;
@ -756,7 +764,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;
}
@ -828,17 +836,19 @@ void hfp_ag_report_extended_audio_gateway_error_result_code(bd_addr_t bd_addr, h
void hfp_ag_establish_audio_connection(bd_addr_t bd_addr){
hfp_ag_establish_service_level_connection(bd_addr);
hfp_connection_t * connection = get_hfp_connection_context_for_bd_addr(bd_addr);
if (!has_codec_negotiation_feature(connection)){
log_info("hfp_ag_establish_audio_connection - no codec negotiation feature");
return;
}
connection->establish_audio_connection = 0;
if (connection->state == HFP_AUDIO_CONNECTION_ESTABLISHED) return;
if (connection->state >= HFP_W2_DISCONNECT_SCO) return;
connection->establish_audio_connection = 1;
if (!has_codec_negotiation_feature(connection)){
log_info("hfp_ag_establish_audio_connection - no codec negotiation feature, using defaults");
connection->negotiated_codec = HFP_CODEC_CVSD;
connection->codecs_state = HFP_CODECS_EXCHANGED;
}
switch (connection->codecs_state){
case HFP_CODECS_IDLE:
case HFP_CODECS_RECEIVED_LIST:
@ -862,7 +872,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;