diff --git a/include/zephyr/bluetooth/audio/bap.h b/include/zephyr/bluetooth/audio/bap.h index c9aaf558a90..1684f5a56b4 100644 --- a/include/zephyr/bluetooth/audio/bap.h +++ b/include/zephyr/bluetooth/audio/bap.h @@ -1249,9 +1249,6 @@ struct bt_bap_unicast_client_discover_params { /** Capabilities type */ enum bt_audio_dir dir; - /** Number of capabilities found */ - uint8_t num_caps; - /** Number of endpoints found */ uint8_t num_eps; diff --git a/samples/bluetooth/unicast_audio_client/src/main.c b/samples/bluetooth/unicast_audio_client/src/main.c index 82d3f26cf51..20cbc0f3350 100644 --- a/samples/bluetooth/unicast_audio_client/src/main.c +++ b/samples/bluetooth/unicast_audio_client/src/main.c @@ -574,11 +574,9 @@ static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) sinks[index].ep = ep; } -static void print_remote_codec(struct bt_codec *codec_capabilities, int index, - enum bt_audio_dir dir) +static void print_remote_codec(struct bt_codec *codec_capabilities, enum bt_audio_dir dir) { - printk("#%u: codec_capabilities %p dir 0x%02x\n", - index, codec_capabilities, dir); + printk("codec_capabilities %p dir 0x%02x\n", codec_capabilities, dir); print_codec_capabilities(codec_capabilities); } @@ -593,7 +591,7 @@ static void discover_sinks_cb(struct bt_conn *conn, int err, struct bt_codec *co } if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(codec, params->dir); return; } @@ -624,7 +622,7 @@ static void discover_sources_cb(struct bt_conn *conn, int err, struct bt_codec * } if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(codec, params->dir); return; } diff --git a/subsys/bluetooth/audio/bap_unicast_client.c b/subsys/bluetooth/audio/bap_unicast_client.c index 7071fc3557d..7945d5da85a 100644 --- a/subsys/bluetooth/audio/bap_unicast_client.c +++ b/subsys/bluetooth/audio/bap_unicast_client.c @@ -3488,6 +3488,7 @@ static uint8_t unicast_client_read_func(struct bt_conn *conn, uint8_t err, struct bt_pacs_read_rsp *rsp; struct net_buf_simple *buf; int cb_err = err; + uint8_t i; params = CONTAINER_OF(read, struct bt_bap_unicast_client_discover_params, read); @@ -3533,13 +3534,13 @@ static uint8_t unicast_client_read_func(struct bt_conn *conn, uint8_t err, goto fail; } - while (rsp->num_pac) { + for (i = 0U; i < rsp->num_pac; i++) { struct bt_pac_codec *pac_codec; struct bt_pac_ltv_data *meta, *cc; void *cc_ltv, *meta_ltv; struct bt_codec codec; - LOG_DBG("pac #%u", params->num_caps); + LOG_DBG("pac #%u", i); if (buf->len < sizeof(*pac_codec)) { LOG_ERR("Malformed PAC: remaining len %u expected %zu", @@ -3595,12 +3596,11 @@ static uint8_t unicast_client_read_func(struct bt_conn *conn, uint8_t err, codec.meta_count); discover_cb(conn, 0, &codec, NULL, params); - - rsp->num_pac--; - params->num_caps++; } - if (!params->num_caps) { + if (i != rsp->num_pac) { + LOG_DBG("Failed to process all PAC records (%u/%u)", i, rsp->num_pac); + cb_err = BT_ATT_ERR_INVALID_PDU; goto fail; } @@ -3706,7 +3706,6 @@ int bt_bap_unicast_client_discover(struct bt_conn *conn, conn_cb_registered = true; } - params->num_caps = 0u; params->num_eps = 0u; return bt_gatt_discover(conn, ¶ms->discover); diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 4fa6d2d9c02..60a8116b6aa 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -703,11 +703,10 @@ static uint8_t stream_dir(const struct bt_bap_stream *stream) return 0; } -static void print_remote_codec(const struct bt_conn *conn, struct bt_codec *codec, uint8_t index, +static void print_remote_codec(const struct bt_conn *conn, struct bt_codec *codec, enum bt_audio_dir dir) { - shell_print(ctx_shell, "conn %p: #%u: codec %p dir 0x%02x", - conn, index, codec, dir); + shell_print(ctx_shell, "conn %p: codec %p dir 0x%02x", conn, codec, dir); print_codec(ctx_shell, codec); } @@ -736,7 +735,7 @@ static void discover_cb(struct bt_conn *conn, int err, struct bt_codec *codec, s struct bt_bap_unicast_client_discover_params *params) { if (codec != NULL) { - print_remote_codec(conn, codec, params->num_caps, params->dir); + print_remote_codec(conn, codec, params->dir); return; } @@ -765,7 +764,7 @@ static void discover_all(struct bt_conn *conn, int err, struct bt_codec *codec, struct bt_bap_ep *ep, struct bt_bap_unicast_client_discover_params *params) { if (codec != NULL) { - print_remote_codec(conn, codec, params->num_caps, params->dir); + print_remote_codec(conn, codec, params->dir); return; } diff --git a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c index 2720d3bf5e1..69ed859aaa2 100644 --- a/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c +++ b/tests/bsim/bluetooth/audio/src/bap_unicast_client_test.c @@ -212,9 +212,9 @@ static void add_remote_source(struct bt_bap_ep *ep, uint8_t index) g_sources[index] = ep; } -static void print_remote_codec(struct bt_codec *codec, int index, enum bt_audio_dir dir) +static void print_remote_codec(struct bt_codec *codec, enum bt_audio_dir dir) { - printk("#%u: codec %p dir 0x%02x\n", index, codec, dir); + printk("codec %p dir 0x%02x\n", codec, dir); print_codec(codec); } @@ -232,7 +232,7 @@ static void discover_sinks_cb(struct bt_conn *conn, int err, struct bt_codec *co } if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(codec, params->dir); codec_found = true; return; } @@ -272,7 +272,7 @@ static void discover_sources_cb(struct bt_conn *conn, int err, struct bt_codec * } if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(codec, params->dir); codec_found = true; return; } diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c index 964932309ee..6a097f7a6ea 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_test.c @@ -249,9 +249,9 @@ static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index) unicast_sink_eps[index] = ep; } -static void print_remote_codec(struct bt_codec *codec, int index, enum bt_audio_dir dir) +static void print_remote_codec(struct bt_codec *codec, enum bt_audio_dir dir) { - printk("#%u: codec %p dir 0x%02x\n", index, codec, dir); + printk("codec %p dir 0x%02x\n", codec, dir); print_codec(codec); } @@ -269,7 +269,7 @@ static void discover_sink_cb(struct bt_conn *conn, int err, struct bt_codec *cod } if (codec != NULL) { - print_remote_codec(codec, params->num_caps, params->dir); + print_remote_codec(codec, params->dir); codec_found = true; return;