This commit is contained in:
Matthias Ringwald 2015-11-18 22:41:56 +01:00
commit eb9aa28c64
6 changed files with 190 additions and 206 deletions

216
src/hfp.c
View File

@ -257,8 +257,7 @@ hfp_connection_t * get_hfp_connection_context_for_sco_handle(uint16_t handle){
void hfp_reset_context_flags(hfp_connection_t * context){
if (!context) return;
context->wait_ok = 0;
context->send_ok = 0;
context->ok_pending = 0;
context->send_error = 0;
context->keep_separator = 0;
@ -607,139 +606,116 @@ void hfp_handle_hci_event(hfp_callback_t callback, uint8_t packet_type, uint8_t
}
// translates command string into hfp_command_t CMD and flags to distinguish between CMD=, CMD?, CMD=?
static void process_command(hfp_connection_t * context){
if (context->line_size < 2) return;
// printf("process_command %s\n", context->line_buffer);
int offset = 0;
int isHandsFree = 1;
static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){
int offset = isHandsFree ? 0 : 2;
if (strncmp((char *)context->line_buffer+offset, HFP_CALL_ANSWERED, strlen(HFP_CALL_ANSWERED)) == 0){
context->command = HFP_CMD_CALL_ANSWERED;
return;
if (strncmp(line_buffer+offset, HFP_CALL_ANSWERED, strlen(HFP_CALL_ANSWERED)) == 0){
return HFP_CMD_CALL_ANSWERED;
}
if (strncmp((char *)context->line_buffer, "AT", 2) == 0){
offset = 2;
isHandsFree = 0;
}
if (strncmp((char *)context->line_buffer+offset, HFP_ERROR, strlen(HFP_ERROR)) == 0){
context->command = HFP_CMD_ERROR;
return;
if (strncmp(line_buffer+offset, HFP_ERROR, strlen(HFP_ERROR)) == 0){
return HFP_CMD_ERROR;
}
if (isHandsFree && strncmp((char *)context->line_buffer+offset, HFP_OK, strlen(HFP_OK)) == 0){
//printf("parsed HFP_CMD_OK \n");
context->command = HFP_CMD_OK;
return;
if (isHandsFree && strncmp(line_buffer+offset, HFP_OK, strlen(HFP_OK)) == 0){
return HFP_CMD_OK;
}
if (strncmp((char *)context->line_buffer+offset, HFP_SUPPORTED_FEATURES, strlen(HFP_SUPPORTED_FEATURES)) == 0){
context->command = HFP_CMD_SUPPORTED_FEATURES;
return;
if (strncmp(line_buffer+offset, HFP_SUPPORTED_FEATURES, strlen(HFP_SUPPORTED_FEATURES)) == 0){
return HFP_CMD_SUPPORTED_FEATURES;
}
if (strncmp((char *)context->line_buffer+offset, HFP_INDICATOR, strlen(HFP_INDICATOR)) == 0){
if (strncmp((char *)context->line_buffer+strlen(HFP_INDICATOR)+offset, "?", 1) == 0){
context->command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
if (strncmp(line_buffer+offset, HFP_INDICATOR, strlen(HFP_INDICATOR)) == 0){
if (strncmp(line_buffer+strlen(HFP_INDICATOR)+offset, "?", 1) == 0){
return HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
}
if (strncmp((char *)context->line_buffer+strlen(HFP_INDICATOR)+offset, "=?", 2) == 0){
context->command = HFP_CMD_RETRIEVE_AG_INDICATORS;
if (strncmp(line_buffer+strlen(HFP_INDICATOR)+offset, "=?", 2) == 0){
return HFP_CMD_RETRIEVE_AG_INDICATORS;
}
return;
}
if (strncmp((char *)context->line_buffer+offset, HFP_AVAILABLE_CODECS, strlen(HFP_AVAILABLE_CODECS)) == 0){
context->command = HFP_CMD_AVAILABLE_CODECS;
return;
if (strncmp(line_buffer+offset, HFP_AVAILABLE_CODECS, strlen(HFP_AVAILABLE_CODECS)) == 0){
return HFP_CMD_AVAILABLE_CODECS;
}
if (strncmp((char *)context->line_buffer+offset, HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS, strlen(HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS)) == 0){
context->command = HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE;
return;
if (strncmp(line_buffer+offset, HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS, strlen(HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS)) == 0){
return HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE;
}
if (strncmp((char *)context->line_buffer+offset, HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, strlen(HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES)) == 0){
context->command = HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES;
return;
if (strncmp(line_buffer+offset, HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, strlen(HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES)) == 0){
return HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES;
}
if (strncmp((char *)context->line_buffer+offset, HFP_GENERIC_STATUS_INDICATOR, strlen(HFP_GENERIC_STATUS_INDICATOR)) == 0){
if (isHandsFree) return;
if (strncmp(line_buffer+offset, HFP_GENERIC_STATUS_INDICATOR, strlen(HFP_GENERIC_STATUS_INDICATOR)) == 0){
if (isHandsFree) return HFP_CMD_UNKNOWN;
if (strncmp((char *)context->line_buffer+strlen(HFP_GENERIC_STATUS_INDICATOR)+offset, "=?", 2) == 0){
context->command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS;
} else if (strncmp((char *)context->line_buffer+strlen(HFP_GENERIC_STATUS_INDICATOR)+offset, "=", 1) == 0){
context->command = HFP_CMD_LIST_GENERIC_STATUS_INDICATORS;
} else {
context->command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
}
return;
}
if (strncmp((char *)context->line_buffer+offset, HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS, strlen(HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS)) == 0){
context->command = HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE;
return;
}
if (strncmp((char *)context->line_buffer+offset, HFP_QUERY_OPERATOR_SELECTION, strlen(HFP_QUERY_OPERATOR_SELECTION)) == 0){
context->command = HFP_CMD_QUERY_OPERATOR_SELECTION_NAME;
if (isHandsFree) return;
if (strncmp((char *)context->line_buffer+strlen(HFP_QUERY_OPERATOR_SELECTION)+offset, "=", 1) == 0){
context->command = HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT;
if (strncmp(line_buffer+strlen(HFP_GENERIC_STATUS_INDICATOR)+offset, "=?", 2) == 0){
return HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS;
}
return;
}
if (strncmp((char *)context->line_buffer+offset, HFP_TRANSFER_AG_INDICATOR_STATUS, strlen(HFP_TRANSFER_AG_INDICATOR_STATUS)) == 0){
context->command = HFP_CMD_TRANSFER_AG_INDICATOR_STATUS;
return;
}
if (isHandsFree && strncmp((char *)context->line_buffer+offset, HFP_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0){
context->command = HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR;
return;
}
if (!isHandsFree && strncmp((char *)context->line_buffer+offset, HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0){
context->command = HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR;
return;
}
if (strncmp((char *)context->line_buffer+offset, HFP_TRIGGER_CODEC_CONNECTION_SETUP, strlen(HFP_TRIGGER_CODEC_CONNECTION_SETUP)) == 0){
context->command = HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP;
return;
}
if (strncmp((char *)context->line_buffer+offset, HFP_CONFIRM_COMMON_CODEC, strlen(HFP_CONFIRM_COMMON_CODEC)) == 0){
if (!isHandsFree){
context->command = HFP_CMD_HF_CONFIRMED_CODEC;
} else {
context->command = HFP_CMD_AG_SUGGESTED_CODEC;
if (strncmp(line_buffer+strlen(HFP_GENERIC_STATUS_INDICATOR)+offset, "=", 1) == 0){
return HFP_CMD_LIST_GENERIC_STATUS_INDICATORS;
}
return;
{
return HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
}
}
if (strncmp(line_buffer+offset, HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS, strlen(HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS)) == 0){
return HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE;
}
if (strncmp((char *)context->line_buffer+offset, "AT+", 3) == 0){
context->command = HFP_CMD_UNKNOWN;
printf(" process unknown HF command %s \n", context->line_buffer);
return;
if (strncmp(line_buffer+offset, HFP_QUERY_OPERATOR_SELECTION, strlen(HFP_QUERY_OPERATOR_SELECTION)) == 0){
if (isHandsFree) return HFP_CMD_QUERY_OPERATOR_SELECTION_NAME;
if (strncmp(line_buffer+strlen(HFP_QUERY_OPERATOR_SELECTION)+offset, "=", 1) == 0){
return HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT;
}
return HFP_CMD_QUERY_OPERATOR_SELECTION_NAME;
}
if (strncmp(line_buffer+offset, HFP_TRANSFER_AG_INDICATOR_STATUS, strlen(HFP_TRANSFER_AG_INDICATOR_STATUS)) == 0){
return HFP_CMD_TRANSFER_AG_INDICATOR_STATUS;
}
if (strncmp((char *)context->line_buffer+offset, "+", 1) == 0){
context->command = HFP_CMD_UNKNOWN;
printf(" process unknown AG command %s \n", context->line_buffer);
return;
if (isHandsFree && strncmp(line_buffer+offset, HFP_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0){
return HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR;
}
if (!isHandsFree && strncmp(line_buffer+offset, HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, strlen(HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR)) == 0){
return HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR;
}
if (strncmp(line_buffer+offset, HFP_TRIGGER_CODEC_CONNECTION_SETUP, strlen(HFP_TRIGGER_CODEC_CONNECTION_SETUP)) == 0){
return HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP;
}
if (strncmp(line_buffer+offset, HFP_CONFIRM_COMMON_CODEC, strlen(HFP_CONFIRM_COMMON_CODEC)) == 0){
if (isHandsFree){
return HFP_CMD_AG_SUGGESTED_CODEC;
} else {
return HFP_CMD_HF_CONFIRMED_CODEC;
}
}
if (strncmp(line_buffer+offset, "AT+", 3) == 0){
printf(" process unknown HF command %s \n", line_buffer);
return HFP_CMD_UNKNOWN;
}
if (strncmp(line_buffer+offset, "+", 1) == 0){
printf(" process unknown AG command %s \n", line_buffer);
return HFP_CMD_UNKNOWN;
}
if (strncmp((char *)context->line_buffer+offset, "NOP", 3) == 0){
context->command = HFP_CMD_NONE;
return;
if (strncmp(line_buffer+offset, "NOP", 3) == 0){
return HFP_CMD_NONE;
}
context->command = HFP_CMD_NONE;
return HFP_CMD_NONE;
}
#if 0
@ -819,7 +795,7 @@ static void hfp_parser_next_state(hfp_connection_t * context, uint8_t byte){
}
}
void hfp_parse(hfp_connection_t * context, uint8_t byte){
void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree){
int value;
// TODO: handle space inside word
@ -853,7 +829,31 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
// printf(" parse header 2 %s, keep separator $ %d\n", context->line_buffer, context->keep_separator);
if (hfp_parser_is_end_of_header(byte) || context->keep_separator == 1){
// printf(" parse header 3 %s, keep separator $ %d\n", context->line_buffer, context->keep_separator);
process_command(context);
char * line_buffer = (char *)context->line_buffer;
context->command = parse_command(line_buffer, isHandsFree);
/* resolve command name according to context */
if (context->command == HFP_CMD_UNKNOWN){
switch(context->state){
case HFP_W4_LIST_GENERIC_STATUS_INDICATORS:
context->command = HFP_CMD_LIST_GENERIC_STATUS_INDICATORS;
break;
case HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS:
context->command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS;
break;
case HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS:
context->command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
break;
case HFP_W4_RETRIEVE_INDICATORS_STATUS:
context->command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
break;
case HFP_W4_RETRIEVE_INDICATORS:
context->command = HFP_CMD_RETRIEVE_AG_INDICATORS;
break;
default:
break;
}
}
}
break;
@ -945,7 +945,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
break;
case HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR:
context->enable_extended_audio_gateway_error_report = (uint8_t)atoi((char*)context->line_buffer);
context->send_ok = 1;
context->ok_pending = 1;
context->extended_audio_gateway_error = 0;
break;
default:

View File

@ -377,8 +377,8 @@ typedef struct hfp_connection {
uint8_t negotiated_codec;
// TODO: put these bit flags in a bitmap
uint8_t wait_ok;
uint8_t send_ok;
uint8_t ok_pending;
// uint8_t send_ok;
uint8_t send_error;
uint8_t keep_separator;
@ -422,7 +422,7 @@ hfp_generic_status_indicator_t * get_hfp_generic_status_indicators(void);
void set_hfp_generic_status_indicators(hfp_generic_status_indicator_t * indicators, int indicator_nr);
linked_list_t * hfp_get_connections(void);
void hfp_parse(hfp_connection_t * context, uint8_t byte);
void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree);
void hfp_init(uint16_t rfcomm_channel_nr);
void hfp_establish_service_level_connection(bd_addr_t bd_addr, uint16_t service_uuid);

View File

@ -708,25 +708,25 @@ static void hfp_run_for_context(hfp_connection_t *context){
if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
if (context->command == HFP_CMD_UNKNOWN){
hfp_ag_error(context->rfcomm_cid);
context->send_ok = 0;
context->ok_pending = 0;
context->send_error = 0;
context->command = HFP_CMD_NONE;
hfp_ag_error(context->rfcomm_cid);
return;
}
if (context->send_ok){
hfp_ag_ok(context->rfcomm_cid);
context->send_ok = 0;
if (context->ok_pending){
context->ok_pending = 0;
context->command = HFP_CMD_NONE;
hfp_ag_ok(context->rfcomm_cid);
return;
}
if (context->send_error){
hfp_ag_error(context->rfcomm_cid);
context->send_error = 0;
context->command = HFP_CMD_NONE;
hfp_ag_error(context->rfcomm_cid);
return;
}
@ -765,7 +765,7 @@ static void hfp_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_
if (!context) return;
int pos;
for (pos = 0; pos < size ; pos++){
hfp_parse(context, packet[pos]);
hfp_parse(context, packet[pos], 0);
}
}

View File

@ -253,61 +253,48 @@ static void hfp_emit_network_operator_event(hfp_callback_t callback, int status,
static int hfp_hf_run_for_context_service_level_connection(hfp_connection_t * context){
if (context->state >= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
int done = 0;
if (context->wait_ok) return done;
if (context->ok_pending) return 0;
int done = 1;
switch (context->state){
case HFP_EXCHANGE_SUPPORTED_FEATURES:
hfp_hf_cmd_exchange_supported_features(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_EXCHANGE_SUPPORTED_FEATURES;
hfp_hf_cmd_exchange_supported_features(context->rfcomm_cid);
break;
case HFP_NOTIFY_ON_CODECS:
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_NOTIFY_ON_CODECS;
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
break;
case HFP_RETRIEVE_INDICATORS:
hfp_hf_cmd_retrieve_indicators(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_RETRIEVE_INDICATORS;
context->command = HFP_CMD_RETRIEVE_AG_INDICATORS;
hfp_hf_cmd_retrieve_indicators(context->rfcomm_cid);
break;
case HFP_RETRIEVE_INDICATORS_STATUS:
hfp_hf_cmd_retrieve_indicators_status(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_RETRIEVE_INDICATORS_STATUS;
context->command = HFP_CMD_RETRIEVE_AG_INDICATORS;
hfp_hf_cmd_retrieve_indicators_status(context->rfcomm_cid);
break;
case HFP_ENABLE_INDICATORS_STATUS_UPDATE:
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(context->rfcomm_cid, 1);
done = 1;
context->state = HFP_W4_ENABLE_INDICATORS_STATUS_UPDATE;
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(context->rfcomm_cid, 1);
break;
case HFP_RETRIEVE_CAN_HOLD_CALL:
hfp_hf_cmd_retrieve_can_hold_call(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_RETRIEVE_CAN_HOLD_CALL;
hfp_hf_cmd_retrieve_can_hold_call(context->rfcomm_cid);
break;
case HFP_LIST_GENERIC_STATUS_INDICATORS:
hfp_hf_cmd_list_supported_generic_status_indicators(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_LIST_GENERIC_STATUS_INDICATORS;
context->command = HFP_CMD_LIST_GENERIC_STATUS_INDICATORS;
hfp_hf_cmd_list_supported_generic_status_indicators(context->rfcomm_cid);
break;
case HFP_RETRIEVE_GENERIC_STATUS_INDICATORS:
hfp_hf_cmd_retrieve_supported_generic_status_indicators(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS;
context->command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS;
hfp_hf_cmd_retrieve_supported_generic_status_indicators(context->rfcomm_cid);
break;
case HFP_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS:
hfp_hf_cmd_list_initital_supported_generic_status_indicators(context->rfcomm_cid);
done = 1;
context->state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
context->command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
hfp_hf_cmd_list_initital_supported_generic_status_indicators(context->rfcomm_cid);
break;
default:
done = 0;
break;
}
return done;
@ -377,41 +364,41 @@ static void hfp_hf_handle_ok_service_level_connection_establishment(hfp_connecti
static int hfp_hf_run_for_context_service_level_connection_queries(hfp_connection_t * context){
if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
if (context->wait_ok) return 0;
if (context->ok_pending) return 0;
int done = 0;
if (context->enable_status_update_for_ag_indicators != 0xFF){
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(context->rfcomm_cid, context->enable_status_update_for_ag_indicators);
context->wait_ok = 1;
context->ok_pending = 1;
done = 1;
hfp_hf_cmd_activate_status_update_for_all_ag_indicators(context->rfcomm_cid, context->enable_status_update_for_ag_indicators);
return done;
};
if (context->change_status_update_for_individual_ag_indicators){
context->ok_pending = 1;
done = 1;
hfp_hf_cmd_activate_status_update_for_ag_indicator(context->rfcomm_cid,
context->ag_indicators_status_update_bitmap,
context->ag_indicators_nr);
context->wait_ok = 1;
done = 1;
return done;
}
if (context->command == HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT){
hfp_hf_cmd_query_operator_name_format(context->rfcomm_cid);
context->wait_ok = 1;
context->ok_pending = 1;
done = 1;
hfp_hf_cmd_query_operator_name_format(context->rfcomm_cid);
return done;
}
if (context->command == HFP_CMD_QUERY_OPERATOR_SELECTION_NAME){
hfp_hf_cmd_query_operator_name(context->rfcomm_cid);
context->wait_ok = 1;
context->ok_pending = 1;
done = 1;
hfp_hf_cmd_query_operator_name(context->rfcomm_cid);
return done;
}
if (context->enable_extended_audio_gateway_error_report){
hfp_hf_cmd_enable_extended_audio_gateway_error_report(context->rfcomm_cid, context->enable_extended_audio_gateway_error_report);
context->wait_ok = 1;
context->ok_pending = 1;
done = 1;
hfp_hf_cmd_enable_extended_audio_gateway_error_report(context->rfcomm_cid, context->enable_extended_audio_gateway_error_report);
return done;
}
@ -449,8 +436,8 @@ static void hfp_hf_handle_ok_service_level_connection_queries(hfp_connection_t *
}
static int codecs_exchange_state_machine(hfp_connection_t * context){
if (context->wait_ok) return 0;
int done = 0;
if (context->ok_pending) return 0;
int done = 1;
switch(context->command){
case HFP_CMD_AVAILABLE_CODECS:
@ -467,37 +454,30 @@ static int codecs_exchange_state_machine(hfp_connection_t * context){
default:
break;
}
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
done = 1;
break;
case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP:
context->codecs_state = HFP_CODECS_RECEIVED_TRIGGER_CODEC_EXCHANGE;
hfp_hf_cmd_trigger_codec_connection_setup(context->rfcomm_cid);
done = 1;
break;
case HFP_CMD_AG_SUGGESTED_CODEC:
if (hfp_hf_supports_codec(context->suggested_codec)){
context->codec_confirmed = context->suggested_codec;
hfp_hf_cmd_confirm_codec(context->rfcomm_cid, context->suggested_codec);
done = 1;
} else {
context->codec_confirmed = 0;
context->suggested_codec = 0;
context->negotiated_codec = 0;
hfp_hf_cmd_notify_on_codecs(context->rfcomm_cid);
done = 1;
}
break;
default:
break;
return 0;
}
if (done){
context->wait_ok = 1;
context->ok_pending = 1;
}
return done;
}
@ -540,7 +520,7 @@ static void hfp_run_for_context(hfp_connection_t * context){
static void hfp_hf_switch_on_ok(hfp_connection_t *context){
// printf("switch on ok\n");
context->wait_ok = 0;
context->ok_pending = 0;
hfp_hf_handle_ok_service_level_connection_establishment(context);
hfp_hf_handle_ok_service_level_connection_queries(context);
@ -558,27 +538,27 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
int pos, i;
//printf("\nHF received: %s", packet+2);
for (pos = 0; pos < size ; pos++){
hfp_parse(context, packet[pos]);
hfp_parse(context, packet[pos], 1);
// emit indicators status changed
for (i = 0; i < context->ag_indicators_nr; i++){
if (context->ag_indicators[i].status_changed) {
hfp_emit_ag_indicator_event(hfp_callback, 0, context->ag_indicators[i]);
context->ag_indicators[i].status_changed = 0;
hfp_emit_ag_indicator_event(hfp_callback, 0, context->ag_indicators[i]);
break;
}
}
if (context->command == HFP_CMD_ERROR){
context->wait_ok = 0;
context->ok_pending = 0;
hfp_reset_context_flags(context);
hfp_emit_event(hfp_callback, HFP_SUBEVENT_COMPLETE, 1);
return;
}
if (context->command == HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR){
context->wait_ok = 0;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR, context->extended_audio_gateway_error);
context->ok_pending = 0;
context->extended_audio_gateway_error = 0;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR, context->extended_audio_gateway_error);
return;
}

View File

@ -46,7 +46,7 @@
#include "hfp.h"
void hfp_parse(hfp_connection_t * context, uint8_t byte);
void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree);
hfp_generic_status_indicator_t * get_hfp_generic_status_indicators();
void set_hfp_generic_status_indicators(hfp_generic_status_indicator_t * indicators, int indicator_nr);
@ -93,7 +93,7 @@ TEST(HFPParser, HFP_AG_SUPPORTED_FEATURES){
sprintf(packet, "\r\nAT%s=159\r\n", HFP_SUPPORTED_FEATURES);
context.keep_separator = 0;
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(HFP_CMD_SUPPORTED_FEATURES, context.command);
CHECK_EQUAL(159, context.remote_supported_features);
@ -102,7 +102,7 @@ TEST(HFPParser, HFP_AG_SUPPORTED_FEATURES){
TEST(HFPParser, HFP_AG_AVAILABLE_CODECS){
sprintf(packet, "\r\nAT%s=0,1,2\r\n", HFP_AVAILABLE_CODECS);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(HFP_CMD_AVAILABLE_CODECS, context.command);
CHECK_EQUAL(3, context.remote_codecs_nr);
@ -116,7 +116,7 @@ TEST(HFPParser, HFP_AG_GENERIC_STATUS_INDICATOR){
sprintf(packet, "\r\nAT%s=0,1,2,3,4\r\n", HFP_GENERIC_STATUS_INDICATOR);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(context.command, HFP_CMD_LIST_GENERIC_STATUS_INDICATORS);
@ -131,7 +131,7 @@ TEST(HFPParser, HFP_AG_GENERIC_STATUS_INDICATOR){
TEST(HFPParser, HFP_AG_ENABLE_INDICATOR_STATUS_UPDATE){
sprintf(packet, "\r\nAT%s=3,0,0,1\r\n", HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE, context.command);
CHECK_EQUAL(1, context.enable_status_update_for_ag_indicators);
@ -153,7 +153,7 @@ TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE){
sprintf(packet, "\r\nAT%s=0,0,0,0,0,0,0\r\n",
HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
@ -171,7 +171,7 @@ TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE){
// sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
// HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
// for (pos = 0; pos < strlen(packet); pos++){
// hfp_parse(&context, packet[pos]);
// hfp_parse(&context, packet[pos], 0);
// }
// CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
@ -187,7 +187,7 @@ TEST(HFPParser, HFP_AG_HF_QUERY_OPERATOR_SELECTION){
sprintf(packet, "\r\nAT%s=3,0\r\n", HFP_QUERY_OPERATOR_SELECTION);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(context.operator_name_changed, 0);
@ -196,7 +196,7 @@ TEST(HFPParser, HFP_AG_HF_QUERY_OPERATOR_SELECTION){
sprintf(packet, "\r\nAT%s?\r\n", HFP_QUERY_OPERATOR_SELECTION);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(context.operator_name_changed, 0);
}
@ -205,7 +205,7 @@ TEST(HFPParser, HFP_AG_EXTENDED_AUDIO_GATEWAY_ERROR){
sprintf(packet, "\r\nAT%s=1\r\n", HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(context.command, HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR);
@ -215,7 +215,7 @@ TEST(HFPParser, HFP_AG_EXTENDED_AUDIO_GATEWAY_ERROR){
TEST(HFPParser, HFP_AG_TRIGGER_CODEC_CONNECTION_SETUP){
sprintf(packet, "\r\nAT%s\r\n", HFP_TRIGGER_CODEC_CONNECTION_SETUP);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(context.command, HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP);
}
@ -225,7 +225,7 @@ TEST(HFPParser, HFP_AG_CONFIRM_COMMON_CODEC){
sprintf(packet, "\r\nAT%s=%d\r\n", HFP_CONFIRM_COMMON_CODEC, codec);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 0);
}
CHECK_EQUAL(context.command, HFP_CMD_HF_CONFIRMED_CODEC);

View File

@ -46,7 +46,7 @@
#include "hfp.h"
void hfp_parse(hfp_connection_t * context, uint8_t byte);
void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree);
static hfp_connection_t context;
static int hfp_ag_indicators_nr = 7;
@ -84,7 +84,7 @@ TEST_GROUP(HFPParser){
TEST(HFPParser, HFP_HF_OK){
sprintf(packet, "\r\n%s\r\n", HFP_OK);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
}
@ -92,7 +92,7 @@ TEST(HFPParser, HFP_HF_OK){
TEST(HFPParser, HFP_HF_SUPPORTED_FEATURES){
sprintf(packet, "\r\n%s:1007\r\n\r\nOK\r\n", HFP_SUPPORTED_FEATURES);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
CHECK_EQUAL(1007, context.remote_supported_features);
@ -107,10 +107,11 @@ TEST(HFPParser, HFP_HF_INDICATORS){
}
offset += snprintf(packet+offset, sizeof(packet)-offset, "\"%s\", (%d, %d)\r\n\r\nOK\r\n", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range);
context.command = HFP_CMD_RETRIEVE_AG_INDICATORS;
//context.command = HFP_CMD_RETRIEVE_AG_INDICATORS;
context.state = HFP_W4_RETRIEVE_INDICATORS;
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr);
@ -131,10 +132,11 @@ TEST(HFPParser, HFP_HF_INDICATOR_STATUS){
}
offset += snprintf(packet+offset, sizeof(packet)-offset, "%d\r\n\r\nOK\r\n", hfp_ag_indicators[pos].status);
context.command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
//context.command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
context.state = HFP_W4_RETRIEVE_INDICATORS_STATUS;
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
@ -147,7 +149,7 @@ TEST(HFPParser, HFP_HF_INDICATOR_STATUS){
TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES){
sprintf(packet, "\r\n%s:(1,1x,2,2x,3)\r\n\r\nOK\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
CHECK_EQUAL(5, context.remote_call_services_nr);
@ -161,10 +163,11 @@ TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES){
TEST(HFPParser, HFP_HF_GENERIC_STATUS_INDICATOR){
sprintf(packet, "\r\n%s:0,1,2,3,4\r\n\r\nOK\r\n", HFP_GENERIC_STATUS_INDICATOR);
context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS;
//context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS;
context.state = HFP_W4_RETRIEVE_GENERIC_STATUS_INDICATORS;
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
@ -177,10 +180,11 @@ TEST(HFPParser, HFP_HF_GENERIC_STATUS_INDICATOR){
TEST(HFPParser, HFP_HF_GENERIC_STATUS_INDICATOR_STATE){
sprintf(packet, "\r\n%s:0,1\r\n\r\nOK\r\n", HFP_GENERIC_STATUS_INDICATOR);
context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
// context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
context.state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
@ -196,7 +200,7 @@ TEST(HFPParser, HFP_HF_AG_INDICATOR_STATUS_UPDATE){
sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
@ -209,7 +213,7 @@ TEST(HFPParser, HFP_HF_AG_QUERY_OPERATOR_SELECTION){
context.command = HFP_CMD_QUERY_OPERATOR_SELECTION_NAME;
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(context.command, HFP_CMD_OK);
@ -221,7 +225,7 @@ TEST(HFPParser, HFP_HF_ERROR){
sprintf(packet, "\r\n%s\r\n", HFP_ERROR);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(context.command, HFP_CMD_ERROR);
@ -231,7 +235,7 @@ TEST(HFPParser, HFP_HF_EXTENDED_AUDIO_GATEWAY_ERROR){
sprintf(packet, "\r\n%s:%d\r\n", HFP_EXTENDED_AUDIO_GATEWAY_ERROR, HFP_CME_ERROR_NO_NETWORK_SERVICE);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(context.command, HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR);
@ -248,7 +252,7 @@ TEST(HFPParser, HFP_HF_AG_INDICATOR_CALLS_STATUS_UPDATE){
uint8_t index = call_status_index;
sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
CHECK_EQUAL(context.ag_indicators[index - 1].status, status);
@ -257,7 +261,7 @@ TEST(HFPParser, HFP_HF_AG_INDICATOR_CALLS_STATUS_UPDATE){
index = callsetup_status_index;
sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
CHECK_EQUAL(context.ag_indicators[index - 1].status, status);
@ -266,7 +270,7 @@ TEST(HFPParser, HFP_HF_AG_INDICATOR_CALLS_STATUS_UPDATE){
index = callheld_status_index;
sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
for (pos = 0; pos < strlen(packet); pos++){
hfp_parse(&context, packet[pos]);
hfp_parse(&context, packet[pos], 1);
}
CHECK_EQUAL(HFP_CMD_OK, context.command);
CHECK_EQUAL(context.ag_indicators[index - 1].status, status);