diff --git a/src/shared/bap.c b/src/shared/bap.c
index a0f5a0a..72ce67c 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
return stream->io == io;
}
-static void stream_stop_disabling(void *data, void *user_data)
-{
- struct bt_bap_stream *stream = data;
-
- if (stream->io || stream->ep->state != BT_ASCS_ASE_STATE_DISABLING)
- return;
-
- DBG(stream->bap, "stream %p", stream);
-
- bt_bap_stream_stop(stream, NULL, NULL);
-}
-
static bool bap_stream_io_detach(struct bt_bap_stream *stream)
{
struct bt_bap_stream *link;
/* Detach link if in QoS state */
if (link->ep->state == BT_ASCS_ASE_STATE_QOS)
bap_stream_io_detach(link);
- } else {
- /* Links without IO on disabling state shall be stopped. */
- queue_foreach(stream->links, stream_stop_disabling, NULL);
}
stream_io_unref(io);
return bt_bap_ref(bap);
}
+static void stream_stop_complete(struct bt_bap_stream *stream, uint8_t code,
+ uint8_t reason, void *user_data)
+{
+ DBG(stream->bap, "stream %p stop 0x%02x 0x%02x", stream, code, reason);
+
+ if (stream->ep->state == BT_ASCS_ASE_STATE_DISABLING)
+ bap_stream_io_detach(stream);
+}
+
static void bap_stream_state_changed(struct bt_bap_stream *stream)
{
struct bt_bap *bap = stream->bap;
bap_stream_update_io_links(stream);
break;
case BT_ASCS_ASE_STATE_DISABLING:
- bap_stream_io_detach(stream);
+ /* As client, we detach after Receiver Stop Ready */
+ if (!stream->client)
+ bap_stream_io_detach(stream);
break;
case BT_ASCS_ASE_STATE_QOS:
if (stream->io && !stream->io->connecting)
bt_bap_stream_start(stream, NULL, NULL);
break;
case BT_ASCS_ASE_STATE_DISABLING:
- if (!bt_bap_stream_get_io(stream))
- bt_bap_stream_stop(stream, NULL, NULL);
+ /* Send Stop Ready, and detach IO after remote replies */
+ if (stream->client)
+ bt_bap_stream_stop(stream, stream_stop_complete, NULL);
break;
}