diff --git a/src/shared/bap.c b/src/shared/bap.c
index d8a3add..a1495ca 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
bap_stream_io_detach(stream);
}
+static void bap_req_free(void *data)
+{
+ struct bt_bap_req *req = data;
+ size_t i;
+
+ queue_destroy(req->group, bap_req_free);
+
+ for (i = 0; i < req->len; i++)
+ free(req->iov[i].iov_base);
+
+ free(req->iov);
+ free(req);
+}
+
+static void bap_req_complete(struct bt_bap_req *req,
+ const struct bt_ascs_ase_rsp *rsp)
+{
+ struct queue *group;
+
+ if (!req->func)
+ goto done;
+
+ if (rsp)
+ req->func(req->stream, rsp->code, rsp->reason, req->user_data);
+ else
+ req->func(req->stream, BT_ASCS_RSP_UNSPECIFIED, 0x00,
+ req->user_data);
+
+done:
+ /* Detach from request so it can be freed separately */
+ group = req->group;
+ req->group = NULL;
+
+ queue_foreach(group, (queue_foreach_func_t)bap_req_complete,
+ (void *)rsp);
+
+ queue_destroy(group, NULL);
+
+ bap_req_free(req);
+}
+
static void bap_stream_state_changed(struct bt_bap_stream *stream)
{
struct bt_bap *bap = stream->bap;
/* Post notification updates */
switch (stream->ep->state) {
case BT_ASCS_ASE_STATE_IDLE:
+ if (bap->req && bap->req->stream == stream) {
+ bap_req_complete(bap->req, NULL);
+ bap->req = NULL;
+ }
bap_stream_detach(stream);
break;
case BT_ASCS_ASE_STATE_QOS:
free(state);
}
-static void bap_req_free(void *data)
-{
- struct bt_bap_req *req = data;
- size_t i;
-
- queue_destroy(req->group, bap_req_free);
-
- for (i = 0; i < req->len; i++)
- free(req->iov[i].iov_base);
-
- free(req->iov);
- free(req);
-}
-
static void bap_detached(void *data, void *user_data)
{
struct bt_bap_cb *cb = data;
DBG(bap, "req %p len %u", req, iov.iov_len);
+ if (req->stream && !queue_find(bap->streams, NULL, req->stream)) {
+ DBG(bap, "stream %p detached, aborting op 0x%02x", req->op);
+ return false;
+ }
+
if (!gatt_db_attribute_get_char_data(ascs->ase_cp, NULL, &handle,
NULL, NULL, NULL)) {
DBG(bap, "Unable to find Control Point");
return true;
}
-static void bap_req_complete(struct bt_bap_req *req,
- const struct bt_ascs_ase_rsp *rsp)
-{
- struct queue *group;
-
- if (!req->func)
- goto done;
-
- if (rsp)
- req->func(req->stream, rsp->code, rsp->reason, req->user_data);
- else
- req->func(req->stream, BT_ASCS_RSP_UNSPECIFIED, 0x00,
- req->user_data);
-
-done:
- /* Detach from request so it can be freed separately */
- group = req->group;
- req->group = NULL;
-
- queue_foreach(group, (queue_foreach_func_t)bap_req_complete,
- (void *)rsp);
-
- queue_destroy(group, NULL);
-
- bap_req_free(req);
-}
-
static bool bap_process_queue(void *data)
{
struct bt_bap *bap = data;