Skip to content

Commit

Permalink
Bluetooth: BAP: Improve handling of ASCS notification error
Browse files Browse the repository at this point in the history
If the num_ase == 0xff then it is a special case that needs to be
handled like if num_ase == 0x01.

If there is an error with ase_id = 0x00 then the error cannot
be translated to a specific stream, so the callbacks may now get
NULL for the stream object.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
  • Loading branch information
Thalley authored and carlescufi committed Jun 6, 2023
1 parent 5a57fa2 commit c764c34
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
21 changes: 14 additions & 7 deletions include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,8 @@ struct bt_bap_unicast_client_cb {
* This will be called for each stream in the group that was being QoS
* configured.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand All @@ -1138,7 +1139,8 @@ struct bt_bap_unicast_client_cb {
*
* Called when the enable operation is completed on the server.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand All @@ -1152,7 +1154,8 @@ struct bt_bap_unicast_client_cb {
* only be called if the stream supplied to bt_bap_stream_start() is
* for a @ref BT_AUDIO_DIR_SOURCE endpoint.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand All @@ -1166,7 +1169,8 @@ struct bt_bap_unicast_client_cb {
* only be called if the stream supplied to bt_bap_stream_stop() is
* for a @ref BT_AUDIO_DIR_SOURCE endpoint.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand All @@ -1178,7 +1182,8 @@ struct bt_bap_unicast_client_cb {
*
* Called when the disable operation is completed on the server.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand All @@ -1190,7 +1195,8 @@ struct bt_bap_unicast_client_cb {
*
* Called when the metadata operation is completed on the server.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand All @@ -1202,7 +1208,8 @@ struct bt_bap_unicast_client_cb {
*
* Called when the release operation is completed on the server.
*
* @param stream Stream the operation was performed on.
* @param stream Stream the operation was performed on. May be NULL if there is no stream
* associated with the ASE ID sent by the server.
* @param rsp_code Response code.
* @param reason Reason code.
*/
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/audio/ascs.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ static void ascs_cp_rsp_add(uint8_t id, uint8_t code, uint8_t reason)
*/
case BT_BAP_ASCS_RSP_CODE_NOT_SUPPORTED:
case BT_BAP_ASCS_RSP_CODE_INVALID_LENGTH:
rsp->num_ase = 0xff;
rsp->num_ase = BT_ASCS_UNSUPP_OR_LENGTH_ERR_NUM_ASE;
break;
default:
rsp->num_ase++;
Expand Down
5 changes: 5 additions & 0 deletions subsys/bluetooth/audio/ascs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

#define BT_ASCS_ASE_ID_NONE 0x00

/* The number of ASEs in the notification when the opcode is unsupported or the length of the
* control point write request is incorrect
*/
#define BT_ASCS_UNSUPP_OR_LENGTH_ERR_NUM_ASE 0xFFU

/* Transport QoS Packing */
#define BT_ASCS_QOS_PACKING_SEQ 0x00
#define BT_ASCS_QOS_PACKING_INT 0x01
Expand Down
21 changes: 15 additions & 6 deletions subsys/bluetooth/audio/bap_unicast_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,13 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,

rsp = net_buf_simple_pull_mem(&buf, sizeof(*rsp));

if (rsp->num_ase == BT_ASCS_UNSUPP_OR_LENGTH_ERR_NUM_ASE) {
/* This is a special case where num_ase == BT_ASCS_UNSUPP_OR_LENGTH_ERR_NUM_ASE
* but really there is only one ASE response
*/
rsp->num_ase = 1U;
}

for (uint8_t i = 0U; i < rsp->num_ase; i++) {
struct bt_bap_unicast_client_ep *client_ep;
struct bt_ascs_cp_ase_rsp *ase_rsp;
Expand All @@ -1355,11 +1362,8 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
stream = audio_stream_by_ep_id(conn, ase_rsp->id);
if (stream == NULL) {
LOG_DBG("Could not find stream by id %u", ase_rsp->id);
continue;
}

client_ep = CONTAINER_OF(stream->ep, struct bt_bap_unicast_client_ep, ep);

switch (rsp->op) {
case BT_ASCS_CONFIG_OP:
if (unicast_client_cbs->config != NULL) {
Expand Down Expand Up @@ -1398,9 +1402,14 @@ static uint8_t unicast_client_cp_notify(struct bt_conn *conn,
}
break;
case BT_ASCS_RELEASE_OP:
if (client_ep->release_requested) {
/* Set to false to only handle the callback here */
client_ep->release_requested = false;
if (stream != NULL) {
client_ep = CONTAINER_OF(stream->ep,
struct bt_bap_unicast_client_ep, ep);

if (client_ep->release_requested) {
/* Set to false to only handle the callback here */
client_ep->release_requested = false;
}
}

if (unicast_client_cbs->release != NULL) {
Expand Down

0 comments on commit c764c34

Please sign in to comment.