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 <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-05-15 14:08:48 +02:00 committed by Johan Hedberg
commit f58ac3476f
17 changed files with 59 additions and 15 deletions

View file

@ -312,6 +312,11 @@ Bluetooth Audio
:kconfig:option:`CONFIG_BT_ISO_PERIPHERAL` are not longer `select`ed automatically when :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 enabling :kconfig:option:`CONFIG_BT_BAP_UNICAST_SERVER`, and these must now be set explicitly
in the project configuration file. (:github:`71993`) 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 Bluetooth Classic
================= =================

View file

@ -63,14 +63,16 @@ struct bt_cap_initiator_cb {
* @param conn The connection pointer supplied to * @param conn The connection pointer supplied to
* bt_cap_initiator_unicast_discover(). * bt_cap_initiator_unicast_discover().
* @param err 0 if Common Audio Service was found else -ENODATA. * @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 * @param csis_inst The Coordinated Set Identification Service if
* Common Audio Service was found and includes a * Common Audio Service was found and includes a
* Coordinated Set Identification Service. * Coordinated Set Identification Service.
* NULL on error or if remote device does not include * 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)( void (*unicast_discovery_complete)(
struct bt_conn *conn, int err, 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); 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 * @param conn The connection pointer supplied to
* bt_cap_initiator_unicast_discover(). * bt_cap_initiator_unicast_discover().
* @param err 0 if Common Audio Service was found else -ENODATA. * @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 * @param csis_inst The Coordinated Set Identification Service if
* Common Audio Service was found and includes a * Common Audio Service was found and includes a
* Coordinated Set Identification Service. * Coordinated Set Identification Service.
* NULL on error or if remote device does not include * 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, 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); const struct bt_csip_set_coordinator_csis_inst *csis_inst);
#if defined(CONFIG_BT_VCP_VOL_CTLR) #if defined(CONFIG_BT_VCP_VOL_CTLR)

View file

@ -98,6 +98,7 @@ static struct bt_bap_lc3_preset unicast_preset_48_2_1 =
BT_AUDIO_CONTEXT_TYPE_MEDIA); BT_AUDIO_CONTEXT_TYPE_MEDIA);
static void cap_discovery_complete_cb(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (err != 0) { if (err != 0) {

View file

@ -65,10 +65,11 @@ int bt_cap_commander_unregister_cb(const struct bt_cap_commander_cb *cb)
static void static void
cap_commander_discover_complete(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (cap_cb && cap_cb->discovery_complete) { if (cap_cb && cap_cb->discovery_complete) {
cap_cb->discovery_complete(conn, err, csis_inst); cap_cb->discovery_complete(conn, err, member, csis_inst);
} }
} }

View file

@ -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, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
struct bt_cap_common_client *client; 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; const bt_cap_common_discover_func_t cb_func = client->discover_cb_func;
client->discover_cb_func = NULL; 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) { if (err != 0) {
LOG_DBG("CSIS client discover failed: %d", err); LOG_DBG("CSIS client discover failed: %d", err);
cap_common_discover_complete(conn, err, NULL); cap_common_discover_complete(conn, err, NULL, NULL);
return; 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) { if (member == NULL || set_count == 0 || client->csis_inst == NULL) {
LOG_ERR("Unable to find CSIS for CAS"); LOG_ERR("Unable to find CSIS for CAS");
cap_common_discover_complete(conn, -ENODATA, NULL); cap_common_discover_complete(conn, -ENODATA, NULL, NULL);
} else { } else {
LOG_DBG("Found CAS with CSIS"); 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) { if (attr == NULL) {
LOG_DBG("CAS CSIS include not found"); LOG_DBG("CAS CSIS include not found");
cap_common_discover_complete(conn, 0, NULL); cap_common_discover_complete(conn, 0, NULL, NULL);
} else { } else {
const struct bt_gatt_include *included_service = attr->user_data; const struct bt_gatt_include *included_service = attr->user_data;
struct bt_cap_common_client *client = 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); err = bt_csip_set_coordinator_discover(conn);
if (err != 0) { if (err != 0) {
LOG_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
cap_common_discover_complete(conn, err, NULL); cap_common_discover_complete(conn, err, NULL, NULL);
} }
} else { } 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"); 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) struct bt_gatt_discover_params *params)
{ {
if (attr == NULL) { if (attr == NULL) {
cap_common_discover_complete(conn, -ENODATA, NULL); cap_common_discover_complete(conn, -ENODATA, NULL, NULL);
} else { } else {
const struct bt_gatt_service_val *prim_service = attr->user_data; const struct bt_gatt_service_val *prim_service = attr->user_data;
struct bt_cap_common_client *client = 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) { if (attr->handle == prim_service->end_handle) {
LOG_DBG("Found CAS without CSIS"); 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; 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) { if (err != 0) {
LOG_DBG("Discover failed (err %d)", err); LOG_DBG("Discover failed (err %d)", err);
cap_common_discover_complete(conn, err, NULL); cap_common_discover_complete(conn, err, NULL, NULL);
} }
} }

View file

@ -315,10 +315,11 @@ int bt_cap_initiator_broadcast_get_base(struct bt_cap_broadcast_source *broadcas
static void static void
bt_cap_initiator_discover_complete(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (cap_cb && cap_cb->unicast_discovery_complete) { 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);
} }
} }

View file

@ -118,7 +118,8 @@ struct bt_cap_commander_proc_param {
}; };
typedef void (*bt_cap_common_discover_func_t)( 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 { struct bt_cap_common_proc_param {
union { union {

View file

@ -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_csip_set_coordinator_csis_inst *bt_csip_set_coordinator_csis_inst_by_handle(
struct bt_conn *conn, uint16_t start_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);

View file

@ -1418,6 +1418,22 @@ struct bt_csip_set_coordinator_csis_inst *bt_csip_set_coordinator_csis_inst_by_h
return NULL; 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 ***************************/ /*************************** PUBLIC FUNCTIONS ***************************/
int bt_csip_set_coordinator_register_cb(struct bt_csip_set_coordinator_cb *cb) int bt_csip_set_coordinator_register_cb(struct bt_csip_set_coordinator_cb *cb)
{ {

View file

@ -19,6 +19,7 @@
#include "audio.h" #include "audio.h"
static void cap_discover_cb(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (err != 0) { if (err != 0) {

View file

@ -25,6 +25,7 @@
#define CAP_UNICAST_CLIENT_STREAM_COUNT ARRAY_SIZE(unicast_streams) #define CAP_UNICAST_CLIENT_STREAM_COUNT ARRAY_SIZE(unicast_streams)
static void cap_discover_cb(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (err != 0) { if (err != 0) {

View file

@ -16,6 +16,7 @@ void mock_cap_commander_init(void);
void mock_cap_commander_cleanup(void); void mock_cap_commander_cleanup(void);
DECLARE_FAKE_VOID_FUNC(mock_cap_commander_discovery_complete_cb, struct bt_conn *, int, 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 *); 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_changed_cb, struct bt_conn *, int);
DECLARE_FAKE_VOID_FUNC(mock_cap_commander_volume_mute_changed_cb, struct bt_conn *, int); DECLARE_FAKE_VOID_FUNC(mock_cap_commander_volume_mute_changed_cb, struct bt_conn *, int);

View file

@ -18,6 +18,7 @@
FAKE(mock_cap_commander_microphone_gain_changed_cb) FAKE(mock_cap_commander_microphone_gain_changed_cb)
DEFINE_FAKE_VOID_FUNC(mock_cap_commander_discovery_complete_cb, struct bt_conn *, int, 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 *); const struct bt_csip_set_coordinator_csis_inst *);
DEFINE_FAKE_VOID_FUNC(mock_cap_commander_volume_changed_cb, struct bt_conn *, int); DEFINE_FAKE_VOID_FUNC(mock_cap_commander_volume_changed_cb, struct bt_conn *, int);

View file

@ -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, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
LOG_DBG(""); LOG_DBG("");

View file

@ -36,6 +36,7 @@ CREATE_FLAG(flag_microphone_mute_changed);
CREATE_FLAG(flag_microphone_gain_changed); CREATE_FLAG(flag_microphone_gain_changed);
static void cap_discovery_complete_cb(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (err != 0) { if (err != 0) {

View file

@ -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, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (err != 0) { if (err != 0) {

View file

@ -263,6 +263,7 @@ static struct bt_bap_stream_ops stream_ops = {
}; };
static void cap_discovery_complete_cb(struct bt_conn *conn, int err, 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) const struct bt_csip_set_coordinator_csis_inst *csis_inst)
{ {
if (err != 0) { if (err != 0) {