From ff71508d5f19da2cb035ddd8985bfca745bb5087 Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Wed, 6 Sep 2023 14:46:24 +0200 Subject: [PATCH] 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 --- subsys/bluetooth/audio/ascs.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/subsys/bluetooth/audio/ascs.c b/subsys/bluetooth/audio/ascs.c index c7c9e2e43b6..3ac041e2b7e 100644 --- a/subsys/bluetooth/audio/ascs.c +++ b/subsys/bluetooth/audio/ascs.c @@ -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; }