Bluetooth: Audio: Fix issue with deleting unicast groups

There was a bug in bt_audio_iso_unbind_ep that caused an
assert, missing unbinding on stream released callback
and missing state check in bt_audio_unicast_group_delete

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2022-12-22 11:01:00 +01:00 committed by Carles Cufí
commit 4c058402a5
2 changed files with 22 additions and 5 deletions

View file

@ -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(ep != NULL);
__ASSERT_NO_MSG(iso != 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, __ASSERT(ep->dir == BT_AUDIO_DIR_SINK || ep->dir == BT_AUDIO_DIR_SOURCE,
"Invalid dir: %u", ep->dir); "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)) { bt_audio_ep_is_unicast_client(ep)) {
/* For the unicast client, the direction and tx/rx is reversed */ /* For the unicast client, the direction and tx/rx is reversed */
if (ep->dir == BT_AUDIO_DIR_SOURCE) { if (ep->dir == BT_AUDIO_DIR_SOURCE) {
__ASSERT(iso->rx.ep == NULL, __ASSERT(iso->rx.ep == ep,
"iso %p not bound with ep %p", iso, iso->rx.ep); "iso %p not bound with ep %p", iso, ep);
iso->rx.ep = NULL; iso->rx.ep = NULL;
} else { } else {
__ASSERT(iso->tx.ep == NULL, __ASSERT(iso->tx.ep == ep,
"iso %p not bound with ep %p", iso, iso->tx.ep); "iso %p not bound with ep %p", iso, ep);
iso->tx.ep = NULL; iso->tx.ep = NULL;
} }
} else { } else {

View file

@ -324,6 +324,10 @@ void bt_audio_stream_reset(struct bt_audio_stream *stream)
return; return;
} }
if (stream->ep != NULL && stream->ep->iso != NULL) {
bt_audio_iso_unbind_ep(stream->ep->iso, stream->ep);
}
bt_audio_stream_detach(stream); bt_audio_stream_detach(stream);
} }
@ -1139,11 +1143,23 @@ fail:
int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group) int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group)
{ {
struct bt_audio_stream *stream;
CHECKIF(unicast_group == NULL) { CHECKIF(unicast_group == NULL) {
LOG_DBG("unicast_group is NULL"); LOG_DBG("unicast_group is NULL");
return -EINVAL; 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) { if (unicast_group->cig != NULL) {
const int err = bt_audio_cig_terminate(unicast_group); const int err = bt_audio_cig_terminate(unicast_group);