diff --git a/test/hfp/hfp_ag_client_test.c b/test/hfp/hfp_ag_client_test.c index c5d04ad70..037e0699e 100644 --- a/test/hfp/hfp_ag_client_test.c +++ b/test/hfp/hfp_ag_client_test.c @@ -104,36 +104,204 @@ static uint8_t start_ringing = 0; static uint8_t stop_ringing = 0; static uint8_t call_termiated = 0; +static uint16_t handle = -1; +static int memory_1_enabled = 1; +static int last_number_exists = 1; -static int hfp_command_start_index = 0; -int has_more_hfp_commands(){ - // \r\nOK\r\n is the smallest AG cmd - int has_cmd = get_rfcomm_payload_len() - hfp_command_start_index >= 6; - printf("has more: payload len %d, start %d, has more %d\n", get_rfcomm_payload_len(), hfp_command_start_index, has_cmd); - return has_cmd; +int has_more_hfp_ag_commands(){ + return has_more_hfp_commands(2,2); } -char * get_next_hfp_command(){ - printf("get next: payload len %d, start %d\n", get_rfcomm_payload_len(), hfp_command_start_index); - char * data = (char *)(&get_rfcomm_payload()[hfp_command_start_index + 2]); - int data_len = get_rfcomm_payload_len() - hfp_command_start_index - 2; +char * get_next_hfp_ag_command(){ + return get_next_hfp_command(2,2); +} - int i; - - for (i = 0; i < data_len; i++){ - if ( *(data+i) == '\r' || *(data+i) == '\n' ) { - data[i]=0; - printf("!!! command: '%s'\n", data); - // update state - hfp_command_start_index = hfp_command_start_index + i + 4; - return data; - } else { - // printf("check %i '%c'\n",i,*(data+i)); - } +static void user_command(char cmd){ + switch (cmd){ + case 'a': + 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("Release HFP service level connection.\n"); + hfp_ag_release_service_level_connection(device_addr); + break; + case 'b': + printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr)); + hfp_ag_establish_audio_connection(device_addr); + break; + case 'B': + printf("Release Audio connection.\n"); + hfp_ag_release_audio_connection(device_addr); + break; + case 'c': + printf("Simulate incoming call from 1234567\n"); + // current_call_exists_a = 1; + // current_call_status_a = HFP_ENHANCED_CALL_STATUS_INCOMING; + // current_call_dir = HFP_ENHANCED_CALL_DIR_INCOMING; + hfp_ag_set_clip(129, "1234567"); + hfp_ag_incoming_call(); + break; + case 'm': + printf("Simulate incoming call from 7654321\n"); + // current_call_exists_b = 1; + // current_call_status_b = HFP_ENHANCED_CALL_STATUS_INCOMING; + // current_call_dir = HFP_ENHANCED_CALL_DIR_INCOMING; + hfp_ag_set_clip(129, "7654321"); + hfp_ag_incoming_call(); + break; + case 'C': + printf("Simulate terminate call\n"); + hfp_ag_call_dropped(); + break; + case 'd': + 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("Answer call on AG\n"); + // if (current_call_status_a == HFP_ENHANCED_CALL_STATUS_INCOMING){ + // current_call_status_a = HFP_ENHANCED_CALL_STATUS_ACTIVE; + // } + // if (current_call_status_b == HFP_ENHANCED_CALL_STATUS_INCOMING){ + // current_call_status_b = HFP_ENHANCED_CALL_STATUS_ACTIVE; + // } + hfp_ag_answer_incoming_call(); + break; + case 'E': + printf("Reject call on AG\n"); + hfp_ag_terminate_call(); + break; + case 'f': + printf("Disable cellular network\n"); + hfp_ag_set_registration_status(0); + break; + case 'F': + printf("Enable cellular network\n"); + hfp_ag_set_registration_status(1); + break; + case 'g': + printf("Set signal strength to 0\n"); + hfp_ag_set_signal_strength(0); + break; + case 'G': + printf("Set signal strength to 5\n"); + hfp_ag_set_signal_strength(5); + break; + case 'h': + printf("Disable roaming\n"); + hfp_ag_set_roaming_status(0); + break; + case 'H': + printf("Enable roaming\n"); + hfp_ag_set_roaming_status(1); + break; + case 'i': + printf("Set battery level to 3\n"); + hfp_ag_set_battery_level(3); + break; + case 'I': + printf("Set battery level to 5\n"); + hfp_ag_set_battery_level(5); + break; + case 'j': + printf("Answering call on remote side\n"); + hfp_ag_outgoing_call_established(); + break; + case 'r': + printf("Disable in-band ring tone\n"); + hfp_ag_set_use_in_band_ring_tone(0); + break; + case 'k': + printf("Memory 1 cleared\n"); + memory_1_enabled = 0; + break; + case 'K': + printf("Memory 1 set\n"); + memory_1_enabled = 1; + break; + case 'l': + printf("Last dialed number cleared\n"); + last_number_exists = 0; + break; + case 'L': + printf("Last dialed number set\n"); + last_number_exists = 1; + break; + case 'n': + printf("Disable Voice Recognition\n"); + hfp_ag_activate_voice_recognition(device_addr, 0); + break; + case 'N': + printf("Enable Voice Recognition\n"); + hfp_ag_activate_voice_recognition(device_addr, 1); + break; + case 'o': + printf("Set speaker gain to 0 (minimum)\n"); + hfp_ag_set_speaker_gain(device_addr, 0); + break; + case 'O': + printf("Set speaker gain to 9 (default)\n"); + hfp_ag_set_speaker_gain(device_addr, 9); + break; + case 'p': + printf("Set speaker gain to 12 (higher)\n"); + hfp_ag_set_speaker_gain(device_addr, 12); + break; + case 'P': + printf("Set speaker gain to 15 (maximum)\n"); + hfp_ag_set_speaker_gain(device_addr, 15); + break; + case 'q': + printf("Set microphone gain to 0\n"); + hfp_ag_set_microphone_gain(device_addr, 0); + break; + case 'Q': + printf("Set microphone gain to 9\n"); + hfp_ag_set_microphone_gain(device_addr, 9); + break; + case 's': + printf("Set microphone gain to 12\n"); + hfp_ag_set_microphone_gain(device_addr, 12); + break; + case 'S': + printf("Set microphone gain to 15\n"); + hfp_ag_set_microphone_gain(device_addr, 15); + break; + case 'R': + printf("Enable in-band ring tone\n"); + hfp_ag_set_use_in_band_ring_tone(1); + break; + case 't': + printf("Terminate HCI connection.\n"); + gap_disconnect(handle); + break; + case 'u': + printf("Join held call\n"); + // current_call_mpty = HFP_ENHANCED_CALL_MPTY_CONFERENCE_CALL; + hfp_ag_join_held_call(); + break; + case 'v': + // start_scan(); + break; + case 'w': + printf("AG: Put incoming call on hold (Response and Hold)\n"); + hfp_ag_hold_incoming_call(); + break; + case 'x': + printf("AG: Accept held incoming call (Response and Hold)\n"); + hfp_ag_accept_held_incoming_call(); + break; + case 'X': + printf("AG: Reject held incoming call (Response and Hold)\n"); + hfp_ag_reject_held_incoming_call(); + break; + default: + // show_usage(); + printf("AG: undefined user command\n"); + break; } - printf("should not got here\n"); - return NULL; } void simulate_test_sequence(hfp_test_item_t * test_item){ @@ -141,20 +309,22 @@ void simulate_test_sequence(hfp_test_item_t * test_item){ printf("\nSimulate test sequence: \"%s\"\n", test_item->name); int i = 0; - for (i=0; i < test_item->len; i++){ + while (i < test_item->len){ char * expected_cmd = test_steps[i]; int expected_cmd_len = strlen(expected_cmd); - if (strncmp(expected_cmd, "AT", 2) == 0){ + if (strncmp(expected_cmd, "USER:", 5) == 0){ + 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); - hfp_command_start_index = 0; inject_hfp_command_to_ag((uint8_t*)expected_cmd, expected_cmd_len); + i++; } else { printf("\n---> NEXT STEP expect from AG: %s\n", expected_cmd); - - if (has_more_hfp_commands()){ - char * ag_cmd = get_next_hfp_command(); - printf("AG response verify %s == %s[%d]\n", expected_cmd, ag_cmd, expected_cmd_len); + while (has_more_hfp_ag_commands()){ + char * ag_cmd = get_next_hfp_ag_command(); + //printf("AG 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){ @@ -162,12 +332,15 @@ void simulate_test_sequence(hfp_test_item_t * test_item){ CHECK_EQUAL(equal_cmds,1); return; } - printf("AG response verified '%s'\n", expected_cmd); - } else { - hfp_command_start_index = 0; - printf("\n---> NEXT STEP trigger once more AG\n"); - inject_hfp_command_to_ag((uint8_t*)"NOP",3); - } + printf("Verified: '%s'\n", expected_cmd); + i++; + if (i < test_item->len){ + expected_cmd = test_steps[i]; + expected_cmd_len = strlen(expected_cmd); + } + } + // printf("\n---> NEXT STEP trigger once more AG\n"); + inject_hfp_command_to_ag((uint8_t*)"NOP",3); } } } @@ -214,8 +387,11 @@ void packet_handler(uint8_t * event, uint16_t event_size){ case HFP_SUBEVENT_CALL_TERMINATED: call_termiated = 1; break; + case HFP_CMD_CALL_ANSWERED: + //printf("HF answers call, accept call by GSM\n"); + break; default: - printf("event not handled %u\n", event[2]); + printf("hfp_ag_client_test: event not handled %u\n", event[2]); break; } } @@ -258,6 +434,13 @@ 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, PTSSLCTests){ for (int i = 0; i < hfp_pts_ag_slc_tests_size(); i++){ setup_hfp_service_level_connection(&hfp_pts_ag_slc_tests()[i]); diff --git a/test/hfp/hfp_hf_client_test.c b/test/hfp/hfp_hf_client_test.c index 429af0615..0bd0d1bf0 100644 --- a/test/hfp/hfp_hf_client_test.c +++ b/test/hfp/hfp_hf_client_test.c @@ -113,6 +113,14 @@ int expected_rfcomm_command(const char * cmd){ return cmd_found && ok_found; } +char * get_next_hfp_hf_command(){ + return get_next_hfp_command(0,2); +} + +int has_more_hfp_hf_commands(){ + return has_more_hfp_commands(0,2); +} + 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); @@ -231,6 +239,13 @@ TEST_GROUP(HFPClient){ }; +TEST(HFPClient, PTSATATests){ + for (int i = 0; i < hfp_pts_hf_ata_tests_size(); i++){ + simulate_test_sequence(&hfp_pts_hf_ata_tests()[i]); + teardown(); + } +} + 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]); diff --git a/test/hfp/mock.c b/test/hfp/mock.c index 77c4c0dff..06b19e542 100644 --- a/test/hfp/mock.c +++ b/test/hfp/mock.c @@ -62,7 +62,11 @@ static uint16_t rfcomm_cid = 1; static bd_addr_t dev_addr; static uint16_t sco_handle = 10; static uint8_t rfcomm_payload[200]; -static uint16_t rfcomm_payload_len; +static uint16_t rfcomm_payload_len = 0; + +static uint8_t outgoing_rfcomm_payload[200]; +static uint16_t outgoing_rfcomm_payload_len = 0; + void * active_connection; hfp_connection_t * hfp_context; @@ -77,24 +81,52 @@ uint16_t get_rfcomm_payload_len(){ return rfcomm_payload_len; } +static int hfp_command_start_index = 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= 2 + start_command_offset + end_command_offset; + //printf("has more: payload len %d, start %d, has more %d\n", get_rfcomm_payload_len(), hfp_command_start_index, has_cmd); + return has_cmd; } +char * get_next_hfp_command(int start_command_offset, int end_command_offset){ + //printf("get next: payload len %d, start %d\n", get_rfcomm_payload_len(), hfp_command_start_index); + char * data = (char *)(&get_rfcomm_payload()[hfp_command_start_index + start_command_offset]); + int data_len = get_rfcomm_payload_len() - hfp_command_start_index - start_command_offset; + + int i; + + for (i = 0; i < data_len; i++){ + if ( *(data+i) == '\r' || *(data+i) == '\n' ) { + data[i]=0; + // update state + // printf("!!! command %s\n", data); + hfp_command_start_index = hfp_command_start_index + i + start_command_offset + end_command_offset; + return data; + } + } + printf("should not got here\n"); + return NULL; +} + +// static void print_without_newlines(uint8_t *data, uint16_t len){ +// int found_newline = 0; +// int found_item = 0; + +// for (int i=0; i