hfp hf test: use get_next_hfp_cmd

This commit is contained in:
Milanka Ringwald 2015-12-04 11:56:18 +01:00
parent d5deed0388
commit 3723a70091
7 changed files with 501 additions and 288 deletions

View File

@ -1037,8 +1037,6 @@ void hfp_hf_set_codecs(uint8_t * codecs, int codecs_nr){
char buffer[30];
int offset = join(buffer, sizeof(buffer), hfp_codecs, hfp_codecs_nr);
buffer[offset] = 0;
printf("set codecs %s\n", buffer);
linked_list_iterator_t it;
linked_list_iterator_init(&it, hfp_get_connections());
while (linked_list_iterator_has_next(&it)){

View File

@ -85,7 +85,6 @@ static hfp_ag_indicator_t ag_indicators[] = {
};
static int supported_features_with_codec_negotiation = 4079; // 0011 1110 1111
static int supported_features_without_codec_negotiation = 495; // 0001 1110 1111
static int call_hold_services_nr = 5;
static const char* call_hold_services[] = {"1", "1x", "2", "2x", "3"};
@ -298,7 +297,6 @@ static void user_command(char cmd){
hfp_ag_reject_held_incoming_call();
break;
default:
// show_usage();
printf("AG: undefined user command\n");
break;
}
@ -317,7 +315,7 @@ void simulate_test_sequence(hfp_test_item_t * test_item){
user_command(expected_cmd[5]);
i++;
} else if (strncmp(expected_cmd, "AT", 2) == 0){
printf("\n---> NEXT STEP receive from HF: '%s'\n", expected_cmd);
//printf("\n---> NEXT STEP receive from HF: '%s'\n", expected_cmd);
inject_hfp_command_to_ag((uint8_t*)expected_cmd, expected_cmd_len);
i++;
} else {
@ -434,89 +432,84 @@ TEST_GROUP(HFPClient){
}
};
TEST(HFPClient, PTSATATests){
for (int i = 0; i < hfp_pts_ag_ata_tests_size(); i++){
simulate_test_sequence(&hfp_pts_ag_ata_tests()[i]);
teardown();
}
}
// TEST(HFPClient, PTSATATests){
// for (int i = 0; i < hfp_pts_ag_ata_tests_size(); i++){
// simulate_test_sequence(&hfp_pts_ag_ata_tests()[i]);
// teardown();
// }
// }
TEST(HFPClient, PTSSLCTests){
for (int i = 0; i < hfp_pts_ag_slc_tests_size(); i++){
setup_hfp_service_level_connection(&hfp_pts_ag_slc_tests()[i]);
simulate_test_sequence(&hfp_pts_ag_slc_tests()[i]);
teardown();
}
}
TEST(HFPClient, HFAudioConnectionEstablishedWithCodecNegotiation){
setup_hfp_service_level_connection(default_hfp_slc_test());
CHECK_EQUAL(service_level_connection_established, 1);
// TEST(HFPClient, HFAudioConnectionEstablishedWithCodecNegotiation){
// setup_hfp_service_level_connection(default_hfp_slc_test());
// CHECK_EQUAL(service_level_connection_established, 1);
setup_hfp_codecs_connection(default_hfp_cc_test());
CHECK_EQUAL(codecs_connection_established, 1);
// setup_hfp_codecs_connection(default_hfp_cc_test());
// CHECK_EQUAL(codecs_connection_established, 1);
hfp_ag_establish_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 1);
// hfp_ag_establish_audio_connection(device_addr);
// CHECK_EQUAL(audio_connection_established, 1);
hfp_ag_release_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 0);
}
// hfp_ag_release_audio_connection(device_addr);
// CHECK_EQUAL(audio_connection_established, 0);
// }
TEST(HFPClient, HFAudioConnectionEstablishedWithoutCodecNegotiation){
hfp_ag_init(rfcomm_channel_nr, supported_features_without_codec_negotiation,
codecs, sizeof(codecs),
ag_indicators, ag_indicators_nr,
hf_indicators, hf_indicators_nr,
call_hold_services, call_hold_services_nr);
// TEST(HFPClient, HFAudioConnectionEstablishedWithoutCodecNegotiation){
// hfp_ag_init(rfcomm_channel_nr, supported_features_without_codec_negotiation,
// codecs, sizeof(codecs),
// ag_indicators, ag_indicators_nr,
// hf_indicators, hf_indicators_nr,
// call_hold_services, call_hold_services_nr);
setup_hfp_service_level_connection(&hfp_slc_tests()[1]);
CHECK_EQUAL(service_level_connection_established, 1);
// setup_hfp_service_level_connection(&hfp_slc_tests()[1]);
// CHECK_EQUAL(service_level_connection_established, 1);
setup_hfp_codecs_connection(default_hfp_cc_test());
CHECK_EQUAL(codecs_connection_established, 1);
// setup_hfp_codecs_connection(default_hfp_cc_test());
// CHECK_EQUAL(codecs_connection_established, 1);
hfp_ag_establish_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 1);
// hfp_ag_establish_audio_connection(device_addr);
// CHECK_EQUAL(audio_connection_established, 1);
hfp_ag_release_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 0);
}
// hfp_ag_release_audio_connection(device_addr);
// CHECK_EQUAL(audio_connection_established, 0);
// }
TEST(HFPClient, HFCodecsConnectionEstablished){
for (int i = 0; i < hfp_cc_tests_size(); i++){
setup_hfp_service_level_connection(default_hfp_slc_test());
CHECK_EQUAL(service_level_connection_established, 1);
// TEST(HFPClient, HFCodecsConnectionEstablished){
// for (int i = 0; i < hfp_cc_tests_size(); i++){
// setup_hfp_service_level_connection(default_hfp_slc_test());
// CHECK_EQUAL(service_level_connection_established, 1);
setup_hfp_codecs_connection(&hfp_cc_tests()[i]);
CHECK_EQUAL(codecs_connection_established, 1);
teardown();
}
}
// setup_hfp_codecs_connection(&hfp_cc_tests()[i]);
// CHECK_EQUAL(codecs_connection_established, 1);
// teardown();
// }
// }
TEST(HFPClient, HFServiceLevelConnectionCommands){
setup_hfp_service_level_connection(default_hfp_slc_test());
CHECK_EQUAL(service_level_connection_established, 1);
for (int i = 0; i < hfp_slc_cmds_tests_size(); i++){
simulate_test_sequence(&hfp_slc_cmds_tests()[i]);
}
}
// TEST(HFPClient, HFServiceLevelConnectionCommands){
// setup_hfp_service_level_connection(default_hfp_slc_test());
// CHECK_EQUAL(service_level_connection_established, 1);
// for (int i = 0; i < hfp_slc_cmds_tests_size(); i++){
// simulate_test_sequence(&hfp_slc_cmds_tests()[i]);
// }
// }
TEST(HFPClient, HFServiceLevelConnectionEstablishedWithoutCodecNegotiation){
hfp_ag_init(rfcomm_channel_nr, supported_features_without_codec_negotiation,
codecs, sizeof(codecs),
ag_indicators, ag_indicators_nr,
hf_indicators, hf_indicators_nr,
call_hold_services, call_hold_services_nr);
setup_hfp_service_level_connection(&hfp_slc_tests()[1]);
CHECK_EQUAL(service_level_connection_established, 1);
}
// TEST(HFPClient, HFServiceLevelConnectionEstablishedWithoutCodecNegotiation){
// hfp_ag_init(rfcomm_channel_nr, supported_features_without_codec_negotiation,
// codecs, sizeof(codecs),
// ag_indicators, ag_indicators_nr,
// hf_indicators, hf_indicators_nr,
// call_hold_services, call_hold_services_nr);
// setup_hfp_service_level_connection(&hfp_slc_tests()[1]);
// CHECK_EQUAL(service_level_connection_established, 1);
// }
TEST(HFPClient, HFServiceLevelConnectionEstablishedWithCodecNegotiation){
setup_hfp_service_level_connection(default_hfp_slc_test());
CHECK_EQUAL(service_level_connection_established, 1);
teardown();
}
int main (int argc, const char * argv[]){
hfp_ag_register_packet_handler(packet_handler);

View File

@ -71,7 +71,6 @@ const uint8_t rfcomm_channel_nr = 1;
static bd_addr_t device_addr = {0xD8,0xBb,0x2C,0xDf,0xF1,0x08};
static uint8_t codecs[2] = {1,2};
static uint8_t default_codecs[2] = {1};
static uint16_t indicators[1] = {0x01};
static uint8_t service_level_connection_established = 0;
@ -81,37 +80,9 @@ static uint8_t start_ringing = 0;
static uint8_t stop_ringing = 0;
static uint8_t call_termiated = 0;
static int supported_features_with_codec_negotiation = 438; // 0001 1011 0110
static int supported_features_without_codec_negotiation = 310; // 0001 0011 0110
static int supported_features_with_codec_negotiation = 438;
int expected_rfcomm_command(const char * cmd){
char * ag_cmd = (char *)get_rfcomm_payload();
int offset = 2;
int cmd_size = strlen(cmd);
int cmd_found = strncmp(ag_cmd+offset, cmd, cmd_size) == 0;
while (!cmd_found && get_rfcomm_payload_len() - cmd_size >= offset){
offset++;
cmd_found = strncmp(ag_cmd+offset, cmd, cmd_size) == 0;
}
if (!cmd_found) return 0;
// AG cmds that are not followed by OK
if (strncmp(ag_cmd+offset, "+BCS", 4) == 0){
return cmd_found;
}
offset += strlen(cmd)+4;
// printf("cmd found, offset %d, cmd %s\n", offset, ag_cmd+offset);
int ok_found = strncmp(ag_cmd+offset, "OK", 2) == 0;
while (!ok_found && get_rfcomm_payload_len() - 2 >= offset){
offset++;
// printf("cmd found, offset %d, cmd %s\n", offset, ag_cmd+offset);
ok_found = strncmp(ag_cmd+offset, "OK", 2) == 0;
}
// printf("cmd found, ok found %d\n", ok_found);
return cmd_found && ok_found;
}
static uint16_t handle = -1;
char * get_next_hfp_hf_command(){
return get_next_hfp_command(0,2);
@ -121,44 +92,309 @@ int has_more_hfp_hf_commands(){
return has_more_hfp_commands(0,2);
}
static void user_command(char cmd){
switch (cmd){
case '#':
case '-':
case '+':
case '*':
printf("DTMF Code: %c\n", cmd);
hfp_hf_send_dtmf_code(device_addr, cmd);
break;
case 'a':
printf("Establish Service level connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr));
hfp_hf_establish_service_level_connection(device_addr);
break;
case 'A':
printf("Release Service level connection.\n");
hfp_hf_release_service_level_connection(device_addr);
break;
case 'b':
printf("Establish Audio connection to device with Bluetooth address %s...\n", bd_addr_to_str(device_addr));
hfp_hf_establish_audio_connection(device_addr);
break;
case 'B':
printf("Release Audio service level connection.\n");
hfp_hf_release_audio_connection(device_addr);
break;
case 'C':
printf("Enable registration status update for all AG indicators.\n");
hfp_hf_enable_status_update_for_all_ag_indicators(device_addr);
case 'c':
printf("Disable registration status update for all AG indicators.\n");
hfp_hf_disable_status_update_for_all_ag_indicators(device_addr);
break;
case 'D':
printf("Set HFP AG registration status update for individual indicators (0111111).\n");
hfp_hf_set_status_update_for_individual_ag_indicators(device_addr, 63);
break;
case 'd':
printf("Query network operator.\n");
hfp_hf_query_operator_selection(device_addr);
break;
case 'E':
printf("Enable reporting of the extended AG error result code.\n");
hfp_hf_enable_report_extended_audio_gateway_error_result_code(device_addr);
break;
case 'e':
printf("Disable reporting of the extended AG error result code.\n");
hfp_hf_disable_report_extended_audio_gateway_error_result_code(device_addr);
break;
case 'f':
printf("Answer incoming call.\n");
hfp_hf_answer_incoming_call(device_addr);
break;
case 'F':
printf("Hangup call.\n");
hfp_hf_terminate_call(device_addr);
break;
case 'G':
printf("Reject call.\n");
hfp_hf_reject_call(device_addr);
break;
case 'g':
printf("Query operator.\n");
hfp_hf_query_operator_selection(device_addr);
break;
case 't':
printf("Terminate HCI connection.\n");
gap_disconnect(handle);
break;
case 'i':
printf("Dial 1234567\n");
hfp_hf_dial_number(device_addr, (char *)"1234567");
break;
case 'I':
printf("Dial 7654321\n");
hfp_hf_dial_number(device_addr, (char *)"7654321");
break;
case 'j':
printf("Dial #1\n");
hfp_hf_dial_memory(device_addr, (char *)"1");
break;
case 'J':
printf("Dial #99\n");
hfp_hf_dial_memory(device_addr, (char *)"99");
break;
case 'k':
printf("Deactivate call waiting notification\n");
hfp_hf_deactivate_call_waiting_notification(device_addr);
break;
case 'K':
printf("Activate call waiting notification\n");
hfp_hf_activate_call_waiting_notification(device_addr);
break;
case 'l':
printf("Deactivate calling line notification\n");
hfp_hf_deactivate_calling_line_notification(device_addr);
break;
case 'L':
printf("Activate calling line notification\n");
hfp_hf_activate_calling_line_notification(device_addr);
break;
case 'm':
printf("Deactivate echo canceling and noise reduction\n");
hfp_hf_deactivate_echo_canceling_and_noise_reduction(device_addr);
break;
case 'M':
printf("Activate echo canceling and noise reduction\n");
hfp_hf_activate_echo_canceling_and_noise_reduction(device_addr);
break;
case 'n':
printf("Deactivate voice recognition\n");
hfp_hf_deactivate_voice_recognition_notification(device_addr);
break;
case 'N':
printf("Activate voice recognition\n");
hfp_hf_activate_voice_recognition_notification(device_addr);
break;
case 'o':
printf("Set speaker gain to 0 (minimum)\n");
hfp_hf_set_speaker_gain(device_addr, 0);
break;
case 'O':
printf("Set speaker gain to 9 (default)\n");
hfp_hf_set_speaker_gain(device_addr, 9);
break;
case 'p':
printf("Set speaker gain to 12 (higher)\n");
hfp_hf_set_speaker_gain(device_addr, 12);
break;
case 'P':
printf("Set speaker gain to 15 (maximum)\n");
hfp_hf_set_speaker_gain(device_addr, 15);
break;
case 'q':
printf("Set microphone gain to 0\n");
hfp_hf_set_microphone_gain(device_addr, 0);
break;
case 'Q':
printf("Set microphone gain to 9\n");
hfp_hf_set_microphone_gain(device_addr, 9);
break;
case 's':
printf("Set microphone gain to 12\n");
hfp_hf_set_microphone_gain(device_addr, 12);
break;
case 'S':
printf("Set microphone gain to 15\n");
hfp_hf_set_microphone_gain(device_addr, 15);
break;
case 'u':
printf("Send 'user busy' (Three-Way Call 0)\n");
hfp_hf_user_busy(device_addr);
break;
case 'U':
printf("End active call and accept waiting/held call (Three-Way Call 1)\n");
hfp_hf_end_active_and_accept_other(device_addr);
break;
case 'v':
printf("Swap active call and hold/waiting call (Three-Way Call 2)\n");
hfp_hf_swap_calls(device_addr);
break;
case 'V':
printf("Join hold call (Three-Way Call 3)\n");
hfp_hf_join_held_call(device_addr);
break;
case 'w':
printf("Connect calls (Three-Way Call 4)\n");
hfp_hf_connect_calls(device_addr);
break;
case 'W':
printf("Redial\n");
hfp_hf_redial_last_number(device_addr);
break;
case 'x':
printf("Request phone number for voice tag\n");
hfp_hf_request_phone_number_for_voice_tag(device_addr);
break;
case 'X':
printf("Query current call status\n");
hfp_hf_query_current_call_status(device_addr);
break;
case 'y':
printf("Release call with index 2\n");
hfp_hf_release_call_with_index(device_addr, 2);
break;
case 'Y':
printf("Private consulation with call 2\n");
hfp_hf_private_consultation_with_call(device_addr, 2);
break;
case '[':
printf("Query Response and Hold status (RHH ?)\n");
hfp_hf_rrh_query_status(device_addr);
break;
case ']':
printf("Place call in a response and held state (RHH 0)\n");
hfp_hf_rrh_hold_call(device_addr);
break;
case '{':
printf("Accept held call (RHH 1)\n");
hfp_hf_rrh_accept_held_call(device_addr);
break;
case '}':
printf("Reject held call (RHH 2)\n");
hfp_hf_rrh_reject_held_call(device_addr);
break;
case '?':
printf("Query Subscriber Number\n");
hfp_hf_query_subscriber_number(device_addr);
break;
case '!':
printf("Update HF indicator with assigned number 1 (HFI)\n");
hfp_hf_set_hf_indicator(device_addr, 1, 1);
break;
default:
printf("HF: undefined user command\n");
break;
}
}
void simulate_test_sequence(hfp_test_item_t * test_item){
char ** test_steps = test_item->test;
printf("\nSimulate test sequence: \"%s\"\n", test_item->name);
int i = 0;
for (i=0; i < test_item->len; i++){
char * cmd = test_steps[i];
printf("\n---> NEXT STEP %s\n", cmd);
if (strncmp(cmd, "AT", 2) == 0){
while ( i < test_item->len){
char * expected_cmd = test_steps[i];
int expected_cmd_len = strlen(expected_cmd);
if (strncmp(expected_cmd, "USER:", 5) == 0){
user_command(expected_cmd[5]);
while (has_more_hfp_hf_commands()){
// empty rfcomm payload buffer
get_next_hfp_hf_command();
}
i++;
} else if (strncmp(expected_cmd, "AT+BAC=", 7) == 0){
int parsed_codecs[2];
uint8_t new_codecs[2];
if (strncmp(cmd, "AT+BAC=", 7) == 0){
printf("Send BAC\n");
sscanf(&cmd[7],"%d,%d", &parsed_codecs[0], &parsed_codecs[1]);
new_codecs[0] = parsed_codecs[0];
new_codecs[1] = parsed_codecs[1];
hfp_hf_set_codecs((uint8_t*)new_codecs, 2);
} else {
int expected_cmd = expected_rfcomm_command(cmd);
if (expected_cmd){
printf("\nError: Expected:'%s', but got:'%s'", cmd, (char *)get_rfcomm_payload());
return;
}
printf("Command verified: %s\n", cmd);
inject_hfp_command_to_ag((uint8_t*)"NOP",3);
sscanf(&expected_cmd[7],"%d,%d", &parsed_codecs[0], &parsed_codecs[1]);
new_codecs[0] = parsed_codecs[0];
new_codecs[1] = parsed_codecs[1];
hfp_hf_set_codecs((uint8_t*)new_codecs, 2);
while (has_more_hfp_hf_commands()){
// empty rfcomm payload buffer
get_next_hfp_hf_command();
}
i++;
} else if (strncmp(expected_cmd, "AT+BRSF=", 8) == 0 ){
int supported_features = 0;
sscanf(&expected_cmd[8],"%d", &supported_features);
printf("Call hfp_hf_init with SF %d\n", supported_features);
hfp_hf_init(rfcomm_channel_nr, supported_features, indicators, sizeof(indicators)/sizeof(uint16_t), 1);
user_command('a');
while (has_more_hfp_hf_commands()){
// empty rfcomm payload buffer
get_next_hfp_hf_command();
}
i++;
} else if (strncmp(expected_cmd, "AT+BCC", 6) == 0){
user_command('b');
while (has_more_hfp_hf_commands()){
// empty rfcomm payload buffer
get_next_hfp_hf_command();
}
i++;
} else if (strncmp(expected_cmd, "AT", 2) == 0){
printf("\n---> NEXT STEP expect from HF: %s\n", expected_cmd);
while (has_more_hfp_hf_commands()){
char * ag_cmd = get_next_hfp_hf_command();
//printf("HF response verify %s == %s[%d]\n", expected_cmd, ag_cmd, expected_cmd_len);
int equal_cmds = strncmp(ag_cmd, expected_cmd, expected_cmd_len) == 0;
if (!equal_cmds){
printf("\nError: Expected:'%s', but got:'%s'\n", expected_cmd, ag_cmd);
CHECK_EQUAL(equal_cmds,1);
return;
}
printf("Verified: '%s'\n", expected_cmd);
i++;
if (i < test_item->len){
expected_cmd = test_steps[i];
expected_cmd_len = strlen(expected_cmd);
}
}
} else {
inject_hfp_command_to_hf((uint8_t*)cmd, strlen(cmd));
//printf("\n---> NEXT STEP receive from AG: '%s'\n", expected_cmd);
inject_hfp_command_to_hf((uint8_t*)expected_cmd, strlen(expected_cmd));
i++;
}
}
}
void packet_handler(uint8_t * event, uint16_t event_size){
if (event[0] != HCI_EVENT_HFP_META) return;
if (event[3] && event[2] != HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR){
if (event[3]
&& event[2] != HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR
&& event[2] != HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG
&& event[2] != HFP_SUBEVENT_SPEAKER_VOLUME
&& event[2] != HFP_SUBEVENT_MICROPHONE_VOLUME){
printf("ERROR, status: %u\n", event[3]);
return;
}
switch (event[2]) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
printf("\n** SLC established **\n\n");
@ -195,6 +431,31 @@ void packet_handler(uint8_t * event, uint16_t event_size){
case HFP_SUBEVENT_CALL_TERMINATED:
call_termiated = 1;
break;
case HFP_SUBEVENT_COMPLETE:
printf("HFP AG HFP_SUBEVENT_COMPLETE.\n");
break;
case HFP_SUBEVENT_AG_INDICATOR_STATUS_CHANGED:
printf("AG_INDICATOR_STATUS_CHANGED, AG indicator '%s' (index: %d) to: %d\n", (const char*) &event[6], event[4], event[5]);
break;
case HFP_SUBEVENT_NETWORK_OPERATOR_CHANGED:
printf("NETWORK_OPERATOR_CHANGED, operator mode: %d, format: %d, name: %s\n", event[4], event[5], (char *) &event[6]);
break;
case HFP_SUBEVENT_EXTENDED_AUDIO_GATEWAY_ERROR:
if (event[4])
printf("EXTENDED_AUDIO_GATEWAY_ERROR_REPORT, status : %d\n", event[3]);
break;
case HFP_SUBEVENT_RING:
printf("** Ring **\n");
break;
case HFP_SUBEVENT_NUMBER_FOR_VOICE_TAG:
printf("Phone number for voice tag: %s\n", (const char *) &event[3]);
break;
case HFP_SUBEVENT_SPEAKER_VOLUME:
printf("Speaker volume: %u\n", event[3]);
break;
case HFP_SUBEVENT_MICROPHONE_VOLUME:
printf("Microphone volume: %u\n", event[3]);
break;
default:
printf("event not handled %u\n", event[2]);
break;
@ -202,7 +463,6 @@ void packet_handler(uint8_t * event, uint16_t event_size){
}
TEST_GROUP(HFPClient){
void setup(void){
@ -225,18 +485,6 @@ TEST_GROUP(HFPClient){
codecs_connection_established = 0;
audio_connection_established = 0;
}
void setup_hfp_service_level_connection(hfp_test_item_t * test_item){
service_level_connection_established = 0;
hfp_hf_establish_service_level_connection(device_addr);
simulate_test_sequence(test_item);
}
void setup_hfp_codecs_connection(hfp_test_item_t * test_item){
codecs_connection_established = 0;
simulate_test_sequence(test_item);
}
};
TEST(HFPClient, PTSATATests){
@ -248,52 +496,11 @@ TEST(HFPClient, PTSATATests){
TEST(HFPClient, PTSSLCTests){
for (int i = 0; i < hfp_pts_hf_slc_tests_size(); i++){
setup_hfp_service_level_connection(&hfp_pts_hf_slc_tests()[i]);
CHECK_EQUAL(service_level_connection_established, 1);
simulate_test_sequence(&hfp_pts_hf_slc_tests()[i]);
teardown();
}
}
TEST(HFPClient, HFAudioConnectionEstablishedWithoutCodecNegotiation){
hfp_hf_init(rfcomm_channel_nr, supported_features_without_codec_negotiation, indicators, sizeof(indicators)/sizeof(uint16_t), 1);
hfp_hf_set_codecs(default_codecs, 1);
setup_hfp_service_level_connection(&hfp_slc_tests()[1]);
CHECK_EQUAL(service_level_connection_established, 1);
setup_hfp_codecs_connection(default_hfp_cc_test());
CHECK_EQUAL(codecs_connection_established, 1);
hfp_hf_establish_audio_connection(device_addr);
hfp_hf_release_audio_connection(device_addr);
CHECK_EQUAL(audio_connection_established, 0);
}
TEST(HFPClient, HFCodecsConnectionEstablished){
for (int i = 0; i < hfp_cc_tests_size(); i++){
setup_hfp_service_level_connection(default_hfp_slc_test());
CHECK_EQUAL(service_level_connection_established, 1);
setup_hfp_codecs_connection(&hfp_cc_tests()[i]);
teardown();
}
}
TEST(HFPClient, HFServiceLevelConnectionCommands){
setup_hfp_service_level_connection(default_hfp_slc_test());
CHECK_EQUAL(service_level_connection_established, 1);
for (int i = 0; i < hfp_slc_cmds_tests_size(); i++){
simulate_test_sequence(&hfp_slc_cmds_tests()[i]);
}
}
TEST(HFPClient, HFServiceLevelConnectionEstablished){
for (int i = 0; i < hfp_slc_tests_size(); i++){
setup_hfp_service_level_connection(&hfp_slc_tests()[i]);
CHECK_EQUAL(service_level_connection_established, 1);
teardown();
}
}
int main (int argc, const char * argv[]){

View File

@ -101,7 +101,7 @@ char * get_next_hfp_command(int start_command_offset, int end_command_offset){
if ( *(data+i) == '\r' || *(data+i) == '\n' ) {
data[i]=0;
// update state
// printf("!!! command %s\n", data);
//printf("!!! command %s\n", data);
hfp_command_start_index = hfp_command_start_index + i + start_command_offset + end_command_offset;
return data;
}
@ -110,22 +110,22 @@ char * get_next_hfp_command(int start_command_offset, int end_command_offset){
return NULL;
}
// static void print_without_newlines(uint8_t *data, uint16_t len){
// int found_newline = 0;
// int found_item = 0;
static void print_without_newlines(uint8_t *data, uint16_t len){
int found_newline = 0;
int found_item = 0;
// 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");
// }
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");
}
extern "C" void l2cap_init(void){}
@ -142,17 +142,17 @@ int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
}
if (has_more_hfp_commands(start_command_offset, end_command_offset)){
// printf("Buffer response: ");
//printf("Buffer response: ");
strncpy((char*)&rfcomm_payload[rfcomm_payload_len], (char*)data, len);
rfcomm_payload_len += len;
} else {
hfp_command_start_index = 0;
// printf("Copy response: ");
//printf("Copy response: ");
strncpy((char*)&rfcomm_payload[0], (char*)data, len);
rfcomm_payload_len = len;
}
// print_without_newlines(rfcomm_payload,rfcomm_payload_len);
//print_without_newlines(rfcomm_payload,rfcomm_payload_len);
return 0;
}
@ -315,15 +315,6 @@ static void add_new_lines_to_hfp_command(uint8_t * data, int len){
outgoing_rfcomm_payload[pos++] = '\n';
strncpy((char*)&outgoing_rfcomm_payload[pos], (char*)data, len);
pos += len;
if (memcmp((char*)data, "+BAC", 4) != 0 &&
memcmp((char*)data, "+BCS", 4) != 0){
outgoing_rfcomm_payload[pos++] = '\r';
outgoing_rfcomm_payload[pos++] = '\n';
outgoing_rfcomm_payload[pos++] = 'O';
outgoing_rfcomm_payload[pos++] = 'K';
}
}
outgoing_rfcomm_payload[pos++] = '\r';
outgoing_rfcomm_payload[pos++] = '\n';
@ -333,8 +324,9 @@ static void add_new_lines_to_hfp_command(uint8_t * data, int len){
void inject_hfp_command_to_hf(uint8_t * data, int len){
if (memcmp((char*)data, "AT", 2) == 0) return;
add_new_lines_to_hfp_command(data, len);
// printf("inject_hfp_command_to_hf to HF: ");
// print_without_newlines(outgoing_rfcomm_payload,outgoing_rfcomm_payload_len);
(*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &outgoing_rfcomm_payload[0], outgoing_rfcomm_payload_len);
}

View File

@ -51,52 +51,6 @@
#define TEST_SEQUENCE(test_sequence) { (char *)#test_sequence, (char**)test_sequence, sizeof(test_sequence) / sizeof(char *)}
/* Service Level Connection (slc) test sequences */
// with codec negotiation feature
const char * slc_test1[] = {
"AT+BRSF=127",
"+BRSF:4079",
"OK",
"AT+BAC=1,2",
"OK",
"AT+CIND=?",
"+CIND:(\"service\",(0,1)),(\"call\",(0,1)),(\"callsetup\",(0,3)),(\"battchg\",(0,5)),(\"signal\",(0,5)),(\"roam\",(0,1)),(\"callheld\",(0,2))",
"OK",
"AT+CIND?",
"+CIND:1,0,0,3,5,0,0",
"OK",
"AT+CMER=3,0,0,1",
"OK",
"AT+CHLD=?",
"+CHLD:(1,1x,2,2x,3)",
"OK"
};
// without codec negotiation feature
const char * slc_test2[] = {
"AT+BRSF=438",
"+BRSF:495",
"OK",
"AT+CIND=?",
"+CIND:(\"service\",(0,1)),(\"call\",(0,1)),(\"callsetup\",(0,3)),(\"battchg\",(0,5)),(\"signal\",(0,5)),(\"roam\",(0,1)),(\"callheld\",(0,2))",
"OK",
"AT+CIND?",
"+CIND:1,0,0,3,5,0,0",
"OK",
"AT+CMER=3,0,0,1",
"OK",
"AT+CHLD=?",
"+CHLD:(1,1x,2,2x,3)",
"OK"
};
hfp_test_item_t slc_tests[] = {
TEST_SEQUENCE(slc_test1),
TEST_SEQUENCE(slc_test2)
};
/* Service Level Connection (slc) common commands */
const char * slc_cmds_test1[] = {
"AT+BAC=1,3",
@ -193,6 +147,7 @@ hfp_test_item_t ic_tests[] = {
// PTS test sequences
const char * TC_AG_SLC_BV_01_C[] = {
"USER:a",
"AT+BRSF=127" ,
"+BRSF:4079" ,
"OK" ,
@ -220,6 +175,7 @@ const char * TC_AG_SLC_BV_01_C[] = {
};
const char * TC_AG_SLC_BV_02_C[] = {
"USER:a",
"AT+BRSF=127" ,
"+BRSF:4079" ,
"OK" ,
@ -247,6 +203,7 @@ const char * TC_AG_SLC_BV_02_C[] = {
};
const char * TC_AG_SLC_BV_03_C[] = {
"USER:a",
"AT+BRSF=125" ,
"+BRSF:4079" ,
"OK" ,
@ -271,6 +228,7 @@ const char * TC_AG_SLC_BV_03_C[] = {
};
const char * TC_AG_SLC_BV_04_C[] = {
"USER:a",
"AT+BRSF=125" ,
"+BRSF:4079" ,
"OK" ,
@ -295,6 +253,7 @@ const char * TC_AG_SLC_BV_04_C[] = {
};
const char * TC_AG_SLC_BV_05_I[] = {
"USER:a",
"AT+BRSF=255" ,
"+BRSF:4079" ,
"OK" ,
@ -324,6 +283,7 @@ const char * TC_AG_SLC_BV_05_I[] = {
};
const char * TC_AG_SLC_BV_06_I[] = {
"USER:a",
"AT+BRSF=255" ,
"+BRSF:4079" ,
"OK" ,
@ -353,6 +313,7 @@ const char * TC_AG_SLC_BV_06_I[] = {
};
const char * TC_AG_SLC_BV_07_I[] = {
"USER:a",
"AT+BRSF=127" ,
"+BRSF:4079" ,
"OK" ,
@ -380,6 +341,7 @@ const char * TC_AG_SLC_BV_07_I[] = {
};
const char * TC_AG_SLC_BV_09_I[] = {
"USER:a",
"AT+BRSF=895" ,
"+BRSF:4079" ,
"OK" ,
@ -416,6 +378,7 @@ const char * TC_AG_SLC_BV_09_I[] = {
};
const char * TC_AG_SLC_BV_10_I[] = {
"USER:a",
"AT+BRSF=127" ,
"+BRSF:4079" ,
"OK" ,
@ -470,9 +433,9 @@ const char * TC_HF_SLC_BV_01_C[] = {
"AT+CHLD=?" ,
"+CHLD: (0,1,1x,2,2x,3,4)" ,
"OK" ,
"AT+VGM=9" ,
"USER:Q",
"+BSIR: 0" ,
"AT+VGS=9" ,
"USER:O", // 'AT+VGS=9" ,
"OK" ,
"OK"
};
@ -492,8 +455,8 @@ const char * TC_HF_SLC_BV_02_C[] = {
"AT+CHLD=?" ,
"+CHLD: (0,1,1x,2,2x,3,4)" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -511,8 +474,8 @@ const char * TC_HF_SLC_BV_03_C[] = {
"OK" ,
"AT+CMER=3,0,0,1" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -530,8 +493,8 @@ const char * TC_HF_SLC_BV_04_C[] = {
"OK" ,
"AT+CMER=3,0,0,1" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -554,8 +517,8 @@ const char * TC_HF_SLC_BV_05_I[] = {
"AT+CHLD=?" ,
"+CHLD: (0,1,1x,2,2x,3,4)" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -578,8 +541,8 @@ const char * TC_HF_SLC_BV_06_I[] = {
"AT+CHLD=?" ,
"+CHLD: (0,1,1x,2,2x,3,4)" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -600,8 +563,8 @@ const char * TC_HF_SLC_BV_08_I[] = {
"AT+CHLD=?" ,
"+CHLD: (0,1,1x,2,2x,3,4)" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -630,8 +593,8 @@ const char * TC_HF_SLC_BV_09_I[] = {
"AT+BIND?" ,
"+BIND: 1,1" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -652,8 +615,8 @@ const char * TC_HF_SLC_BV_10_I[] = {
"AT+CHLD=?" ,
"+CHLD: (0,1,1x,2,2x,3,4)" ,
"OK" ,
"AT+VGM=9" ,
"AT+VGS=9" ,
"USER:Q", // "AT+VGM=9" ,
"USER:O", // 'AT+VGS=9" ,
"+BSIR: 0" ,
"OK" ,
"OK"
@ -712,12 +675,51 @@ const char * TC_AG_ATA_BV_01_I[] = {
"+CIEV:2,0"
};
const char * TC_AG_ATA_BV_02_I[] = {
"USER:a",
"AT+BRSF=127" ,
"+BRSF:4079" ,
"OK" ,
"AT+CIND=?" ,
"+CIND:(\"service\",(0,1)),(\"call\",(0,1)),(\"callsetup\",(0,3)),(\"battchg\",(0,5)),(\"signal\",(0,5)),(\"roam\",(0,1)),(\"callheld\",(0,2))" ,
"OK" ,
"AT+CIND?" ,
"+CIND:1,0,0,3,5,0,0" ,
"OK" ,
"AT+CMER=3,0,0,1" ,
"OK" ,
"AT+CHLD=?" ,
"+CHLD:(1,1x,2,2x,3)" ,
"OK" ,
"AT+VGS=9" ,
"OK" ,
"AT+VGM=9" ,
"OK" ,
"AT+CLIP=1" ,
"OK" ,
"AT+CCWA=1" ,
"OK" ,
"AT+CMEE=1" ,
"OK" ,
"USER:c",
"+CIEV:3,1" ,
"RING" ,
"+CLIP: \"1234567\",129" ,
"ATA" ,
"OK" ,
"+CIEV:2,1" ,
"+CIEV:3,0" ,
"USER:C",
"USER:A",
"+CIEV:2,0"
};
hfp_test_item_t pts_ag_ata_tests[] = {
TEST_SEQUENCE(TC_AG_ATA_BV_01_I),
// TEST_SEQUENCE(TC_AG_ATA_BV_01_I),
// TEST_SEQUENCE(TC_AG_ATA_BV_02_I)
};
hfp_test_item_t pts_hf_ata_tests[] = {
// TEST_SEQUENCE(TC_HF_ATA_BV_01_I),
// TEST_SEQUENCE(TC_HF_ATA_BV_02_I)
@ -726,16 +728,6 @@ hfp_test_item_t pts_hf_ata_tests[] = {
static int test_item_size = sizeof(hfp_test_item_t);
// SLC
int hfp_slc_tests_size(){ return sizeof(slc_tests)/test_item_size;}
hfp_test_item_t * hfp_slc_tests(){ return slc_tests;}
hfp_test_item_t * default_hfp_slc_test(){return &slc_tests[0];}
// SLC commands
int hfp_slc_cmds_tests_size(){ return sizeof(slc_cmds_tests)/test_item_size;}
hfp_test_item_t * hfp_slc_cmds_tests(){ return slc_cmds_tests;}
hfp_test_item_t * default_slc_cmds_test() { return &slc_tests[0];}
// CC
int hfp_cc_tests_size(){ return sizeof(cc_tests) /test_item_size;}
hfp_test_item_t * hfp_cc_tests(){ return cc_tests;}

View File

@ -52,17 +52,6 @@ typedef struct hfp_test_item{
int len;
} hfp_test_item_t;
/* Service Level Connection (slc) test sequences */
int hfp_slc_tests_size();
hfp_test_item_t * hfp_slc_tests();
hfp_test_item_t * default_hfp_slc_test();
/* Service Level Connection (slc) common commands */
int hfp_slc_cmds_tests_size();
hfp_test_item_t * hfp_slc_cmds_tests();
hfp_test_item_t * deafult_hfp_slc_cmds_test();
/* Codecs Connection (cc) test sequences */
int hfp_cc_tests_size();
hfp_test_item_t * hfp_cc_tests();

View File

@ -354,31 +354,38 @@ static int stdin_process(struct data_source *ds){
switch (cmd){
case 'a':
memcpy(device_addr, pts_addr, 6);
printf("USER:%c ", cmd);
printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_service_level_connection(device_addr);
break;
case 'A':
printf("USER:%c ", cmd);
printf("Release HFP service level connection.\n");
hfp_ag_release_service_level_connection(device_addr);
break;
case 'z':
memcpy(device_addr, speaker_addr, 6);
printf("USER:%c ", cmd);
printf("Establish HFP service level connection to %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_service_level_connection(device_addr);
break;
case 'Z':
printf("USER:%c ", cmd);
printf("Release HFP service level connection to %s...\n", bd_addr_to_str(device_addr));
hfp_ag_release_service_level_connection(device_addr);
break;
case 'b':
printf("USER:%c ", cmd);
printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_audio_connection(device_addr);
break;
case 'B':
printf("USER:%c ", cmd);
printf("Release Audio connection.\n");
hfp_ag_release_audio_connection(device_addr);
break;
case 'c':
printf("USER:%c ", cmd);
printf("Simulate incoming call from 1234567\n");
current_call_exists_a = 1;
current_call_status_a = HFP_ENHANCED_CALL_STATUS_INCOMING;
@ -387,6 +394,7 @@ static int stdin_process(struct data_source *ds){
hfp_ag_incoming_call();
break;
case 'm':
printf("USER:%c ", cmd);
printf("Simulate incoming call from 7654321\n");
current_call_exists_b = 1;
current_call_status_b = HFP_ENHANCED_CALL_STATUS_INCOMING;
@ -395,14 +403,17 @@ static int stdin_process(struct data_source *ds){
hfp_ag_incoming_call();
break;
case 'C':
printf("USER:%c ", cmd);
printf("Simulate terminate call\n");
hfp_ag_call_dropped();
break;
case 'd':
printf("USER:%c ", cmd);
printf("Report AG failure\n");
hfp_ag_report_extended_audio_gateway_error_result_code(device_addr, HFP_CME_ERROR_AG_FAILURE);
break;
case 'e':
printf("USER:%c ", cmd);
printf("Answer call on AG\n");
if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){
current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE;
@ -413,114 +424,142 @@ static int stdin_process(struct data_source *ds){
hfp_ag_answer_incoming_call();
break;
case 'E':
printf("USER:%c ", cmd);
printf("Reject call on AG\n");
hfp_ag_terminate_call();
break;
case 'f':
printf("USER:%c ", cmd);
printf("Disable cellular network\n");
hfp_ag_set_registration_status(0);
break;
case 'F':
printf("USER:%c ", cmd);
printf("Enable cellular network\n");
hfp_ag_set_registration_status(1);
break;
case 'g':
printf("USER:%c ", cmd);
printf("Set signal strength to 0\n");
hfp_ag_set_signal_strength(0);
break;
case 'G':
printf("USER:%c ", cmd);
printf("Set signal strength to 5\n");
hfp_ag_set_signal_strength(5);
break;
case 'h':
printf("USER:%c ", cmd);
printf("Disable roaming\n");
hfp_ag_set_roaming_status(0);
break;
case 'H':
printf("USER:%c ", cmd);
printf("Enable roaming\n");
hfp_ag_set_roaming_status(1);
break;
case 'i':
printf("USER:%c ", cmd);
printf("Set battery level to 3\n");
hfp_ag_set_battery_level(3);
break;
case 'I':
printf("USER:%c ", cmd);
printf("Set battery level to 5\n");
hfp_ag_set_battery_level(5);
break;
case 'j':
printf("USER:%c ", cmd);
printf("Answering call on remote side\n");
hfp_ag_outgoing_call_established();
break;
case 'r':
printf("USER:%c ", cmd);
printf("Disable in-band ring tone\n");
hfp_ag_set_use_in_band_ring_tone(0);
break;
case 'k':
printf("USER:%c ", cmd);
printf("Memory 1 cleared\n");
memory_1_enabled = 0;
break;
case 'K':
printf("USER:%c ", cmd);
printf("Memory 1 set\n");
memory_1_enabled = 1;
break;
case 'l':
printf("USER:%c ", cmd);
printf("Last dialed number cleared\n");
last_number_exists = 0;
break;
case 'L':
printf("USER:%c ", cmd);
printf("Last dialed number set\n");
last_number_exists = 1;
break;
case 'n':
printf("USER:%c ", cmd);
printf("Disable Voice Recognition\n");
hfp_ag_activate_voice_recognition(device_addr, 0);
break;
case 'N':
printf("USER:%c ", cmd);
printf("Enable Voice Recognition\n");
hfp_ag_activate_voice_recognition(device_addr, 1);
break;
case 'o':
printf("USER:%c ", cmd);
printf("Set speaker gain to 0 (minimum)\n");
hfp_ag_set_speaker_gain(device_addr, 0);
break;
case 'O':
printf("USER:%c ", cmd);
printf("Set speaker gain to 9 (default)\n");
hfp_ag_set_speaker_gain(device_addr, 9);
break;
case 'p':
printf("USER:%c ", cmd);
printf("Set speaker gain to 12 (higher)\n");
hfp_ag_set_speaker_gain(device_addr, 12);
break;
case 'P':
printf("USER:%c ", cmd);
printf("Set speaker gain to 15 (maximum)\n");
hfp_ag_set_speaker_gain(device_addr, 15);
break;
case 'q':
printf("USER:%c ", cmd);
printf("Set microphone gain to 0\n");
hfp_ag_set_microphone_gain(device_addr, 0);
break;
case 'Q':
printf("USER:%c ", cmd);
printf("Set microphone gain to 9\n");
hfp_ag_set_microphone_gain(device_addr, 9);
break;
case 's':
printf("USER:%c ", cmd);
printf("Set microphone gain to 12\n");
hfp_ag_set_microphone_gain(device_addr, 12);
break;
case 'S':
printf("USER:%c ", cmd);
printf("Set microphone gain to 15\n");
hfp_ag_set_microphone_gain(device_addr, 15);
break;
case 'R':
printf("USER:%c ", cmd);
printf("Enable in-band ring tone\n");
hfp_ag_set_use_in_band_ring_tone(1);
break;
case 't':
printf("USER:%c ", cmd);
printf("Terminate HCI connection.\n");
gap_disconnect(handle);
break;
case 'u':
printf("USER:%c ", cmd);
printf("Join held call\n");
current_call_mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL;
hfp_ag_join_held_call();
@ -529,14 +568,17 @@ static int stdin_process(struct data_source *ds){
start_scan();
break;
case 'w':
printf("USER:%c ", cmd);
printf("AG: Put incoming call on hold (Response and Hold)\n");
hfp_ag_hold_incoming_call();
break;
case 'x':
printf("USER:%c ", cmd);
printf("AG: Accept held incoming call (Response and Hold)\n");
hfp_ag_accept_held_incoming_call();
break;
case 'X':
printf("USER:%c ", cmd);
printf("AG: Reject held incoming call (Response and Hold)\n");
hfp_ag_reject_held_incoming_call();
break;