Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: CAP: Add support for handling ASE errors #79014

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,16 @@ int bt_bap_stream_start(struct bt_bap_stream *stream);
*
* @param stream Stream object
*
* @retval 0 Success
* @retval -EINVAL The @p stream does not have an endpoint or a connection, of the stream's
* connection's role is not @p BT_HCI_ROLE_CENTRAL
* @retval -EBADMSG The state of the @p stream endpoint is not @ref BT_BAP_EP_STATE_DISABLING
* @retval -EALREADY The CIS state of the @p is not in a connected state, and thus is already
* stopping
* @retval -EBUSY The @p stream is busy with another operation
* @retval -ENOTCONN The @p stream ACL connection is not connected
* @retval -ENOMEM No memory to send request
* @retval -ENOEXEC The request was rejected by GATT
* @return 0 in case of success or negative value in case of error.
*/
int bt_bap_stream_stop(struct bt_bap_stream *stream);
Expand Down
35 changes: 34 additions & 1 deletion 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 All @@ -3512,7 +3534,18 @@ int bt_bap_unicast_client_stop(struct bt_bap_stream *stream)
}
req->num_ases++;

return bt_bap_unicast_client_ep_send(stream->conn, ep, buf);
err = bt_bap_unicast_client_ep_send(stream->conn, ep, buf);
if (err != 0) {
/* Return expected error directly */
if (err == -ENOTCONN || err == -ENOMEM) {
return err;
}

LOG_DBG("bt_bap_unicast_client_ep_send failed with unexpected error %d",
err);

return -ENOEXEC;
}
}

return 0;
Expand Down
Loading
Loading