Skip to content

Commit

Permalink
Bluetooth: CAP: Add support for handling ASE errors
Browse files Browse the repository at this point in the history
If we get an error/rejection from the CAP acceptor when
performing the Unicast Audio Start or Stop procedure then
we need to abort the procedure and let the application determine
what the next step is.

This change triggered a corner case when connecting to multiple
CAP acceptors as the CAP initiatior that was fixed as part
of this.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
  • Loading branch information
Thalley committed Sep 27, 2024
1 parent e924baa commit fc21c88
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 90 deletions.
22 changes: 0 additions & 22 deletions subsys/bluetooth/audio/bap_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@ int bt_bap_stream_enable(struct bt_bap_stream *stream, const uint8_t meta[], siz

int bt_bap_stream_stop(struct bt_bap_stream *stream)
{
enum bt_iso_state iso_state;
struct bt_bap_ep *ep;
uint8_t role;
int err;
Expand All @@ -726,27 +725,6 @@ int bt_bap_stream_stop(struct bt_bap_stream *stream)
return -EBADMSG;
}

/* ASCS_v1.0 3.2 ASE state machine transitions
*
* If the server detects link loss of a CIS for an ASE in the Streaming state or the
* Disabling state, the server shall immediately transition that ASE to the QoS Configured
* state.
*
* This effectively means that if an ASE no longer has a connected CIS, the server shall
* bring it to the QoS Configured state. That means that we, as a unicast client, should not
* attempt to stop it
*/
if (ep->iso == NULL) {
LOG_DBG("Stream endpoint does not have a CIS, server will stop the ASE");
return -EALREADY;
}

iso_state = ep->iso->chan.state;
if (iso_state != BT_ISO_STATE_CONNECTED && iso_state != BT_ISO_STATE_CONNECTING) {
LOG_DBG("Stream endpoint CIS is not connected, server will stop the ASE");
return -EALREADY;
}

err = bt_bap_unicast_client_stop(stream);
if (err != 0) {
LOG_DBG("Stopping stream failed: %d", err);
Expand Down
22 changes: 22 additions & 0 deletions subsys/bluetooth/audio/bap_unicast_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -3481,6 +3481,7 @@ int bt_bap_unicast_client_disable(struct bt_bap_stream *stream)
int bt_bap_unicast_client_stop(struct bt_bap_stream *stream)
{
struct bt_bap_ep *ep = stream->ep;
enum bt_iso_state iso_state;
struct net_buf_simple *buf;
struct bt_ascs_start_op *req;
int err;
Expand All @@ -3493,6 +3494,27 @@ int bt_bap_unicast_client_stop(struct bt_bap_stream *stream)
return -ENOTCONN;
}

/* ASCS_v1.0 3.2 ASE state machine transitions
*
* If the server detects link loss of a CIS for an ASE in the Streaming state or the
* Disabling state, the server shall immediately transition that ASE to the QoS Configured
* state.
*
* This effectively means that if an ASE no longer has a connected CIS, the server shall
* bring it to the QoS Configured state. That means that we, as a unicast client, should not
* attempt to stop it
*/
if (ep->iso == NULL) {
LOG_DBG("Stream endpoint does not have a CIS, server will stop the ASE");
return -EALREADY;
}

iso_state = ep->iso->chan.state;
if (iso_state != BT_ISO_STATE_CONNECTED && iso_state != BT_ISO_STATE_CONNECTING) {
LOG_DBG("Stream endpoint CIS is not connected, server will stop the ASE");
return -EALREADY;
}

buf = bt_bap_unicast_client_ep_create_pdu(stream->conn, BT_ASCS_STOP_OP);
if (buf == NULL) {
LOG_DBG("Could not create PDU");
Expand Down
Loading

0 comments on commit fc21c88

Please sign in to comment.