Skip to content

Commit

Permalink
Bluetooth: CAP: Add reference to the set member for CAP discover
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thalley authored and jhedberg committed May 18, 2024
1 parent cc1894b commit f58ac34
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 15 deletions.
5 changes: 5 additions & 0 deletions doc/releases/migration-guide-3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=================
Expand Down
8 changes: 6 additions & 2 deletions include/zephyr/bluetooth/audio/cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions samples/bluetooth/tmap_central/src/cap_initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion subsys/bluetooth/audio/cap_commander.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
25 changes: 15 additions & 10 deletions subsys/bluetooth/audio/cap_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand All @@ -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 =
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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 =
Expand All @@ -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;
}
Expand All @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion subsys/bluetooth/audio/cap_initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion subsys/bluetooth/audio/cap_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions subsys/bluetooth/audio/csip_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
16 changes: 16 additions & 0 deletions subsys/bluetooth/audio/csip_set_coordinator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/audio/shell/cap_commander.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/audio/shell/cap_initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/audio/mocks/include/cap_commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/audio/mocks/src/cap_commander.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/tester/src/btp_cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/cap_commander_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/audio/src/gmap_ugg_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f58ac34

Please sign in to comment.