From f58ac3476fac566335622778c396202138e42b32 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 15 May 2024 14:08:48 +0200 Subject: [PATCH] Bluetooth: CAP: Add reference to the set member for CAP discover Since the CSIP API expects a set member struct for nearly all functionality, the reference to the full set member (along with the CAS specific CSIS) should be given to the application. Signed-off-by: Emil Gydesen --- doc/releases/migration-guide-3.7.rst | 5 ++++ include/zephyr/bluetooth/audio/cap.h | 8 ++++-- .../tmap_central/src/cap_initiator.c | 1 + subsys/bluetooth/audio/cap_commander.c | 3 ++- subsys/bluetooth/audio/cap_common.c | 25 +++++++++++-------- subsys/bluetooth/audio/cap_initiator.c | 3 ++- subsys/bluetooth/audio/cap_internal.h | 3 ++- subsys/bluetooth/audio/csip_internal.h | 2 ++ subsys/bluetooth/audio/csip_set_coordinator.c | 16 ++++++++++++ subsys/bluetooth/audio/shell/cap_commander.c | 1 + subsys/bluetooth/audio/shell/cap_initiator.c | 1 + .../audio/mocks/include/cap_commander.h | 1 + .../bluetooth/audio/mocks/src/cap_commander.c | 1 + tests/bluetooth/tester/src/btp_cap.c | 1 + .../bluetooth/audio/src/cap_commander_test.c | 1 + .../audio/src/cap_initiator_unicast_test.c | 1 + .../bsim/bluetooth/audio/src/gmap_ugg_test.c | 1 + 17 files changed, 59 insertions(+), 15 deletions(-) diff --git a/doc/releases/migration-guide-3.7.rst b/doc/releases/migration-guide-3.7.rst index 0ba7d361c03..3222d6ad9c0 100644 --- a/doc/releases/migration-guide-3.7.rst +++ b/doc/releases/migration-guide-3.7.rst @@ -312,6 +312,11 @@ Bluetooth Audio :kconfig:option:`CONFIG_BT_ISO_PERIPHERAL` are not longer `select`ed automatically when enabling :kconfig:option:`CONFIG_BT_BAP_UNICAST_SERVER`, and these must now be set explicitly in the project configuration file. (:github:`71993`) +* The discover callback functions :code:`bt_cap_initiator_cb.unicast_discovery_complete`` and + :code:`bt_cap_commander_cb.discovery_complete`` for CAP now contain an additional parameter for + the set member. + This needs to be added to all instances of CAP discovery callback functions defined. + (:github:`72797`) Bluetooth Classic ================= diff --git a/include/zephyr/bluetooth/audio/cap.h b/include/zephyr/bluetooth/audio/cap.h index a6cfcb418d6..6bf5e1b018e 100644 --- a/include/zephyr/bluetooth/audio/cap.h +++ b/include/zephyr/bluetooth/audio/cap.h @@ -63,14 +63,16 @@ struct bt_cap_initiator_cb { * @param conn The connection pointer supplied to * bt_cap_initiator_unicast_discover(). * @param err 0 if Common Audio Service was found else -ENODATA. + * @param member Pointer to the set member. NULL if err != 0. * @param csis_inst The Coordinated Set Identification Service if * Common Audio Service was found and includes a * Coordinated Set Identification Service. * NULL on error or if remote device does not include - * Coordinated Set Identification Service. + * Coordinated Set Identification Service. NULL if err != 0. */ void (*unicast_discovery_complete)( struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst); /** @@ -676,13 +678,15 @@ struct bt_cap_commander_cb { * @param conn The connection pointer supplied to * bt_cap_initiator_unicast_discover(). * @param err 0 if Common Audio Service was found else -ENODATA. + * @param member Pointer to the set member. NULL if err != 0. * @param csis_inst The Coordinated Set Identification Service if * Common Audio Service was found and includes a * Coordinated Set Identification Service. * NULL on error or if remote device does not include - * Coordinated Set Identification Service. + * Coordinated Set Identification Service. NULL if err != 0. */ void (*discovery_complete)(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst); #if defined(CONFIG_BT_VCP_VOL_CTLR) diff --git a/samples/bluetooth/tmap_central/src/cap_initiator.c b/samples/bluetooth/tmap_central/src/cap_initiator.c index dc7e54c439d..fd20fadaa71 100644 --- a/samples/bluetooth/tmap_central/src/cap_initiator.c +++ b/samples/bluetooth/tmap_central/src/cap_initiator.c @@ -98,6 +98,7 @@ static struct bt_bap_lc3_preset unicast_preset_48_2_1 = BT_AUDIO_CONTEXT_TYPE_MEDIA); static void cap_discovery_complete_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (err != 0) { diff --git a/subsys/bluetooth/audio/cap_commander.c b/subsys/bluetooth/audio/cap_commander.c index 7a9c1663594..80fd66c103a 100644 --- a/subsys/bluetooth/audio/cap_commander.c +++ b/subsys/bluetooth/audio/cap_commander.c @@ -65,10 +65,11 @@ int bt_cap_commander_unregister_cb(const struct bt_cap_commander_cb *cb) static void cap_commander_discover_complete(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (cap_cb && cap_cb->discovery_complete) { - cap_cb->discovery_complete(conn, err, csis_inst); + cap_cb->discovery_complete(conn, err, member, csis_inst); } } diff --git a/subsys/bluetooth/audio/cap_common.c b/subsys/bluetooth/audio/cap_common.c index ea450411599..cd4ee8639f0 100644 --- a/subsys/bluetooth/audio/cap_common.c +++ b/subsys/bluetooth/audio/cap_common.c @@ -256,6 +256,7 @@ struct bt_cap_common_client *bt_cap_common_get_client(enum bt_cap_set_type type, } static void cap_common_discover_complete(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { struct bt_cap_common_client *client; @@ -265,7 +266,7 @@ static void cap_common_discover_complete(struct bt_conn *conn, int err, const bt_cap_common_discover_func_t cb_func = client->discover_cb_func; client->discover_cb_func = NULL; - cb_func(conn, err, csis_inst); + cb_func(conn, err, member, csis_inst); } } @@ -278,7 +279,7 @@ static void csis_client_discover_cb(struct bt_conn *conn, if (err != 0) { LOG_DBG("CSIS client discover failed: %d", err); - cap_common_discover_complete(conn, err, NULL); + cap_common_discover_complete(conn, err, NULL, NULL); return; } @@ -290,10 +291,10 @@ static void csis_client_discover_cb(struct bt_conn *conn, if (member == NULL || set_count == 0 || client->csis_inst == NULL) { LOG_ERR("Unable to find CSIS for CAS"); - cap_common_discover_complete(conn, -ENODATA, NULL); + cap_common_discover_complete(conn, -ENODATA, NULL, NULL); } else { LOG_DBG("Found CAS with CSIS"); - cap_common_discover_complete(conn, 0, client->csis_inst); + cap_common_discover_complete(conn, 0, member, client->csis_inst); } } @@ -304,7 +305,7 @@ static uint8_t bt_cap_common_discover_included_cb(struct bt_conn *conn, if (attr == NULL) { LOG_DBG("CAS CSIS include not found"); - cap_common_discover_complete(conn, 0, NULL); + cap_common_discover_complete(conn, 0, NULL, NULL); } else { const struct bt_gatt_include *included_service = attr->user_data; struct bt_cap_common_client *client = @@ -335,11 +336,15 @@ static uint8_t bt_cap_common_discover_included_cb(struct bt_conn *conn, err = bt_csip_set_coordinator_discover(conn); if (err != 0) { LOG_DBG("Discover failed (err %d)", err); - cap_common_discover_complete(conn, err, NULL); + cap_common_discover_complete(conn, err, NULL, NULL); } } else { + const struct bt_csip_set_coordinator_set_member *member = + bt_csip_set_coordinator_csis_member_by_conn(conn); + LOG_DBG("Found CAS with CSIS"); - cap_common_discover_complete(conn, 0, client->csis_inst); + + cap_common_discover_complete(conn, 0, member, client->csis_inst); } } @@ -350,7 +355,7 @@ static uint8_t bt_cap_common_discover_cas_cb(struct bt_conn *conn, const struct struct bt_gatt_discover_params *params) { if (attr == NULL) { - cap_common_discover_complete(conn, -ENODATA, NULL); + cap_common_discover_complete(conn, -ENODATA, NULL, NULL); } else { const struct bt_gatt_service_val *prim_service = attr->user_data; struct bt_cap_common_client *client = @@ -362,7 +367,7 @@ static uint8_t bt_cap_common_discover_cas_cb(struct bt_conn *conn, const struct if (attr->handle == prim_service->end_handle) { LOG_DBG("Found CAS without CSIS"); - cap_common_discover_complete(conn, 0, NULL); + cap_common_discover_complete(conn, 0, NULL, NULL); return BT_GATT_ITER_STOP; } @@ -379,7 +384,7 @@ static uint8_t bt_cap_common_discover_cas_cb(struct bt_conn *conn, const struct if (err != 0) { LOG_DBG("Discover failed (err %d)", err); - cap_common_discover_complete(conn, err, NULL); + cap_common_discover_complete(conn, err, NULL, NULL); } } diff --git a/subsys/bluetooth/audio/cap_initiator.c b/subsys/bluetooth/audio/cap_initiator.c index cd57f97e11c..3f750e9516f 100644 --- a/subsys/bluetooth/audio/cap_initiator.c +++ b/subsys/bluetooth/audio/cap_initiator.c @@ -315,10 +315,11 @@ int bt_cap_initiator_broadcast_get_base(struct bt_cap_broadcast_source *broadcas static void bt_cap_initiator_discover_complete(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (cap_cb && cap_cb->unicast_discovery_complete) { - cap_cb->unicast_discovery_complete(conn, err, csis_inst); + cap_cb->unicast_discovery_complete(conn, err, member, csis_inst); } } diff --git a/subsys/bluetooth/audio/cap_internal.h b/subsys/bluetooth/audio/cap_internal.h index a2605e4b0c7..ad94a97a965 100644 --- a/subsys/bluetooth/audio/cap_internal.h +++ b/subsys/bluetooth/audio/cap_internal.h @@ -118,7 +118,8 @@ struct bt_cap_commander_proc_param { }; typedef void (*bt_cap_common_discover_func_t)( - struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_csis_inst *csis_inst); + struct bt_conn *conn, int err, const struct bt_csip_set_coordinator_set_member *member, + const struct bt_csip_set_coordinator_csis_inst *csis_inst); struct bt_cap_common_proc_param { union { diff --git a/subsys/bluetooth/audio/csip_internal.h b/subsys/bluetooth/audio/csip_internal.h index 082a96d2f1b..86dcdcc0161 100644 --- a/subsys/bluetooth/audio/csip_internal.h +++ b/subsys/bluetooth/audio/csip_internal.h @@ -48,3 +48,5 @@ struct bt_csip_set_coordinator_svc_inst { struct bt_csip_set_coordinator_csis_inst *bt_csip_set_coordinator_csis_inst_by_handle( struct bt_conn *conn, uint16_t start_handle); +struct bt_csip_set_coordinator_set_member * +bt_csip_set_coordinator_csis_member_by_conn(struct bt_conn *conn); diff --git a/subsys/bluetooth/audio/csip_set_coordinator.c b/subsys/bluetooth/audio/csip_set_coordinator.c index b59587ebdfc..fb68aa2ee9e 100644 --- a/subsys/bluetooth/audio/csip_set_coordinator.c +++ b/subsys/bluetooth/audio/csip_set_coordinator.c @@ -1418,6 +1418,22 @@ struct bt_csip_set_coordinator_csis_inst *bt_csip_set_coordinator_csis_inst_by_h return NULL; } +struct bt_csip_set_coordinator_set_member * +bt_csip_set_coordinator_csis_member_by_conn(struct bt_conn *conn) +{ + struct bt_csip_set_coordinator_inst *client; + + CHECKIF(conn == NULL) { + LOG_DBG("conn is NULL"); + + return NULL; + } + + client = &client_insts[bt_conn_index(conn)]; + + return &client->set_member; +} + /*************************** PUBLIC FUNCTIONS ***************************/ int bt_csip_set_coordinator_register_cb(struct bt_csip_set_coordinator_cb *cb) { diff --git a/subsys/bluetooth/audio/shell/cap_commander.c b/subsys/bluetooth/audio/shell/cap_commander.c index 1042f3530a2..16a6d5ce7f8 100644 --- a/subsys/bluetooth/audio/shell/cap_commander.c +++ b/subsys/bluetooth/audio/shell/cap_commander.c @@ -19,6 +19,7 @@ #include "audio.h" static void cap_discover_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (err != 0) { diff --git a/subsys/bluetooth/audio/shell/cap_initiator.c b/subsys/bluetooth/audio/shell/cap_initiator.c index 54d2e7caf53..d5b7496eb19 100644 --- a/subsys/bluetooth/audio/shell/cap_initiator.c +++ b/subsys/bluetooth/audio/shell/cap_initiator.c @@ -25,6 +25,7 @@ #define CAP_UNICAST_CLIENT_STREAM_COUNT ARRAY_SIZE(unicast_streams) static void cap_discover_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (err != 0) { diff --git a/tests/bluetooth/audio/mocks/include/cap_commander.h b/tests/bluetooth/audio/mocks/include/cap_commander.h index 1e56aca6930..6133ce2ae64 100644 --- a/tests/bluetooth/audio/mocks/include/cap_commander.h +++ b/tests/bluetooth/audio/mocks/include/cap_commander.h @@ -16,6 +16,7 @@ void mock_cap_commander_init(void); void mock_cap_commander_cleanup(void); DECLARE_FAKE_VOID_FUNC(mock_cap_commander_discovery_complete_cb, struct bt_conn *, int, + const struct bt_csip_set_coordinator_set_member *, const struct bt_csip_set_coordinator_csis_inst *); DECLARE_FAKE_VOID_FUNC(mock_cap_commander_volume_changed_cb, struct bt_conn *, int); DECLARE_FAKE_VOID_FUNC(mock_cap_commander_volume_mute_changed_cb, struct bt_conn *, int); diff --git a/tests/bluetooth/audio/mocks/src/cap_commander.c b/tests/bluetooth/audio/mocks/src/cap_commander.c index 4305f8e1b8e..c652de7946c 100644 --- a/tests/bluetooth/audio/mocks/src/cap_commander.c +++ b/tests/bluetooth/audio/mocks/src/cap_commander.c @@ -18,6 +18,7 @@ FAKE(mock_cap_commander_microphone_gain_changed_cb) DEFINE_FAKE_VOID_FUNC(mock_cap_commander_discovery_complete_cb, struct bt_conn *, int, + const struct bt_csip_set_coordinator_set_member *, const struct bt_csip_set_coordinator_csis_inst *); DEFINE_FAKE_VOID_FUNC(mock_cap_commander_volume_changed_cb, struct bt_conn *, int); diff --git a/tests/bluetooth/tester/src/btp_cap.c b/tests/bluetooth/tester/src/btp_cap.c index c8ddf116b0e..58d34bd0651 100644 --- a/tests/bluetooth/tester/src/btp_cap.c +++ b/tests/bluetooth/tester/src/btp_cap.c @@ -50,6 +50,7 @@ static void btp_send_discovery_completed_ev(struct bt_conn *conn, uint8_t status } static void cap_discovery_complete_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { LOG_DBG(""); diff --git a/tests/bsim/bluetooth/audio/src/cap_commander_test.c b/tests/bsim/bluetooth/audio/src/cap_commander_test.c index 9271a6a12de..8d100ebb826 100644 --- a/tests/bsim/bluetooth/audio/src/cap_commander_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_commander_test.c @@ -36,6 +36,7 @@ CREATE_FLAG(flag_microphone_mute_changed); CREATE_FLAG(flag_microphone_gain_changed); static void cap_discovery_complete_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (err != 0) { diff --git a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c index 3ae18ced886..0a4daa04ca1 100644 --- a/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c +++ b/tests/bsim/bluetooth/audio/src/cap_initiator_unicast_test.c @@ -185,6 +185,7 @@ static struct bt_bap_stream_ops unicast_stream_ops = { }; static void cap_discovery_complete_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (err != 0) { diff --git a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c index 3048dfa8999..1d686a31016 100644 --- a/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c +++ b/tests/bsim/bluetooth/audio/src/gmap_ugg_test.c @@ -263,6 +263,7 @@ static struct bt_bap_stream_ops stream_ops = { }; static void cap_discovery_complete_cb(struct bt_conn *conn, int err, + const struct bt_csip_set_coordinator_set_member *member, const struct bt_csip_set_coordinator_csis_inst *csis_inst) { if (err != 0) {