hfp: filter link setting by allowed sco packet types

This commit is contained in:
Matthias Ringwald 2020-09-08 18:21:38 +02:00
parent 3427dd75c1
commit 01e5b7274c
2 changed files with 36 additions and 4 deletions

View File

@ -165,7 +165,7 @@ static void (*hfp_hf_run_for_context)(hfp_connection_t * hfp_connection);
static hfp_connection_t * sco_establishment_active;
// HFP_SCO_PACKET_TYPES_NONE == no choice/override
static uint16_t hfp_accept_sco_packet_types;
static uint16_t hfp_allowed_sco_packet_types;
// prototypes
static hfp_link_settings_t hfp_next_link_setting_for_connection(hfp_link_settings_t current_setting, hfp_connection_t * hfp_connection, uint8_t eSCO_S4_supported);
@ -1625,15 +1625,15 @@ void hfp_set_hf_run_for_context(void (*callback)(hfp_connection_t * hfp_connecti
}
void hfp_init(void){
hfp_accept_sco_packet_types = HFP_SCO_PACKET_TYPES_NONE;
hfp_allowed_sco_packet_types = HFP_SCO_PACKET_TYPES_NONE;
}
void hfp_set_sco_packet_types(uint16_t packet_types){
hfp_accept_sco_packet_types = packet_types;
hfp_allowed_sco_packet_types = packet_types;
}
uint16_t hfp_get_sco_packet_types(void){
return hfp_accept_sco_packet_types;
return hfp_allowed_sco_packet_types;
}
hfp_link_settings_t hfp_next_link_setting(hfp_link_settings_t current_setting, bool local_eSCO_supported, bool remote_eSCO_supported, bool eSCO_S4_supported, uint8_t negotiated_codec){
@ -1647,6 +1647,11 @@ hfp_link_settings_t hfp_next_link_setting(hfp_link_settings_t current_setting, b
if ((setting == (int8_t) HFP_LINK_SETTINGS_S4) && !eSCO_S4_supported) continue;
// skip wrong codec
if ( hfp_link_settings[setting].codec != negotiated_codec) continue;
// skip disabled packet types
uint16_t required_packet_types = hfp_link_settings[setting].packet_types ^ HFP_SCO_PACKET_TYPES_NONE;
uint16_t allowed_packet_types = hfp_allowed_sco_packet_types ^HFP_SCO_PACKET_TYPES_NONE;
if ((allowed_packet_types != 0) && ((required_packet_types & allowed_packet_types) == 0)) continue;
// found matching setting
return (hfp_link_settings_t) setting;
}

View File

@ -7,6 +7,7 @@
TEST_GROUP(HFPLinkSettings){
void setup(void){
hfp_set_sco_packet_types(HFP_SCO_PACKET_TYPES_NONE);
}
void teardown(void){
}
@ -55,6 +56,32 @@ TEST(HFPLinkSettings, D1_D0){
CHECK_EQUAL(HFP_LINK_SETTINGS_D0, hfp_next_link_setting(HFP_LINK_SETTINGS_D1, true, false, true, HFP_CODEC_CVSD));
}
// initial settings based on packet types
TEST(HFPLinkSettings, HV1){
hfp_set_sco_packet_types(HFP_SCO_PACKET_TYPES_HV1);
CHECK_EQUAL(HFP_LINK_SETTINGS_D0, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, false, true, true, HFP_CODEC_CVSD));
CHECK_EQUAL(HFP_LINK_SETTINGS_D0, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, false, true, HFP_CODEC_CVSD));
}
TEST(HFPLinkSettings, HV3){
hfp_set_sco_packet_types(HFP_SCO_PACKET_TYPES_HV3);
CHECK_EQUAL(HFP_LINK_SETTINGS_D1, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, false, HFP_CODEC_CVSD));
}
TEST(HFPLinkSettings, EV3){
hfp_set_sco_packet_types(HFP_SCO_PACKET_TYPES_EV3);
CHECK_EQUAL(HFP_LINK_SETTINGS_S1, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, true, HFP_CODEC_CVSD));
CHECK_EQUAL(HFP_LINK_SETTINGS_T1, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, true, HFP_CODEC_MSBC));
}
TEST(HFPLinkSettings, 2EV3){
hfp_set_sco_packet_types(HFP_SCO_PACKET_TYPES_2EV3);
CHECK_EQUAL(HFP_LINK_SETTINGS_S3, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, false, HFP_CODEC_CVSD));
CHECK_EQUAL(HFP_LINK_SETTINGS_S4, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, true, HFP_CODEC_CVSD));
CHECK_EQUAL(HFP_LINK_SETTINGS_T2, hfp_next_link_setting(HFP_LINK_SETTINGS_NONE, true, true, true, HFP_CODEC_MSBC));
}
int main (int argc, const char * argv[]){
return CommandLineTestRunner::RunAllTests(argc, argv);
}