write test for hfp ag codecs connection

This commit is contained in:
Milanka Ringwald 2015-10-23 22:41:31 +02:00
parent 588953c14f
commit 62656e3397
6 changed files with 237 additions and 174 deletions

View File

@ -628,6 +628,7 @@ void process_command(hfp_connection_t * context){
if (strncmp((char *)context->line_buffer+offset, HFP_AVAILABLE_CODECS, strlen(HFP_AVAILABLE_CODECS)) == 0){ if (strncmp((char *)context->line_buffer+offset, HFP_AVAILABLE_CODECS, strlen(HFP_AVAILABLE_CODECS)) == 0){
context->command = HFP_CMD_AVAILABLE_CODECS; context->command = HFP_CMD_AVAILABLE_CODECS;
context->notify_ag_on_new_codecs = 1;
return; return;
} }
@ -700,10 +701,10 @@ void process_command(hfp_connection_t * context){
// printf("HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP update command\n"); // printf("HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP update command\n");
if (isHandsFree){ if (isHandsFree){
context->hf_trigger_codec_connection_setup = 1; context->hf_trigger_codec_connection_setup = 1;
printf("TRIGGER_CODEC_CONNECTION_SETUP hf_trigger_codec_connection_setup = 1\n"); printf("update command: hf_trigger_codec_connection_setup = 1\n");
} else { } else {
context->hf_trigger_codec_connection_setup = 1; context->hf_trigger_codec_connection_setup = 1;
printf("TRIGGER_CODEC_CONNECTION_SETUP hf_trigger_codec_connection_setup = 1\n"); printf("update command: hf_trigger_codec_connection_setup = 1\n");
} }
return; return;
} }
@ -842,18 +843,18 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
switch (context->command){ switch (context->command){
case HFP_CMD_HF_CONFIRMED_CODEC: case HFP_CMD_HF_CONFIRMED_CODEC:
context->codec_confirmed = atoi((char*)context->line_buffer); context->codec_confirmed = atoi((char*)context->line_buffer);
printf("hfp parse HFP_CMD_HF_CONFIRMED_CODEC %d\n", context->codec_confirmed); log_info("hfp parse HFP_CMD_HF_CONFIRMED_CODEC %d\n", context->codec_confirmed);
break; break;
case HFP_CMD_AG_SUGGESTED_CODEC: case HFP_CMD_AG_SUGGESTED_CODEC:
context->suggested_codec = atoi((char*)context->line_buffer); context->suggested_codec = atoi((char*)context->line_buffer);
printf("hfp parse HFP_CMD_AG_SUGGESTED_CODEC %d\n", context->suggested_codec); log_info("hfp parse HFP_CMD_AG_SUGGESTED_CODEC %d\n", context->suggested_codec);
break; break;
case HFP_CMD_SUPPORTED_FEATURES: case HFP_CMD_SUPPORTED_FEATURES:
context->remote_supported_features = atoi((char*)context->line_buffer); context->remote_supported_features = atoi((char*)context->line_buffer);
printf("Parsed supported feature %d\n", context->remote_supported_features); log_info("Parsed supported feature %d\n", context->remote_supported_features);
break; break;
case HFP_CMD_AVAILABLE_CODECS: case HFP_CMD_AVAILABLE_CODECS:
printf("Parsed codec %s\n", context->line_buffer); log_info("Parsed codec %s\n", context->line_buffer);
context->remote_codecs[context->parser_item_index] = (uint16_t)atoi((char*)context->line_buffer); context->remote_codecs[context->parser_item_index] = (uint16_t)atoi((char*)context->line_buffer);
context->parser_item_index++; context->parser_item_index++;
context->remote_codecs_nr = context->parser_item_index; context->remote_codecs_nr = context->parser_item_index;
@ -862,11 +863,11 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
if (context->retrieve_ag_indicators == 1){ if (context->retrieve_ag_indicators == 1){
strcpy((char *)context->ag_indicators[context->parser_item_index].name, (char *)context->line_buffer); strcpy((char *)context->ag_indicators[context->parser_item_index].name, (char *)context->line_buffer);
context->ag_indicators[context->parser_item_index].index = context->parser_item_index+1; context->ag_indicators[context->parser_item_index].index = context->parser_item_index+1;
printf("Indicator %d: %s (", context->ag_indicators_nr+1, context->line_buffer); log_info("Indicator %d: %s (", context->ag_indicators_nr+1, context->line_buffer);
} }
if (context->retrieve_ag_indicators_status == 1){ if (context->retrieve_ag_indicators_status == 1){
printf("Parsed Indicator %d with status: %s\n", context->parser_item_index+1, context->line_buffer); log_info("Parsed Indicator %d with status: %s\n", context->parser_item_index+1, context->line_buffer);
context->ag_indicators[context->parser_item_index].status = atoi((char *) context->line_buffer); context->ag_indicators[context->parser_item_index].status = atoi((char *) context->line_buffer);
context->parser_item_index++; context->parser_item_index++;
break; break;
@ -875,32 +876,32 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
case HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE: case HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE:
context->parser_item_index++; context->parser_item_index++;
if (context->parser_item_index != 4) break; if (context->parser_item_index != 4) break;
printf("Parsed Enable indicators: %s\n", context->line_buffer); log_info("Parsed Enable indicators: %s\n", context->line_buffer);
value = atoi((char *)&context->line_buffer[0]); value = atoi((char *)&context->line_buffer[0]);
context->enable_status_update_for_ag_indicators = (uint8_t) value; context->enable_status_update_for_ag_indicators = (uint8_t) value;
break; break;
case HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES: case HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES:
printf("Parsed Support call hold: %s\n", context->line_buffer); log_info("Parsed Support call hold: %s\n", context->line_buffer);
if (context->line_size > 2 ) break; if (context->line_size > 2 ) break;
strcpy((char *)context->remote_call_services[context->remote_call_services_nr].name, (char *)context->line_buffer); strcpy((char *)context->remote_call_services[context->remote_call_services_nr].name, (char *)context->line_buffer);
context->remote_call_services_nr++; context->remote_call_services_nr++;
break; break;
case HFP_CMD_GENERIC_STATUS_INDICATOR: case HFP_CMD_GENERIC_STATUS_INDICATOR:
printf("parser HFP_CMD_GENERIC_STATUS_INDICATOR 1 (%d, %d, %d)\n", log_info("parser HFP_CMD_GENERIC_STATUS_INDICATOR 1 (%d, %d, %d)\n",
context->list_generic_status_indicators, context->list_generic_status_indicators,
context->retrieve_generic_status_indicators, context->retrieve_generic_status_indicators,
context->retrieve_generic_status_indicators_state); context->retrieve_generic_status_indicators_state);
if (context->retrieve_generic_status_indicators == 1 || context->list_generic_status_indicators == 1){ if (context->retrieve_generic_status_indicators == 1 || context->list_generic_status_indicators == 1){
printf("Parsed Generic status indicator: %s\n", context->line_buffer); log_info("Parsed Generic status indicator: %s\n", context->line_buffer);
context->generic_status_indicators[context->parser_item_index].uuid = (uint16_t)atoi((char*)context->line_buffer); context->generic_status_indicators[context->parser_item_index].uuid = (uint16_t)atoi((char*)context->line_buffer);
context->parser_item_index++; context->parser_item_index++;
context->generic_status_indicators_nr = context->parser_item_index; context->generic_status_indicators_nr = context->parser_item_index;
break; break;
} }
printf("parser HFP_CMD_GENERIC_STATUS_INDICATOR 2\n"); log_info("parser HFP_CMD_GENERIC_STATUS_INDICATOR 2\n");
if (context->retrieve_generic_status_indicators_state == 1){ if (context->retrieve_generic_status_indicators_state == 1){
// HF parses inital AG gen. ind. state // HF parses inital AG gen. ind. state
printf("Parsed List generic status indicator %s state: ", context->line_buffer); log_info("Parsed List generic status indicator %s state: ", context->line_buffer);
context->parser_item_index = (uint8_t)atoi((char*)context->line_buffer); context->parser_item_index = (uint8_t)atoi((char*)context->line_buffer);
break; break;
} }
@ -908,7 +909,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
case HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE: case HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE:
// AG parses new gen. ind. state // AG parses new gen. ind. state
printf("Parsed Enable ag indicator state: %s\n", context->line_buffer); log_info("Parsed Enable ag indicator state: %s\n", context->line_buffer);
value = atoi((char *)&context->line_buffer[0]); value = atoi((char *)&context->line_buffer[0]);
if (!context->ag_indicators[context->parser_item_index].mandatory){ if (!context->ag_indicators[context->parser_item_index].mandatory){
context->ag_indicators[context->parser_item_index].enabled = value; context->ag_indicators[context->parser_item_index].enabled = value;
@ -918,22 +919,22 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){
case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS: case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS:
// indicators are indexed starting with 1 // indicators are indexed starting with 1
context->parser_item_index = atoi((char *)&context->line_buffer[0]) - 1; context->parser_item_index = atoi((char *)&context->line_buffer[0]) - 1;
printf("Parsed status of the AG indicator %d, status ", context->parser_item_index); log_info("Parsed status of the AG indicator %d, status ", context->parser_item_index);
break; break;
case HFP_CMD_QUERY_OPERATOR_SELECTION: case HFP_CMD_QUERY_OPERATOR_SELECTION:
if (context->operator_name_format == 1){ if (context->operator_name_format == 1){
if (context->line_buffer[0] == '3'){ if (context->line_buffer[0] == '3'){
printf("Parsed Set network operator format : %s, ", context->line_buffer); log_info("Parsed Set network operator format : %s, ", context->line_buffer);
break; break;
} }
// TODO emit ERROR, wrong format // TODO emit ERROR, wrong format
printf("ERROR Set network operator format: index %s not supported\n", context->line_buffer); log_info("ERROR Set network operator format: index %s not supported\n", context->line_buffer);
break; break;
} }
if (context->operator_name == 1) { if (context->operator_name == 1) {
context->network_operator.mode = atoi((char *)&context->line_buffer[0]); context->network_operator.mode = atoi((char *)&context->line_buffer[0]);
printf("Parsed network operator mode: %d, ", context->network_operator.mode); log_info("Parsed network operator mode: %d, ", context->network_operator.mode);
break; break;
} }
break; break;

View File

@ -364,7 +364,7 @@ static uint8_t hfp_ag_suggest_codec(hfp_connection_t *context){
static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * context){ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * context){
if (context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return; if (context->state >= HFP_CODECS_CONNECTION_ESTABLISHED) return;
printf(" AG run for context_service_level_connection \n"); printf(" AG run for context_service_level_connection \n");
switch(context->command){ switch(context->command){
@ -388,6 +388,12 @@ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * c
hfp_ag_retrieve_codec_cmd(context->rfcomm_cid); hfp_ag_retrieve_codec_cmd(context->rfcomm_cid);
context->state = HFP_W4_RETRIEVE_INDICATORS; context->state = HFP_W4_RETRIEVE_INDICATORS;
break; break;
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
context->suggested_codec = hfp_ag_suggest_codec(context);
printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec);
hfp_ag_ok(context->rfcomm_cid);
break;
default: default:
break; break;
} }
@ -423,9 +429,6 @@ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * c
context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0); hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0);
break; break;
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
// TODO
break;
default: default:
break; break;
} }
@ -470,76 +473,102 @@ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * c
break; break;
} }
break; break;
default:
break;
}
}
static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * context){
if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
int done = 0;
printf(" SLC queries: ");
switch(context->command){
case HFP_CMD_AVAILABLE_CODECS:
context->suggested_codec = hfp_ag_suggest_codec(context);
printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec);
hfp_ag_ok(context->rfcomm_cid);
done = 1;
break;
case HFP_CMD_QUERY_OPERATOR_SELECTION: case HFP_CMD_QUERY_OPERATOR_SELECTION:
if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) break;
if (context->operator_name_format == 1){ if (context->operator_name_format == 1){
if (context->network_operator.format != 0){ if (context->network_operator.format != 0){
hfp_ag_error(context->rfcomm_cid); hfp_ag_error(context->rfcomm_cid);
done = 1;
break; break;
} }
hfp_ag_ok(context->rfcomm_cid); hfp_ag_ok(context->rfcomm_cid);
done = 1;
context->operator_name_format = 0; context->operator_name_format = 0;
break; break;
} }
if (context->operator_name == 1){ if (context->operator_name == 1){
hfp_ag_report_network_operator_name_cmd(context->rfcomm_cid, context->network_operator); hfp_ag_report_network_operator_name_cmd(context->rfcomm_cid, context->network_operator);
context->operator_name = 0; context->operator_name = 0;
done = 1;
break; break;
} }
break; break;
default: case HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE:{
break; int i;
} for (i = 0; i < context->ag_indicators_nr; i++){
} if (context->ag_indicators[i].enabled == 0) continue;
if (context->ag_indicators[i].status_changed == 0) continue;
static void hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * context){ hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, context->ag_indicators[i]);
if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return; done = 1;
context->ag_indicators[i].status_changed = 0;
printf(" AG run for service_level_connection_queries \n"); return done;
if (context->enable_status_update_for_ag_indicators){ }
int i; break;
for (i = 0; i < context->ag_indicators_nr; i++){
if (context->ag_indicators[i].enabled == 0) continue;
if (context->ag_indicators[i].status_changed == 0) continue;
hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, context->ag_indicators[i]);
context->ag_indicators[i].status_changed = 0;
return;
}
}
if (context->enable_extended_audio_gateway_error_report){
if (context->extended_audio_gateway_error){
hfp_ag_report_extended_audio_gateway_error(context->rfcomm_cid, context->extended_audio_gateway_error);
context->extended_audio_gateway_error = 0;
return;
}
}
}
static void hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
if (context->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return;
if (context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return;
printf(" AG run for context_codecs_connection \n");
switch (context->state){
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
if (context->notify_ag_on_new_codecs){ // received BAC
printf(" received BAC \n");
context->notify_ag_on_new_codecs = 0;
context->suggested_codec = hfp_ag_suggest_codec(context);
hfp_ag_ok(context->rfcomm_cid);
return;
} }
case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP:
if (context->hf_trigger_codec_connection_setup){ // received BCC if (context->hf_trigger_codec_connection_setup){ // received BCC
printf(" received BCC \n"); printf(" received BCC \n");
context->hf_trigger_codec_connection_setup = 0; context->hf_trigger_codec_connection_setup = 0;
context->ag_trigger_codec_connection_setup = 1; context->ag_trigger_codec_connection_setup = 1;
context->state = HFP_SLE_W2_EXCHANGE_COMMON_CODEC;
hfp_ag_ok(context->rfcomm_cid); hfp_ag_ok(context->rfcomm_cid);
return; done = 1;
return done;
} }
if (context->ag_trigger_codec_connection_setup){ // received BCS
printf(" send BCS \n");
context->ag_trigger_codec_connection_setup = 0;
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
context->suggested_codec = hfp_ag_suggest_codec(context);
hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec);
done = 1;
return done;
}
break;
case HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR:
if (context->extended_audio_gateway_error){
hfp_ag_report_extended_audio_gateway_error(context->rfcomm_cid, context->extended_audio_gateway_error);
context->extended_audio_gateway_error = 0;
done = 1;
break;
}
case HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE:
printf("TODO\n");
break;
default:
break;
}
return done;
}
static void hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
if (context->state <= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return;
if (context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return;
printf(" AG run for context_codecs_connection: ");
switch (context->state){
case HFP_SLE_W2_EXCHANGE_COMMON_CODEC:
if (context->ag_trigger_codec_connection_setup){ // received BCS if (context->ag_trigger_codec_connection_setup){ // received BCS
printf(" send BCS \n"); printf(" send BCS \n");
context->ag_trigger_codec_connection_setup = 0; context->ag_trigger_codec_connection_setup = 0;
@ -548,80 +577,71 @@ static void hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context)
hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec); hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec);
return; return;
} }
break; break;
case HFP_SLE_W4_EXCHANGE_COMMON_CODEC: case HFP_SLE_W4_EXCHANGE_COMMON_CODEC:
if (context->notify_ag_on_new_codecs){ // received BAC switch(context->command){
context->notify_ag_on_new_codecs = 0; case HFP_CMD_AVAILABLE_CODECS:
if (context->suggested_codec != hfp_ag_suggest_codec(context)){ if (context->notify_ag_on_new_codecs){ // received BAC
context->suggested_codec = hfp_ag_suggest_codec(context); printf(" received BAC\n");
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; context->notify_ag_on_new_codecs = 0;
} if (context->suggested_codec != hfp_ag_suggest_codec(context)){
hfp_ag_ok(context->rfcomm_cid); context->suggested_codec = hfp_ag_suggest_codec(context);
return; context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
} }
hfp_ag_ok(context->rfcomm_cid);
if (context->codec_confirmed != context->suggested_codec){ return;
context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; }
hfp_ag_error(context->rfcomm_cid); break;
return; case HFP_CMD_HF_CONFIRMED_CODEC:
} printf(" received AT+BCS\n");
context->negotiated_codec = context->codec_confirmed; if (context->codec_confirmed != context->suggested_codec){
context->state = HFP_CODECS_CONNECTION_ESTABLISHED; context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
hfp_ag_ok(context->rfcomm_cid); hfp_ag_error(context->rfcomm_cid);
hfp_emit_event(hfp_callback, HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE, 0); return;
return; }
context->negotiated_codec = context->codec_confirmed;
case HFP_CODECS_CONNECTION_ESTABLISHED: context->state = HFP_CODECS_CONNECTION_ESTABLISHED;
if (context->notify_ag_on_new_codecs){ // received BAC hfp_emit_event(hfp_callback, HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE, 0);
context->notify_ag_on_new_codecs = 0; hfp_ag_ok(context->rfcomm_cid);
if (context->suggested_codec != hfp_ag_suggest_codec(context)){ break;
context->suggested_codec = hfp_ag_suggest_codec(context); default:
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; break;
}
hfp_ag_ok(context->rfcomm_cid);
return;
}
if (context->ag_trigger_codec_connection_setup){
context->ag_trigger_codec_connection_setup = 0;
if (context->negotiated_codec != hfp_ag_suggest_codec(context)){
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
context->suggested_codec = hfp_ag_suggest_codec(context);
hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec);
}
} }
break; break;
case HFP_CODECS_CONNECTION_ESTABLISHED:
switch(context->command){
case HFP_CMD_AVAILABLE_CODECS:
if (context->notify_ag_on_new_codecs){ // received BAC
context->notify_ag_on_new_codecs = 0;
if (context->suggested_codec != hfp_ag_suggest_codec(context)){
context->suggested_codec = hfp_ag_suggest_codec(context);
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
}
hfp_ag_ok(context->rfcomm_cid);
return;
}
break;
case HFP_CMD_AG_SUGGESTED_CODEC:
if (context->ag_trigger_codec_connection_setup){
context->ag_trigger_codec_connection_setup = 0;
if (context->negotiated_codec != hfp_ag_suggest_codec(context)){
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
context->suggested_codec = hfp_ag_suggest_codec(context);
hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec);
}
}
break;
default:
break;
}
default: default:
break; break;
} }
switch(context->command){
// START codec setup
case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP:
switch (context->state){
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec);
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
break;
default:
hfp_ag_error(context->rfcomm_cid);
break;
}
break;
case HFP_CMD_AVAILABLE_CODECS:
switch(context->state){
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
case HFP_SLE_W2_EXCHANGE_COMMON_CODEC:
case HFP_SLE_W4_EXCHANGE_COMMON_CODEC:
context->notify_ag_on_new_codecs = 1;
break;
default:
break;
}
break;
default:
break;
}
} }
@ -642,13 +662,13 @@ void hfp_run_for_context(hfp_connection_t *context){
context->send_error = 0; context->send_error = 0;
return; return;
} }
int done;
if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
hfp_ag_run_for_context_service_level_connection(context); hfp_ag_run_for_context_service_level_connection(context);
if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
hfp_ag_run_for_context_service_level_connection_queries(context); done = hfp_ag_run_for_context_service_level_connection_queries(context);
if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; if (!rfcomm_can_send_packet_now(context->rfcomm_cid) || done) return;
hfp_ag_run_for_context_codecs_connection(context); hfp_ag_run_for_context_codecs_connection(context);
if (context->command == HFP_CMD_NONE){ if (context->command == HFP_CMD_NONE){
@ -697,7 +717,6 @@ static void hfp_run(){
static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type){ switch (packet_type){
case RFCOMM_DATA_PACKET: case RFCOMM_DATA_PACKET:
printf("\nAG received: %s", packet);
hfp_handle_rfcomm_event(packet_type, channel, packet, size); hfp_handle_rfcomm_event(packet_type, channel, packet, size);
break; break;
case HCI_EVENT_PACKET: case HCI_EVENT_PACKET:

View File

@ -606,7 +606,7 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
packet[size] = 0; packet[size] = 0;
int pos, i; int pos, i;
printf("AG response: %s\n", packet+2); printf("\nHF received: %s", packet+2);
for (pos = 0; pos < size ; pos++){ for (pos = 0; pos < size ; pos++){
hfp_parse(context, packet[pos]); hfp_parse(context, packet[pos]);
@ -649,7 +649,6 @@ static void hfp_run(){
static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type){ switch (packet_type){
case RFCOMM_DATA_PACKET: case RFCOMM_DATA_PACKET:
printf("\nHF received: %s\n", packet);
hfp_handle_rfcomm_event(packet_type, channel, packet, size); hfp_handle_rfcomm_event(packet_type, channel, packet, size);
break; break;
case HCI_EVENT_PACKET: case HCI_EVENT_PACKET:

View File

@ -113,12 +113,12 @@ int expected_rfcomm_command(const char * expected_cmd){
return 0; return 0;
} }
#define HFP_NOP_CMD ""
void simulate_test_sequence(char ** test_steps, int nr_test_steps){ void simulate_test_sequence(char ** test_steps, int nr_test_steps){
int i = 0; int i = 0;
for (i=0; i < nr_test_steps; i++){ for (i=0; i < nr_test_steps; i++){
char * cmd = test_steps[i]; char * cmd = test_steps[i];
printf(" test step %d %s\n", i, cmd); printf("\n --> Test step %d: ", i);
if (memcmp(cmd, "AT", 2) == 0){ if (memcmp(cmd, "AT", 2) == 0){
inject_rfcomm_command_to_ag((uint8_t*)cmd, strlen(cmd)); inject_rfcomm_command_to_ag((uint8_t*)cmd, strlen(cmd));
} else if (memcmp(cmd, "NOP", 3) == 0){ } else if (memcmp(cmd, "NOP", 3) == 0){
@ -127,10 +127,11 @@ void simulate_test_sequence(char ** test_steps, int nr_test_steps){
} else { } else {
int expected_cmd = expected_rfcomm_command(cmd); int expected_cmd = expected_rfcomm_command(cmd);
if (!expected_cmd){ if (!expected_cmd){
printf("\nError: Expected:'%s', but got:'%s'", cmd, (char *)get_rfcomm_payload()); printf("\nError: Expected:'%s', but got:'%s'\n", cmd, (char *)get_rfcomm_payload());
CHECK_EQUAL(expected_cmd,1);
return; return;
} }
printf("AG response verified %s\n", cmd); printf("AG response verified %s\n\n", cmd);
} }
} }
} }
@ -144,13 +145,13 @@ void packet_handler(uint8_t * event, uint16_t event_size){
switch (event[2]) { switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
printf("\n\n\n\n ** SLC established **\n\n\n\n\n"); printf("\n** SLC established **\n\n");
service_level_connection_established = 1; service_level_connection_established = 1;
codecs_connection_established = 0; codecs_connection_established = 0;
audio_connection_established = 0; audio_connection_established = 0;
break; break;
case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE: case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE:
printf("\n\n\n\n ** CC established **\n\n\n\n\n"); printf("\n** CC established **\n\n");
codecs_connection_established = 1; codecs_connection_established = 1;
audio_connection_established = 0; audio_connection_established = 0;
break; break;
@ -179,6 +180,8 @@ TEST_GROUP(HFPClient){
if (service_level_connection_established){ if (service_level_connection_established){
hfp_ag_release_service_level_connection(device_addr); hfp_ag_release_service_level_connection(device_addr);
CHECK_EQUAL(service_level_connection_released, 1); CHECK_EQUAL(service_level_connection_released, 1);
service_level_connection_established = 0;
service_level_connection_released = 0;
} }
} }
@ -190,28 +193,34 @@ TEST_GROUP(HFPClient){
void setup_hfp_codecs_connection(char ** test_steps, int nr_test_steps){ void setup_hfp_codecs_connection(char ** test_steps, int nr_test_steps){
codecs_connection_established = 0; codecs_connection_established = 0;
//hfp_ag_negotiate_codecs(device_addr);
simulate_test_sequence((char **) test_steps, nr_test_steps); simulate_test_sequence((char **) test_steps, nr_test_steps);
} }
}; };
TEST(HFPClient, HFCodecsConnectionEstablished){ TEST(HFPClient, HFCodecsConnectionEstablished){
setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size());
CHECK_EQUAL(service_level_connection_established, 1);
for (int i = 0; i < cc_tests_size(); i++){ for (int i = 0; i < cc_tests_size(); i++){
service_level_connection_established = 0;
setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size());
CHECK_EQUAL(service_level_connection_established, 1);
setup_hfp_codecs_connection(hfp_cc_tests()[i].test, hfp_cc_tests()[i].len); setup_hfp_codecs_connection(hfp_cc_tests()[i].test, hfp_cc_tests()[i].len);
CHECK_EQUAL(codecs_connection_established, 1); CHECK_EQUAL(codecs_connection_established, 1);
teardown();
} }
} }
// TEST(HFPClient, HFServiceLevelConnectionCommands){ // TEST(HFPClient, HFServiceLevelConnectionCommands){
// service_level_connection_established = 0;
// setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size()); // setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size());
// CHECK_EQUAL(service_level_connection_established, 1);
// for (int i = 0; i < slc_cmds_tests_size(); i++){ // for (int i = 0; i < slc_cmds_tests_size(); i++){
// simulate_test_sequence(hfp_slc_cmds_tests()[i].test, hfp_slc_cmds_tests()[i].len); // simulate_test_sequence(hfp_slc_cmds_tests()[i].test, hfp_slc_cmds_tests()[i].len);
// } // }
// CHECK_EQUAL(service_level_connection_established, 1);
// } // }
// TEST(HFPClient, HFServiceLevelConnectionEstablished){ // TEST(HFPClient, HFServiceLevelConnectionEstablished){

View File

@ -103,12 +103,30 @@ static void prepare_rfcomm_buffer(uint8_t * data, int len){
rfcomm_payload_len = pos; rfcomm_payload_len = pos;
} }
static void print_without_newlines(uint8_t *data, uint16_t len){
int found_newline = 0;
int found_item = 0;
printf("\n");
for (int i=0; i<len; i++){
if (data[i] == '\r' || data[i] == '\n'){
if (!found_newline && found_item) printf("\n");
found_newline = 1;
} else {
printf("%c", data[i]);
found_newline = 0;
found_item = 1;
}
}
printf("\n");
}
int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){ int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
if (strncmp((char*)data, "AT", 2) == 0){ if (strncmp((char*)data, "AT", 2) == 0){
printf("Verify HF state machine response: %s", data); printf("Verify HF state machine response: ");
print_without_newlines(data,len);
} else { } else {
printf("Verify AG state machine response: %s", data+2); printf("Verify AG state machine response: ");
print_without_newlines(data,len);
} }
strncpy((char*)&rfcomm_payload[0], (char*)data, len); strncpy((char*)&rfcomm_payload[0], (char*)data, len);
rfcomm_payload_len = len; rfcomm_payload_len = len;
@ -216,9 +234,9 @@ void inject_rfcomm_command_to_hf(uint8_t * data, int len){
prepare_rfcomm_buffer(data, len); prepare_rfcomm_buffer(data, len);
if (data[0] == '+'){ if (data[0] == '+'){
printf("\n\n ---> Send cmd to HF state machine: %s", data); printf("Send cmd to HF state machine: %s", data);
} else { } else {
printf("\n\n ---> trigger HF state machine: %s", data); printf("Trigger HF state machine: %s", data);
} }
(*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len); (*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len);
} }
@ -228,9 +246,9 @@ void inject_rfcomm_command_to_ag(uint8_t * data, int len){
prepare_rfcomm_buffer(data, len); prepare_rfcomm_buffer(data, len);
if (memcmp((char*)data, "AT", 2) == 0){ if (memcmp((char*)data, "AT", 2) == 0){
printf("\n\n ---> Send cmd to AG state machine: %s", data); printf("Send cmd to AG state machine: %s\n", data);
} else { } else {
printf("\n\n ---> trigger AG state machine: %s", data); printf("Trigger AG state machine: %s", data);
} }
(*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len); (*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len);
} }

View File

@ -82,6 +82,26 @@ const char * slc_cmds_test1[] = {
"OK" "OK"
}; };
const char * slc_cmds_test2[] = {
"AT+BAC=1,3",
"OK"
};
const char * slc_cmds_test3[] = {
"AT+BAC=1,3",
"OK"
};
const char * slc_cmds_test4[] = {
"AT+BAC=1,3",
"OK"
};
const char * slc_cmds_test5[] = {
"AT+BAC=1,3",
"OK"
};
hfp_test_item_t slc_cmds_tests[] = { hfp_test_item_t slc_cmds_tests[] = {
TEST_SEQUENCE(slc_cmds_test1) TEST_SEQUENCE(slc_cmds_test1)
}; };
@ -89,58 +109,55 @@ hfp_test_item_t slc_cmds_tests[] = {
const char * cc_test1[] = { const char * cc_test1[] = {
"AT+BCC", "AT+BCC",
"OK", "OK",
"NOP",
"+BCS:1", "+BCS:1",
"AT+BCS=1", "AT+BCS=1",
"OK" "OK"
}; };
const char * cc_test2[] = { const char * cc_test2[] = {
"AT+BCC", "AT+BAC=1,2",
"OK",
"AT+BCC",
"OK", "OK",
"NOP",
"NOP+BCS:1", "NOP+BCS:1",
"AT+BCS=1", "AT+BCS=1",
"OK" "OK"
}; };
const char * cc_test3[] = { const char * cc_test3[] = {
"AT+BAC=1,2", "AT+BAC=1,2",
"OK", "OK",
"AT+BCC", "AT+BCC",
"OK", "OK",
"+BCS:1", "NOP",
"AT+BCS=1",
"OK"
};
const char * cc_test4[] = {
"AT+BAC=1,2",
"OK",
"AT+BCC",
"OK",
"+BCS:1", "+BCS:1",
"AT+BAC=2,3", "AT+BAC=2,3",
"OK", "OK",
"NOP",
"+BCS:2", "+BCS:2",
"AT+BCS=2", "AT+BCS=2",
"OK" "OK"
}; };
const char * cc_test5[] = { const char * cc_test4[] = {
"AT+BCC", "AT+BCC",
"OK", "OK",
"NOP",
"+BCS:1", "+BCS:1",
"AT+BAC=2,3", "AT+BAC=2,3",
"OK", "OK",
"NOP",
"+BCS:2", "+BCS:2",
"AT+BCS=2", "AT+BCS=2",
"OK" "OK"
}; };
hfp_test_item_t cc_tests[] = { hfp_test_item_t cc_tests[] = {
TEST_SEQUENCE(cc_test1)//, TEST_SEQUENCE(cc_test1),
// TEST_SEQUENCE(cc_test2), TEST_SEQUENCE(cc_test2),
// TEST_SEQUENCE(cc_test3),
// TEST_SEQUENCE(cc_test3) // TEST_SEQUENCE(cc_test3)
}; };