diff --git a/subsys/bluetooth/audio/audio_iso.c b/subsys/bluetooth/audio/audio_iso.c index ee38f6f0770..56403cf0202 100644 --- a/subsys/bluetooth/audio/audio_iso.c +++ b/subsys/bluetooth/audio/audio_iso.c @@ -184,7 +184,8 @@ void bt_audio_iso_unbind_ep(struct bt_audio_iso *iso, struct bt_audio_ep *ep) __ASSERT_NO_MSG(ep != NULL); __ASSERT_NO_MSG(iso != NULL); - __ASSERT(ep->iso == iso, "ep %p not bound with iso", iso, ep); + __ASSERT(ep->iso == iso, "ep %p not bound with iso %p, was bound to %p", + ep, iso, ep->iso); __ASSERT(ep->dir == BT_AUDIO_DIR_SINK || ep->dir == BT_AUDIO_DIR_SOURCE, "Invalid dir: %u", ep->dir); @@ -194,12 +195,12 @@ void bt_audio_iso_unbind_ep(struct bt_audio_iso *iso, struct bt_audio_ep *ep) bt_audio_ep_is_unicast_client(ep)) { /* For the unicast client, the direction and tx/rx is reversed */ if (ep->dir == BT_AUDIO_DIR_SOURCE) { - __ASSERT(iso->rx.ep == NULL, - "iso %p not bound with ep %p", iso, iso->rx.ep); + __ASSERT(iso->rx.ep == ep, + "iso %p not bound with ep %p", iso, ep); iso->rx.ep = NULL; } else { - __ASSERT(iso->tx.ep == NULL, - "iso %p not bound with ep %p", iso, iso->tx.ep); + __ASSERT(iso->tx.ep == ep, + "iso %p not bound with ep %p", iso, ep); iso->tx.ep = NULL; } } else { diff --git a/subsys/bluetooth/audio/stream.c b/subsys/bluetooth/audio/stream.c index 79f8001e4a2..eddc7298503 100644 --- a/subsys/bluetooth/audio/stream.c +++ b/subsys/bluetooth/audio/stream.c @@ -324,6 +324,10 @@ void bt_audio_stream_reset(struct bt_audio_stream *stream) return; } + if (stream->ep != NULL && stream->ep->iso != NULL) { + bt_audio_iso_unbind_ep(stream->ep->iso, stream->ep); + } + bt_audio_stream_detach(stream); } @@ -1139,11 +1143,23 @@ fail: int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group) { + struct bt_audio_stream *stream; + CHECKIF(unicast_group == NULL) { LOG_DBG("unicast_group is NULL"); return -EINVAL; } + SYS_SLIST_FOR_EACH_CONTAINER(&unicast_group->streams, stream, _node) { + /* If a stream has an endpoint, it is not ready to be removed + * from a group, as it is not in an idle state + */ + if (stream->ep != NULL) { + LOG_DBG("stream %p is not released", stream); + return -EINVAL; + } + } + if (unicast_group->cig != NULL) { const int err = bt_audio_cig_terminate(unicast_group);