Bluetooth: audio: ascs: Add endpoint by stream lookup function

This adds endpoint by stream lookup function used to find the active
endpoints that use the stream object provided. The function is used
instead of dereferencing stream->ep that may be not valid if application
did not memset the stream object.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2023-09-06 14:46:24 +02:00 committed by Fabio Baltieri
parent c1214f2067
commit ff71508d5f

View File

@ -1480,6 +1480,19 @@ static int ase_config(struct bt_ascs_ase *ase, const struct bt_ascs_config *cfg)
return 0;
}
static struct bt_bap_ep *ep_lookup_stream(struct bt_conn *conn, struct bt_bap_stream *stream)
{
for (size_t i = 0; i < ARRAY_SIZE(ase_pool); i++) {
struct bt_ascs_ase *ase = &ase_pool[i];
if (ase->conn == conn && ase->ep.stream == stream) {
return &ase->ep;
}
}
return NULL;
}
int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream,
struct bt_audio_codec_cfg *codec_cfg,
const struct bt_audio_codec_qos_pref *qos_pref)
@ -1494,7 +1507,8 @@ int bt_ascs_config_ase(struct bt_conn *conn, struct bt_bap_stream *stream,
return -EINVAL;
}
if (stream->ep != NULL) {
ep = ep_lookup_stream(conn, stream);
if (ep != NULL) {
LOG_DBG("Stream already configured for conn %p", (void *)stream->conn);
return -EALREADY;
}