From 555cc8ad1e6e762b57dca4b8762e8c63f707b10c Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Thu, 19 Nov 2015 12:08:02 +0100 Subject: [PATCH] hfp: use default codec --- src/hfp_ag.c | 8 ++---- test/hfp/hfp_ag_client_test.c | 53 +++++++++++++++++++++++++++-------- test/hfp/test_sequences.c | 22 ++++++++++++++- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 351cf8194..d24340432 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -353,7 +353,7 @@ static int hfp_ag_cmd_suggest_codec(uint16_t cid, uint8_t codec){ static uint8_t hfp_ag_suggest_codec(hfp_connection_t *context){ int i,j; - uint8_t codec = 0; + uint8_t codec = HFP_CODEC_CVSD; for (i = 0; i < hfp_codecs_nr; i++){ for (j = 0; j < context->remote_codecs_nr; j++){ if (context->remote_codecs[j] == hfp_codecs[i]){ @@ -793,7 +793,7 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, rfcomm_register_packet_handler(packet_handler); hfp_init(rfcomm_channel_nr); - + hfp_supported_features = supported_features; hfp_codecs_nr = codecs_nr; @@ -804,9 +804,6 @@ void hfp_ag_init(uint16_t rfcomm_channel_nr, uint32_t supported_features, hfp_ag_indicators_nr = ag_indicators_nr; memcpy(hfp_ag_indicators, ag_indicators, ag_indicators_nr * sizeof(hfp_ag_indicator_t)); - for (i=0; inegotiated_codec = HFP_CODEC_CVSD; connection->codecs_state = HFP_CODECS_EXCHANGED; } diff --git a/test/hfp/hfp_ag_client_test.c b/test/hfp/hfp_ag_client_test.c index 31a024031..3d3f75e3b 100644 --- a/test/hfp/hfp_ag_client_test.c +++ b/test/hfp/hfp_ag_client_test.c @@ -84,6 +84,9 @@ static hfp_ag_indicator_t ag_indicators[] = { {7, "callheld", 0, 2, 0, 1, 1, 0} }; +static int supported_features_with_codec_negotiation = 1007; // 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"}; @@ -186,6 +189,12 @@ TEST_GROUP(HFPClient){ service_level_connection_established = 0; codecs_connection_established = 0; audio_connection_established = 0; + + hfp_ag_init(rfcomm_channel_nr, supported_features_with_codec_negotiation, + codecs, sizeof(codecs), + ag_indicators, ag_indicators_nr, + hf_indicators, hf_indicators_nr, + call_hold_services, call_hold_services_nr); } void teardown(void){ @@ -226,7 +235,7 @@ TEST(HFPClient, HFAnswerIncomingCallWithInBandRingTone){ } -TEST(HFPClient, HFAudioConnectionEstablished){ +TEST(HFPClient, HFAudioConnectionEstablishedWithCodecNegtiation){ setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size()); CHECK_EQUAL(service_level_connection_established, 1); @@ -240,6 +249,26 @@ TEST(HFPClient, HFAudioConnectionEstablished){ CHECK_EQUAL(audio_connection_established, 0); } +TEST(HFPClient, HFAudioConnectionEstablishedWithDefaultCodec){ + 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].test, hfp_slc_tests()[1].len); + CHECK_EQUAL(service_level_connection_established, 1); + + setup_hfp_codecs_connection(default_cc_setup(), default_cc_setup_size()); + CHECK_EQUAL(codecs_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); +} + TEST(HFPClient, HFCodecsConnectionEstablished){ for (int i = 0; i < cc_tests_size(); i++){ setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size()); @@ -259,20 +288,22 @@ TEST(HFPClient, HFServiceLevelConnectionCommands){ } } -TEST(HFPClient, HFServiceLevelConnectionEstablished){ - for (int i = 0; i < slc_tests_size(); i++){ - setup_hfp_service_level_connection(hfp_slc_tests()[i].test, hfp_slc_tests()[i].len); - CHECK_EQUAL(service_level_connection_established, 1); - } -} - - -int main (int argc, const char * argv[]){ - hfp_ag_init(rfcomm_channel_nr, 1007, codecs, sizeof(codecs), +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].test, hfp_slc_tests()[1].len); + CHECK_EQUAL(service_level_connection_established, 1); +} +TEST(HFPClient, HFServiceLevelConnectionEstablishedWithCodecNegotiation){ + setup_hfp_service_level_connection(hfp_slc_tests()[0].test, hfp_slc_tests()[0].len); + CHECK_EQUAL(service_level_connection_established, 1); +} + +int main (int argc, const char * argv[]){ hfp_ag_register_packet_handler(packet_handler); return CommandLineTestRunner::RunAllTests(argc, argv); diff --git a/test/hfp/test_sequences.c b/test/hfp/test_sequences.c index 413e9b245..4f66cc1f4 100644 --- a/test/hfp/test_sequences.c +++ b/test/hfp/test_sequences.c @@ -53,6 +53,7 @@ /* Service Level Connection (slc) test sequences */ +// with codec negotiation feature const char * slc_test1[] = { "AT+BRSF=438", "+BRSF:1007", @@ -72,8 +73,27 @@ const char * slc_test1[] = { "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_test1), + TEST_SEQUENCE(slc_test2) }; /* Service Level Connection (slc) common commands */