Bluetooth: BAP: Fix bad check in bt_audio_valid_qos_pref

The checks did not properly take into account
that the pref_pd_min and pref_pd_max could have valid
0 values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-10-04 11:09:29 +02:00 committed by Carles Cufí
parent 8fc0aba4ae
commit b2e61ef355
1 changed files with 29 additions and 18 deletions

View File

@ -298,30 +298,41 @@ bool bt_bap_valid_qos_pref(const struct bt_bap_qos_cfg_pref *qos_pref)
return false;
}
/* The absolute minimum and maximum values of pref_pd_min and pref_pd_max are implicitly
* checked using the bounds of pd_min and pd_max, so we can just compare the preferences
* to the min and max values that have been bound checked already
*/
if (qos_pref->pref_pd_min != BT_AUDIO_PD_PREF_NONE) {
/* If pref_pd_min != BT_AUDIO_PD_PREF_NONE then pd_min <= pref_pd_min <= pd_max */
if (!IN_RANGE(qos_pref->pref_pd_min, qos_pref->pd_min, qos_pref->pd_max)) {
LOG_DBG("Invalid combination of pref_pd_min %u, pd_min %u and pd_max: %u",
qos_pref->pref_pd_min, qos_pref->pd_min, qos_pref->pd_max);
return false;
}
if (qos_pref->pref_pd_max < qos_pref->pref_pd_min) {
LOG_DBG("Invalid combination of pref_pd_min %u and pref_pd_max: %u",
qos_pref->pref_pd_min, qos_pref->pref_pd_max);
return false;
}
if (qos_pref->pref_pd_max != BT_AUDIO_PD_PREF_NONE) {
/* If pref_pd_min == BT_AUDIO_PD_PREF_NONE then pd_min <= pref_pd_max <= pd_max
*
* If pref_pd_min != BT_AUDIO_PD_PREF_NONE then
* pd_min <= pref_pd_min <= pref_pd_max <= pd_max
*/
if (qos_pref->pref_pd_min == BT_AUDIO_PD_PREF_NONE) {
if (!IN_RANGE(qos_pref->pref_pd_max, qos_pref->pd_min, qos_pref->pd_max)) {
LOG_DBG("Invalid combination of pref_pd_max %u, pd_min %u and pd_max: %u",
LOG_DBG("Invalid combination of pref_pd_max %u, pd_min %u and "
"pd_max: %u",
qos_pref->pref_pd_max, qos_pref->pd_min, qos_pref->pd_max);
return false;
}
} else {
if (!IN_RANGE(qos_pref->pref_pd_max, qos_pref->pref_pd_min,
qos_pref->pd_max)) {
LOG_DBG("Invalid combination of pref_pd_max %u, pref_pd_min %u and "
"pd_max: %u",
qos_pref->pref_pd_max, qos_pref->pd_min, qos_pref->pd_max);
return false;
}
}
}
return true;
}