Skip to content

Commit

Permalink
Bluetooth: VCP: Fix missing guards for AICS and VOCS
Browse files Browse the repository at this point in the history
Some places VCP accessed AICS and VOCS when it was not supported.
Also modify existing guards to be consistent with new guards.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley authored and henrikbrixandersen committed Feb 5, 2024
1 parent adb74f0 commit 68ed2e0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
3 changes: 3 additions & 0 deletions include/zephyr/bluetooth/audio/vcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ int bt_vcp_vol_ctlr_conn_get(const struct bt_vcp_vol_ctlr *vol_ctlr,
* Volume Offset Control Service (Volume Offset Control Service) or
* Audio Input Control Service (AICS) instances.
*
* Requires that @kconfig{CONFIG_BT_VCP_VOL_CTLR_VOCS} or @kconfig{CONFIG_BT_VCP_VOL_CTLR_AICS} is
* enabled.
*
* @param vol_ctlr Volume Controller instance pointer.
* @param[out] included Pointer to store the result in.
*
Expand Down
4 changes: 4 additions & 0 deletions subsys/bluetooth/audio/vcp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ struct bt_vcp_vol_ctlr {
struct bt_uuid_16 uuid;
struct bt_conn *conn;

#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
uint8_t vocs_inst_cnt;
struct bt_vocs *vocs[CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST];
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
#if defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
uint8_t aics_inst_cnt;
struct bt_aics *aics[CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST];
#endif /* CONFIG_BT_VCP_VOL_CTLR_AICS */
};

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VCP_INTERNAL_*/
60 changes: 48 additions & 12 deletions subsys/bluetooth/audio/vcp_vol_ctlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,21 @@ static void vcp_vol_ctlr_discover_complete(struct bt_vcp_vol_ctlr *vol_ctlr, int

SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&vcp_vol_ctlr_cbs, listener, next, _node) {
if (listener->discover) {
listener->discover(vol_ctlr, err, err == 0 ? vol_ctlr->vocs_inst_cnt : 0,
err == 0 ? vol_ctlr->aics_inst_cnt : 0);
uint8_t vocs_cnt = 0U;
uint8_t aics_cnt = 0U;

#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
if (err == 0) {
vocs_cnt = vol_ctlr->vocs_inst_cnt;
}
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
#if defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
if (err == 0) {
aics_cnt = vol_ctlr->aics_inst_cnt;
}
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */

listener->discover(vol_ctlr, err, vocs_cnt, aics_cnt);
}
}
}
Expand Down Expand Up @@ -303,7 +316,7 @@ static void vcp_vol_ctlr_write_vcs_cp_cb(struct bt_conn *conn, uint8_t err,
vcs_cp_notify_app(vol_ctlr, opcode, err);
}

#if (CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST > 0 || CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST > 0)
#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS) || defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
static uint8_t vcs_discover_include_func(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
struct bt_gatt_discover_params *params)
Expand All @@ -314,8 +327,19 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
struct bt_vcp_vol_ctlr *vol_ctlr = vol_ctlr_get_by_conn(conn);

if (attr == NULL) {
LOG_DBG("Discover include complete for vol_ctlr: %u AICS and %u VOCS",
vol_ctlr->aics_inst_cnt, vol_ctlr->vocs_inst_cnt);
uint8_t vocs_cnt = 0U;
uint8_t aics_cnt = 0U;

#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
vocs_cnt = vol_ctlr->vocs_inst_cnt;
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */

#if defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
aics_cnt = vol_ctlr->aics_inst_cnt;
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */

LOG_DBG("Discover include complete for vol_ctlr: %u AICS and %u VOCS", aics_cnt,
vocs_cnt);
(void)memset(params, 0, sizeof(*params));

vcp_vol_ctlr_discover_complete(vol_ctlr, 0);
Expand All @@ -331,7 +355,7 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
include = (struct bt_gatt_include *)attr->user_data;
LOG_DBG("Include UUID %s", bt_uuid_str(include->uuid));

#if CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST > 0
#if defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
if (bt_uuid_cmp(include->uuid, BT_UUID_AICS) == 0 &&
vol_ctlr->aics_inst_cnt < CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST) {
struct bt_aics_discover_param param = {
Expand All @@ -355,8 +379,8 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,

return BT_GATT_ITER_STOP;
}
#endif /* CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST */
#if CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST > 0
#endif /* CONFIG_BT_VCP_VOL_CTLR_AICS */
#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
if (bt_uuid_cmp(include->uuid, BT_UUID_VOCS) == 0 &&
vol_ctlr->vocs_inst_cnt < CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST) {
struct bt_vocs_discover_param param = {
Expand All @@ -380,12 +404,12 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,

return BT_GATT_ITER_STOP;
}
#endif /* CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST */
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
}

return BT_GATT_ITER_CONTINUE;
}
#endif /* (CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST > 0 || CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST > 0) */
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS || CONFIG_BT_VCP_VOL_CTLR_AICS */

/**
* @brief This will discover all characteristics on the server, retrieving the
Expand All @@ -404,7 +428,7 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
if (attr == NULL) {
LOG_DBG("Setup complete for vol_ctlr");
(void)memset(params, 0, sizeof(*params));
#if (CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST > 0 || CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST > 0)
#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS) || defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
/* Discover included services */
vol_ctlr->discover_params.start_handle = vol_ctlr->start_handle;
vol_ctlr->discover_params.end_handle = vol_ctlr->end_handle;
Expand All @@ -418,7 +442,7 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
}
#else
vcp_vol_ctlr_discover_complete(vol_ctlr, err);
#endif /* (CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST > 0 || CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST > 0) */
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS || CONFIG_BT_VCP_VOL_CTLR_AICS */

return BT_GATT_ITER_STOP;
}
Expand Down Expand Up @@ -811,8 +835,12 @@ static void vcp_vol_ctlr_reset(struct bt_vcp_vol_ctlr *vol_ctlr)
vol_ctlr->state_handle = 0;
vol_ctlr->control_handle = 0;
vol_ctlr->flag_handle = 0;
#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
vol_ctlr->vocs_inst_cnt = 0;
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */
#if defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
vol_ctlr->aics_inst_cnt = 0;
#endif /* CONFIG_BT_VCP_VOL_CTLR_AICS */

memset(&vol_ctlr->discover_params, 0, sizeof(vol_ctlr->discover_params));

Expand Down Expand Up @@ -976,21 +1004,29 @@ int bt_vcp_vol_ctlr_cb_unregister(struct bt_vcp_vol_ctlr_cb *cb)
return 0;
}

#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS) || defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
int bt_vcp_vol_ctlr_included_get(struct bt_vcp_vol_ctlr *vol_ctlr,
struct bt_vcp_included *included)
{
CHECKIF(!included || vol_ctlr == NULL) {
return -EINVAL;
}

memset(included, 0, sizeof(*included));

#if defined(CONFIG_BT_VCP_VOL_CTLR_VOCS)
included->vocs_cnt = vol_ctlr->vocs_inst_cnt;
included->vocs = vol_ctlr->vocs;
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS */

#if defined(CONFIG_BT_VCP_VOL_CTLR_AICS)
included->aics_cnt = vol_ctlr->aics_inst_cnt;
included->aics = vol_ctlr->aics;
#endif /* CONFIG_BT_VCP_VOL_CTLR_AICS */

return 0;
}
#endif /* CONFIG_BT_VCP_VOL_CTLR_VOCS || CONFIG_BT_VCP_VOL_CTLR_AICS*/

struct bt_vcp_vol_ctlr *bt_vcp_vol_ctlr_get_by_conn(const struct bt_conn *conn)
{
Expand Down

0 comments on commit 68ed2e0

Please sign in to comment.