Bluetooth: Audio: Update VCS API to use bt_vcs

Update the VCS API to use the bt_vcs struct instead
of the bt_conn. This is create a more simple API
that uses a, remote or loca, instance pointer, rather
than a specified connection (for remote) or NULL (for
local) operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2021-05-30 20:27:10 +02:00 committed by Carles Cufí
commit 0043c741a5
8 changed files with 640 additions and 516 deletions

View file

@ -94,20 +94,19 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs);
* Volume Offset Control Service (Volume Offset Control Service) or
* Audio Input Control Service (AICS) instances.
*
* @param conn Connection to peer device, or NULL to get server value.
* @param vcs Volume Control Service instance pointer.
* @param[out] included Pointer to store the result in.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_included_get(struct bt_conn *conn, struct bt_vcs_included *included);
int bt_vcs_included_get(struct bt_vcs *vcs, struct bt_vcs_included *included);
/**
* @brief Callback function for bt_vcs_discover.
*
* This callback is only used for the client.
*
* @param conn The connection that was used to discover
* Volume Control Service.
* @param vcs Volume Control Service instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* @param vocs_count Number of Volume Offset Control Service instances
@ -115,7 +114,7 @@ int bt_vcs_included_get(struct bt_conn *conn, struct bt_vcs_included *included);
* @param aics_count Number of Audio Input Control Service instances on
* peer device.
*/
typedef void (*bt_vcs_discover_cb)(struct bt_conn *conn, int err,
typedef void (*bt_vcs_discover_cb)(struct bt_vcs *vcs, int err,
uint8_t vocs_count, uint8_t aics_count);
/**
@ -125,14 +124,13 @@ typedef void (*bt_vcs_discover_cb)(struct bt_conn *conn, int err,
* Called when the value is remotely read as the client.
* Called if the value is changed by either the server or client.
*
* @param conn NULL if local server read or write, otherwise the connection
* to the peer device if remotely read or written.
* @param vcs Volume Control Service instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* @param volume The volume of the Volume Control Service server.
* @param mute The mute setting of the Volume Control Service server.
*/
typedef void (*bt_vcs_state_cb)(struct bt_conn *conn, int err, uint8_t volume,
typedef void (*bt_vcs_state_cb)(struct bt_vcs *vcs, int err, uint8_t volume,
uint8_t mute);
/**
@ -142,24 +140,22 @@ typedef void (*bt_vcs_state_cb)(struct bt_conn *conn, int err, uint8_t volume,
* Called when the value is remotely read as the client.
* Called if the value is changed by either the server or client.
*
* @param conn NULL if local server read or write, otherwise the connection
* to the peer device if remotely read or written.
* @param vcs Volume Control Service instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* @param flags The flags of the Volume Control Service server.
*/
typedef void (*bt_vcs_flags_cb)(struct bt_conn *conn, int err, uint8_t flags);
typedef void (*bt_vcs_flags_cb)(struct bt_vcs *vcs, int err, uint8_t flags);
/**
* @brief Callback function for writes.
*
* This callback is only used for the client.
*
* @param conn NULL if local server read or write, otherwise the connection
* to the peer device if remotely read or written.
* @param vcs Volume Control Service instance pointer.
* @param err Error value. 0 on success, GATT error on fail.
*/
typedef void (*bt_vcs_write_cb)(struct bt_conn *conn, int err);
typedef void (*bt_vcs_write_cb)(struct bt_vcs *vcs, int err);
struct bt_vcs_cb {
/* Volume Control Service */
@ -217,152 +213,149 @@ int bt_vcs_vol_step_set(uint8_t volume_step);
/**
* @brief Read the Volume Control Service volume state.
*
* @param conn Connection to the peer device,
* or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vol_get(struct bt_conn *conn);
int bt_vcs_vol_get(struct bt_vcs *vcs);
/**
* @brief Read the Volume Control Service flags.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_flags_get(struct bt_conn *conn);
int bt_vcs_flags_get(struct bt_vcs *vcs);
/**
* @brief Turn the volume down by one step on the server.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vol_down(struct bt_conn *conn);
int bt_vcs_vol_down(struct bt_vcs *vcs);
/**
* @brief Turn the volume up by one step on the server.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vol_up(struct bt_conn *conn);
int bt_vcs_vol_up(struct bt_vcs *vcs);
/**
* @brief Turn the volume down and unmute the server.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_unmute_vol_down(struct bt_conn *conn);
int bt_vcs_unmute_vol_down(struct bt_vcs *vcs);
/**
* @brief Turn the volume up and unmute the server.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_unmute_vol_up(struct bt_conn *conn);
int bt_vcs_unmute_vol_up(struct bt_vcs *vcs);
/**
* @brief Set the volume on the server
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param volume The absolute volume to set.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vol_set(struct bt_conn *conn, uint8_t volume);
int bt_vcs_vol_set(struct bt_vcs *vcs, uint8_t volume);
/**
* @brief Unmute the server.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_unmute(struct bt_conn *conn);
int bt_vcs_unmute(struct bt_vcs *vcs);
/**
* @brief Mute the server.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_mute(struct bt_conn *conn);
int bt_vcs_mute(struct bt_vcs *vcs);
/**
* @brief Read the Volume Offset Control Service offset state.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Volume Offset Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vocs_state_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vcs_vocs_state_get(struct bt_vcs *vcs, struct bt_vocs *inst);
/**
* @brief Read the Volume Offset Control Service location.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Volume Offset Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vocs_location_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vcs_vocs_location_get(struct bt_vcs *vcs, struct bt_vocs *inst);
/**
* @brief Set the Volume Offset Control Service location.
*
* @param conn Connection to peer device, or NULL to set local server
* value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Volume Offset Control Service instance.
* @param location The location to set.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vocs_location_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vcs_vocs_location_set(struct bt_vcs *vcs, struct bt_vocs *inst,
uint8_t location);
/**
* @brief Set the Volume Offset Control Service offset state.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Volume Offset Control Service instance.
* @param offset The offset to set (-255 to 255).
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vocs_state_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vcs_vocs_state_set(struct bt_vcs *vcs, struct bt_vocs *inst,
int16_t offset);
/**
* @brief Read the Volume Offset Control Service output description.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Volume Offset Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vcs_vocs_description_get(struct bt_vcs *vcs, struct bt_vocs *inst);
/**
* @brief Set the Volume Offset Control Service description.
*
* @param conn Connection to peer device, or NULL to set local server
* value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Volume Offset Control Service instance.
* @param description The description to set.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vcs_vocs_description_set(struct bt_vcs *vcs, struct bt_vocs *inst,
const char *description);
/**
@ -371,11 +364,12 @@ int bt_vcs_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst,
* Audio Input Control Services are activated by default, but this will allow
* the server to deactivate an Audio Input Control Service.
*
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_deactivate(struct bt_aics *inst);
int bt_vcs_aics_deactivate(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Activates an Audio Input Control Service instance.
@ -384,125 +378,125 @@ int bt_vcs_aics_deactivate(struct bt_aics *inst);
* the server to reactivate an Audio Input Control Service instance after it has
* been deactivated with @ref bt_vcs_aics_deactivate.
*
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_activate(struct bt_aics *inst);
int bt_vcs_aics_activate(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Read the Audio Input Control Service input state.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_state_get(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_state_get(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Read the Audio Input Control Service gain settings.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_gain_setting_get(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_gain_setting_get(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Read the Audio Input Control Service input type.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_type_get(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_type_get(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Read the Audio Input Control Service input status.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_status_get(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_status_get(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Mute the Audio Input Control Service input.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_mute(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_mute(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Unmute the Audio Input Control Service input.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_unmute(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_unmute(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Set input gain to manual.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_manual_gain_set(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_manual_gain_set(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Set the input gain to automatic.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_automatic_gain_set(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_automatic_gain_set(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Set the input gain.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
* @param gain The gain in dB to set (-128 to 127).
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_gain_set(struct bt_conn *conn, struct bt_aics *inst,
int bt_vcs_aics_gain_set(struct bt_vcs *vcs, struct bt_aics *inst,
int8_t gain);
/**
* @brief Read the Audio Input Control Service description.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_description_get(struct bt_conn *conn, struct bt_aics *inst);
int bt_vcs_aics_description_get(struct bt_vcs *vcs, struct bt_aics *inst);
/**
* @brief Set the Audio Input Control Service description.
*
* @param conn Connection to peer device, or NULL to set local server
* value.
* @param vcs Volume Control Service instance pointer.
* @param inst Pointer to the Audio Input Control Service instance.
* @param description The description to set.
*
* @return 0 if success, errno on failure.
*/
int bt_vcs_aics_description_set(struct bt_conn *conn, struct bt_aics *inst,
int bt_vcs_aics_description_set(struct bt_vcs *vcs, struct bt_aics *inst,
const char *description);
/**

View file

@ -10,6 +10,7 @@
#include <zephyr.h>
#include <sys/byteorder.h>
#include <sys/check.h>
#include <device.h>
#include <init.h>
@ -25,6 +26,40 @@
#define LOG_MODULE_NAME bt_vcs
#include "common/log.h"
static bool valid_vocs_inst(struct bt_vcs *vcs, struct bt_vocs *vocs)
{
if (vocs == NULL) {
return false;
}
#if defined(CONFIG_BT_VCS)
for (int i = 0; i < ARRAY_SIZE(vcs->srv.vocs_insts); i++) {
if (vcs->srv.vocs_insts[i] == vocs) {
return true;
}
}
#endif /* CONFIG_BT_VCS */
return false;
}
static bool valid_aics_inst(struct bt_vcs *vcs, struct bt_aics *aics)
{
if (aics == NULL) {
return false;
}
#if defined(CONFIG_BT_VCS)
for (int i = 0; i < ARRAY_SIZE(vcs->srv.aics_insts); i++) {
if (vcs->srv.aics_insts[i] == aics) {
return true;
}
}
#endif /* CONFIG_BT_VCS */
return false;
}
#if defined(CONFIG_BT_VCS)
#define VOLUME_DOWN(current_vol) \
@ -173,7 +208,8 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
&vcs_inst.srv.state, sizeof(vcs_inst.srv.state));
if (vcs_inst.srv.cb && vcs_inst.srv.cb->state) {
vcs_inst.srv.cb->state(conn, 0, vcs_inst.srv.state.volume,
vcs_inst.srv.cb->state(&vcs_inst, 0,
vcs_inst.srv.state.volume,
vcs_inst.srv.state.mute);
}
}
@ -186,7 +222,7 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
&vcs_inst.srv.flags, sizeof(vcs_inst.srv.flags));
if (vcs_inst.srv.cb && vcs_inst.srv.cb->flags) {
vcs_inst.srv.cb->flags(conn, 0, vcs_inst.srv.flags);
vcs_inst.srv.cb->flags(&vcs_inst, 0, vcs_inst.srv.flags);
}
}
return len;
@ -360,18 +396,38 @@ int bt_vcs_register(struct bt_vcs_register_param *param, struct bt_vcs **vcs)
return err;
}
int bt_vcs_aics_deactivate(struct bt_aics *inst)
int bt_vcs_aics_deactivate(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (inst == NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
CHECKIF(inst == NULL) {
BT_DBG("NULL aics instance");
return -EINVAL;
}
if (!valid_aics_inst(vcs, inst)) {
return -EINVAL;
}
return bt_aics_deactivate(inst);
}
int bt_vcs_aics_activate(struct bt_aics *inst)
int bt_vcs_aics_activate(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (inst == NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
CHECKIF(inst == NULL) {
BT_DBG("NULL aics instance");
return -EINVAL;
}
if (!valid_aics_inst(vcs, inst)) {
return -EINVAL;
}
@ -380,45 +436,16 @@ int bt_vcs_aics_activate(struct bt_aics *inst)
#endif /* CONFIG_BT_VCS */
static bool valid_vocs_inst(struct bt_vocs *vocs)
int bt_vcs_included_get(struct bt_vcs *vcs, struct bt_vcs_included *included)
{
if (vocs == NULL) {
return false;
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
#if defined(CONFIG_BT_VCS)
for (int i = 0; i < ARRAY_SIZE(vcs_inst.srv.vocs_insts); i++) {
if (vcs_inst.srv.vocs_insts[i] == vocs) {
return true;
}
}
#endif /* CONFIG_BT_VCS */
return false;
}
static bool valid_aics_inst(struct bt_aics *aics)
{
if (aics == NULL) {
return false;
}
#if defined(CONFIG_BT_VCS)
for (int i = 0; i < ARRAY_SIZE(vcs_inst.srv.aics_insts); i++) {
if (vcs_inst.srv.aics_insts[i] == aics) {
return true;
}
}
#endif /* CONFIG_BT_VCS */
return false;
}
int bt_vcs_included_get(struct bt_conn *conn, struct bt_vcs_included *included)
{
if (conn != NULL) {
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_included_get(conn, included);
return bt_vcs_client_included_get(vcs, included);
} else {
return -EOPNOTSUPP;
}
@ -429,11 +456,11 @@ int bt_vcs_included_get(struct bt_conn *conn, struct bt_vcs_included *included)
return -EINVAL;
}
included->vocs_cnt = ARRAY_SIZE(vcs_inst.srv.vocs_insts);
included->vocs = vcs_inst.srv.vocs_insts;
included->vocs_cnt = ARRAY_SIZE(vcs->srv.vocs_insts);
included->vocs = vcs->srv.vocs_insts;
included->aics_cnt = ARRAY_SIZE(vcs_inst.srv.aics_insts);
included->aics = vcs_inst.srv.aics_insts;
included->aics_cnt = ARRAY_SIZE(vcs->srv.aics_insts);
included->aics = vcs->srv.aics_insts;
return 0;
#else
@ -455,20 +482,25 @@ int bt_vcs_vol_step_set(uint8_t volume_step)
return -EOPNOTSUPP;
}
int bt_vcs_vol_get(struct bt_conn *conn)
int bt_vcs_vol_get(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_read_vol_state(conn);
return bt_vcs_client_read_vol_state(vcs);
} else {
return -EOPNOTSUPP;
}
}
#if defined(CONFIG_BT_VCS)
if (vcs_inst.srv.cb && vcs_inst.srv.cb->state) {
vcs_inst.srv.cb->state(conn, 0, vcs_inst.srv.state.volume,
vcs_inst.srv.state.mute);
if (vcs->srv.cb && vcs->srv.cb->state) {
vcs->srv.cb->state(vcs, 0, vcs->srv.state.volume,
vcs->srv.state.mute);
}
return 0;
@ -477,19 +509,24 @@ int bt_vcs_vol_get(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_flags_get(struct bt_conn *conn)
int bt_vcs_flags_get(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_read_flags(conn);
return bt_vcs_client_read_flags(vcs);
} else {
return -EOPNOTSUPP;
}
}
#if defined(CONFIG_BT_VCS)
if (vcs_inst.srv.cb && vcs_inst.srv.cb->flags) {
vcs_inst.srv.cb->flags(conn, 0, vcs_inst.srv.flags);
if (vcs->srv.cb && vcs->srv.cb->flags) {
vcs->srv.cb->flags(vcs, 0, vcs->srv.flags);
}
return 0;
@ -498,11 +535,16 @@ int bt_vcs_flags_get(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_vol_down(struct bt_conn *conn)
int bt_vcs_vol_down(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_vol_down(conn);
return bt_vcs_client_vol_down(vcs);
} else {
return -EOPNOTSUPP;
}
@ -511,7 +553,7 @@ int bt_vcs_vol_down(struct bt_conn *conn)
#if defined(CONFIG_BT_VCS)
const struct vcs_control cp = {
.opcode = BT_VCS_OPCODE_REL_VOL_DOWN,
.counter = vcs_inst.srv.state.change_counter,
.counter = vcs->srv.state.change_counter,
};
int err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
@ -521,11 +563,16 @@ int bt_vcs_vol_down(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_vol_up(struct bt_conn *conn)
int bt_vcs_vol_up(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_vol_up(conn);
return bt_vcs_client_vol_up(vcs);
} else {
return -EOPNOTSUPP;
}
@ -534,7 +581,7 @@ int bt_vcs_vol_up(struct bt_conn *conn)
#if defined(CONFIG_BT_VCS)
const struct vcs_control cp = {
.opcode = BT_VCS_OPCODE_REL_VOL_UP,
.counter = vcs_inst.srv.state.change_counter,
.counter = vcs->srv.state.change_counter,
};
int err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
@ -544,11 +591,16 @@ int bt_vcs_vol_up(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_unmute_vol_down(struct bt_conn *conn)
int bt_vcs_unmute_vol_down(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_unmute_vol_down(conn);
return bt_vcs_client_unmute_vol_down(vcs);
} else {
return -EOPNOTSUPP;
}
@ -557,7 +609,7 @@ int bt_vcs_unmute_vol_down(struct bt_conn *conn)
#if defined(CONFIG_BT_VCS)
const struct vcs_control cp = {
.opcode = BT_VCS_OPCODE_UNMUTE_REL_VOL_DOWN,
.counter = vcs_inst.srv.state.change_counter,
.counter = vcs->srv.state.change_counter,
};
int err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
@ -567,11 +619,16 @@ int bt_vcs_unmute_vol_down(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_unmute_vol_up(struct bt_conn *conn)
int bt_vcs_unmute_vol_up(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_unmute_vol_up(conn);
return bt_vcs_client_unmute_vol_up(vcs);
} else {
return -EOPNOTSUPP;
}
@ -580,7 +637,7 @@ int bt_vcs_unmute_vol_up(struct bt_conn *conn)
#if defined(CONFIG_BT_VCS)
const struct vcs_control cp = {
.opcode = BT_VCS_OPCODE_UNMUTE_REL_VOL_UP,
.counter = vcs_inst.srv.state.change_counter,
.counter = vcs->srv.state.change_counter,
};
int err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
@ -590,11 +647,16 @@ int bt_vcs_unmute_vol_up(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_vol_set(struct bt_conn *conn, uint8_t volume)
int bt_vcs_vol_set(struct bt_vcs *vcs, uint8_t volume)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_set_volume(conn, volume);
return bt_vcs_client_set_volume(vcs, volume);
} else {
return -EOPNOTSUPP;
}
@ -604,7 +666,7 @@ int bt_vcs_vol_set(struct bt_conn *conn, uint8_t volume)
const struct vcs_control_vol cp = {
.cp = {
.opcode = BT_VCS_OPCODE_SET_ABS_VOL,
.counter = vcs_inst.srv.state.change_counter
.counter = vcs->srv.state.change_counter
},
.volume = volume
};
@ -616,11 +678,16 @@ int bt_vcs_vol_set(struct bt_conn *conn, uint8_t volume)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_unmute(struct bt_conn *conn)
int bt_vcs_unmute(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_unmute(conn);
return bt_vcs_client_unmute(vcs);
} else {
return -EOPNOTSUPP;
}
@ -629,7 +696,7 @@ int bt_vcs_unmute(struct bt_conn *conn)
#if defined(CONFIG_BT_VCS)
const struct vcs_control cp = {
.opcode = BT_VCS_OPCODE_UNMUTE,
.counter = vcs_inst.srv.state.change_counter,
.counter = vcs->srv.state.change_counter,
};
int err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
@ -639,11 +706,16 @@ int bt_vcs_unmute(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_mute(struct bt_conn *conn)
int bt_vcs_mute(struct bt_vcs *vcs)
{
if (conn != NULL) {
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (vcs->client_instance) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT)) {
return bt_vcs_client_mute(conn);
return bt_vcs_client_mute(vcs);
} else {
return -EOPNOTSUPP;
}
@ -652,7 +724,7 @@ int bt_vcs_mute(struct bt_conn *conn)
#if defined(CONFIG_BT_VCS)
const struct vcs_control cp = {
.opcode = BT_VCS_OPCODE_MUTE,
.counter = vcs_inst.srv.state.change_counter,
.counter = vcs->srv.state.change_counter,
};
int err = write_vcs_control(NULL, NULL, &cp, sizeof(cp), 0, 0);
@ -662,243 +734,328 @@ int bt_vcs_mute(struct bt_conn *conn)
#endif /* CONFIG_BT_VCS */
}
int bt_vcs_vocs_state_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vcs_vocs_state_get(struct bt_vcs *vcs, struct bt_vocs *inst)
{
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
bt_vcs_client_valid_vocs_inst(vcs, inst)) {
return bt_vocs_state_get(inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && valid_vocs_inst(vcs, inst)) {
return bt_vocs_state_get(inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_vocs_location_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vcs_vocs_location_get(struct bt_vcs *vcs, struct bt_vocs *inst)
{
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
bt_vcs_client_valid_vocs_inst(vcs, inst)) {
return bt_vocs_location_get(inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && valid_vocs_inst(vcs, inst)) {
return bt_vocs_location_get(inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_vocs_location_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vcs_vocs_location_set(struct bt_vcs *vcs, struct bt_vocs *inst,
uint8_t location)
{
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
bt_vcs_client_valid_vocs_inst(vcs, inst)) {
return bt_vocs_location_set(inst, location);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && valid_vocs_inst(vcs, inst)) {
return bt_vocs_location_set(inst, location);
}
return -EOPNOTSUPP;
}
int bt_vcs_vocs_state_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vcs_vocs_state_set(struct bt_vcs *vcs, struct bt_vocs *inst,
int16_t offset)
{
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
bt_vcs_client_valid_vocs_inst(vcs, inst)) {
return bt_vocs_state_set(inst, offset);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && valid_vocs_inst(vcs, inst)) {
return bt_vocs_state_set(inst, offset);
}
return -EOPNOTSUPP;
}
int bt_vcs_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vcs_vocs_description_get(struct bt_vcs *vcs, struct bt_vocs *inst)
{
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
bt_vcs_client_valid_vocs_inst(vcs, inst)) {
return bt_vocs_description_get(inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && valid_vocs_inst(vcs, inst)) {
return bt_vocs_description_get(inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vcs_vocs_description_set(struct bt_vcs *vcs, struct bt_vocs *inst,
const char *description)
{
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
bt_vcs_client_valid_vocs_inst(vcs, inst)) {
return bt_vocs_description_set(inst, description);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && valid_vocs_inst(vcs, inst)) {
return bt_vocs_description_set(inst, description);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_state_get(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_state_get(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_state_get(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_state_get(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_state_get(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_gain_setting_get(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_gain_setting_get(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_gain_setting_get(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_gain_setting_get(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_gain_setting_get(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_type_get(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_type_get(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_type_get(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_type_get(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_type_get(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_status_get(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_status_get(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_status_get(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_status_get(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_status_get(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_unmute(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_unmute(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_unmute(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_unmute(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_unmute(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_mute(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_mute(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_mute(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_mute(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_mute(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_manual_gain_set(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_manual_gain_set(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_manual_gain_set(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_manual_gain_set(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_manual_gain_set(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_automatic_gain_set(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_automatic_gain_set(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_automatic_gain_set(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_automatic_gain_set(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_automatic_gain_set(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_gain_set(struct bt_conn *conn, struct bt_aics *inst,
int bt_vcs_aics_gain_set(struct bt_vcs *vcs, struct bt_aics *inst,
int8_t gain)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_gain_set(conn, inst, gain);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_gain_set(vcs->cli.conn, inst, gain);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_gain_set(NULL, inst, gain);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_description_get(struct bt_conn *conn, struct bt_aics *inst)
int bt_vcs_aics_description_get(struct bt_vcs *vcs, struct bt_aics *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_description_get(conn, inst);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_description_get(vcs->cli.conn, inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_description_get(NULL, inst);
}
return -EOPNOTSUPP;
}
int bt_vcs_aics_description_set(struct bt_conn *conn, struct bt_aics *inst,
int bt_vcs_aics_description_set(struct bt_vcs *vcs, struct bt_aics *inst,
const char *description)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
conn && bt_vcs_client_valid_aics_inst(conn, inst)) {
return bt_aics_description_set(conn, inst, description);
CHECKIF(vcs == NULL) {
BT_DBG("NULL vcs instance");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && !conn && valid_aics_inst(inst)) {
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_AICS) &&
bt_vcs_client_valid_aics_inst(vcs, inst)) {
return bt_aics_description_set(vcs->cli.conn, inst, description);
}
if (IS_ENABLED(CONFIG_BT_VCS_AICS) && valid_aics_inst(vcs, inst)) {
return bt_aics_description_set(NULL, inst, description);
}

View file

@ -30,7 +30,7 @@
static struct bt_vcs_cb *vcs_client_cb;
static struct bt_vcs vcs_insts[CONFIG_BT_MAX_CONN];
static int vcs_client_common_vcs_cp(struct bt_conn *conn, uint8_t opcode);
static int vcs_client_common_vcs_cp(struct bt_vcs *vcs, uint8_t opcode);
static struct bt_vcs *lookup_vcs_by_vocs(const struct bt_vocs *vocs)
{
@ -47,22 +47,26 @@ static struct bt_vcs *lookup_vcs_by_vocs(const struct bt_vocs *vocs)
return NULL;
}
bool bt_vcs_client_valid_vocs_inst(struct bt_conn *conn, struct bt_vocs *vocs)
bool bt_vcs_client_valid_vocs_inst(struct bt_vcs *vcs, struct bt_vocs *vocs)
{
uint8_t conn_index;
if (conn == NULL) {
if (vcs == NULL) {
return false;
}
conn_index = bt_conn_index(conn);
if (!vcs->client_instance) {
return false;
}
if (vcs->cli.conn == NULL) {
return false;
}
if (vocs == NULL) {
return false;
}
for (int i = 0; i < ARRAY_SIZE(vcs_insts[conn_index].cli.vocs); i++) {
if (vcs_insts[conn_index].cli.vocs[i] == vocs) {
for (int i = 0; i < ARRAY_SIZE(vcs->cli.vocs); i++) {
if (vcs->cli.vocs[i] == vocs) {
return true;
}
}
@ -70,22 +74,26 @@ bool bt_vcs_client_valid_vocs_inst(struct bt_conn *conn, struct bt_vocs *vocs)
return false;
}
bool bt_vcs_client_valid_aics_inst(struct bt_conn *conn, struct bt_aics *aics)
bool bt_vcs_client_valid_aics_inst(struct bt_vcs *vcs, struct bt_aics *aics)
{
uint8_t conn_index;
if (conn == NULL) {
if (vcs == NULL) {
return false;
}
conn_index = bt_conn_index(conn);
if (!vcs->client_instance) {
return false;
}
if (vcs->cli.conn == NULL) {
return false;
}
if (aics == NULL) {
return false;
}
for (int i = 0; i < ARRAY_SIZE(vcs_insts[conn_index].cli.aics); i++) {
if (vcs_insts[conn_index].cli.aics[i] == aics) {
for (int i = 0; i < ARRAY_SIZE(vcs->cli.aics); i++) {
if (vcs->cli.aics[i] == aics) {
return true;
}
}
@ -111,7 +119,7 @@ static uint8_t vcs_client_notify_handler(struct bt_conn *conn,
vcs_inst->cli.state.volume, vcs_inst->cli.state.mute,
vcs_inst->cli.state.change_counter);
if (vcs_client_cb && vcs_client_cb->state) {
vcs_client_cb->state(conn, 0, vcs_inst->cli.state.volume,
vcs_client_cb->state(vcs_inst, 0, vcs_inst->cli.state.volume,
vcs_inst->cli.state.mute);
}
} else if (handle == vcs_inst->cli.flag_handle &&
@ -119,7 +127,7 @@ static uint8_t vcs_client_notify_handler(struct bt_conn *conn,
memcpy(&vcs_inst->cli.flags, data, length);
BT_DBG("Flags %u", vcs_inst->cli.flags);
if (vcs_client_cb && vcs_client_cb->flags) {
vcs_client_cb->flags(conn, 0, vcs_inst->cli.flags);
vcs_client_cb->flags(vcs_inst, 0, vcs_inst->cli.flags);
}
}
@ -153,9 +161,9 @@ static uint8_t vcs_client_read_vol_state_cb(struct bt_conn *conn, uint8_t err,
if (vcs_client_cb && vcs_client_cb->state) {
if (cb_err) {
vcs_client_cb->state(conn, cb_err, 0, 0);
vcs_client_cb->state(vcs_inst, cb_err, 0, 0);
} else {
vcs_client_cb->state(conn, cb_err,
vcs_client_cb->state(vcs_inst, cb_err,
vcs_inst->cli.state.volume,
vcs_inst->cli.state.mute);
}
@ -188,16 +196,16 @@ static uint8_t vcs_client_read_flag_cb(struct bt_conn *conn, uint8_t err,
if (vcs_client_cb && vcs_client_cb->flags) {
if (cb_err) {
vcs_client_cb->flags(conn, cb_err, 0);
vcs_client_cb->flags(vcs_inst, cb_err, 0);
} else {
vcs_client_cb->flags(conn, cb_err, vcs_inst->cli.flags);
vcs_client_cb->flags(vcs_inst, cb_err, vcs_inst->cli.flags);
}
}
return BT_GATT_ITER_STOP;
}
static void vcs_cp_notify_app(struct bt_conn *conn, uint8_t opcode, int err)
static void vcs_cp_notify_app(struct bt_vcs *vcs, uint8_t opcode, int err)
{
if (vcs_client_cb == NULL) {
return;
@ -206,37 +214,37 @@ static void vcs_cp_notify_app(struct bt_conn *conn, uint8_t opcode, int err)
switch (opcode) {
case BT_VCS_OPCODE_REL_VOL_DOWN:
if (vcs_client_cb->vol_down) {
vcs_client_cb->vol_down(conn, err);
vcs_client_cb->vol_down(vcs, err);
}
break;
case BT_VCS_OPCODE_REL_VOL_UP:
if (vcs_client_cb->vol_up) {
vcs_client_cb->vol_up(conn, err);
vcs_client_cb->vol_up(vcs, err);
}
break;
case BT_VCS_OPCODE_UNMUTE_REL_VOL_DOWN:
if (vcs_client_cb->vol_down_unmute) {
vcs_client_cb->vol_down_unmute(conn, err);
vcs_client_cb->vol_down_unmute(vcs, err);
}
break;
case BT_VCS_OPCODE_UNMUTE_REL_VOL_UP:
if (vcs_client_cb->vol_up_unmute) {
vcs_client_cb->vol_up_unmute(conn, err);
vcs_client_cb->vol_up_unmute(vcs, err);
}
break;
case BT_VCS_OPCODE_SET_ABS_VOL:
if (vcs_client_cb->vol_set) {
vcs_client_cb->vol_set(conn, err);
vcs_client_cb->vol_set(vcs, err);
}
break;
case BT_VCS_OPCODE_UNMUTE:
if (vcs_client_cb->unmute) {
vcs_client_cb->unmute(conn, err);
vcs_client_cb->unmute(vcs, err);
}
break;
case BT_VCS_OPCODE_MUTE:
if (vcs_client_cb->mute) {
vcs_client_cb->mute(conn, err);
vcs_client_cb->mute(vcs, err);
}
break;
default:
@ -272,10 +280,10 @@ static uint8_t internal_read_vol_state_cb(struct bt_conn *conn, uint8_t err,
/* clear busy flag to reuse function */
vcs_inst->cli.busy = false;
if (opcode == BT_VCS_OPCODE_SET_ABS_VOL) {
write_err = bt_vcs_client_set_volume(conn,
write_err = bt_vcs_client_set_volume(vcs_inst,
vcs_inst->cli.cp_val.volume);
} else {
write_err = vcs_client_common_vcs_cp(conn,
write_err = vcs_client_common_vcs_cp(vcs_inst,
opcode);
}
if (write_err) {
@ -290,7 +298,7 @@ static uint8_t internal_read_vol_state_cb(struct bt_conn *conn, uint8_t err,
if (cb_err) {
vcs_inst->cli.busy = false;
vcs_cp_notify_app(conn, opcode, cb_err);
vcs_cp_notify_app(vcs_inst, opcode, cb_err);
}
return BT_GATT_ITER_STOP;
@ -334,7 +342,7 @@ static void vcs_client_write_vcs_cp_cb(struct bt_conn *conn, uint8_t err,
vcs_inst->cli.busy = false;
vcs_inst->cli.cp_retried = false;
vcs_cp_notify_app(conn, opcode, err);
vcs_cp_notify_app(vcs_inst, opcode, err);
}
#if (CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0 || CONFIG_BT_VCS_CLIENT_MAX_VOCS_INST > 0)
@ -356,7 +364,7 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
/*
* TODO: Validate that all mandatory handles were found
*/
vcs_client_cb->discover(conn, 0,
vcs_client_cb->discover(vcs_inst, 0,
vcs_inst->cli.vocs_inst_cnt,
vcs_inst->cli.aics_inst_cnt);
}
@ -392,8 +400,8 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
if (err != 0) {
BT_DBG("AICS Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, err, 0,
0);
vcs_client_cb->discover(vcs_inst, err,
0, 0);
}
}
@ -420,8 +428,8 @@ static uint8_t vcs_discover_include_func(struct bt_conn *conn,
if (err != 0) {
BT_DBG("VOCS Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, err, 0,
0);
vcs_client_cb->discover(vcs_inst, err,
0, 0);
}
}
@ -462,12 +470,12 @@ static uint8_t vcs_discover_func(struct bt_conn *conn,
if (err != 0) {
BT_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, err, 0, 0);
vcs_client_cb->discover(vcs_inst, err, 0, 0);
}
}
#else
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, err, 0, 0);
vcs_client_cb->discover(vcs_inst, err, 0, 0);
}
#endif /* (CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0 || CONFIG_BT_VCS_CLIENT_MAX_VOCS_INST > 0) */
@ -532,7 +540,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
if (attr == NULL) {
BT_DBG("Could not find a VCS instance on the server");
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, -ENODATA, 0, 0);
vcs_client_cb->discover(vcs_inst, -ENODATA, 0, 0);
}
return BT_GATT_ITER_STOP;
}
@ -559,7 +567,7 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
if (err != 0) {
BT_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, err, 0, 0);
vcs_client_cb->discover(vcs_inst, err, 0, 0);
}
}
@ -569,37 +577,34 @@ static uint8_t primary_discover_func(struct bt_conn *conn,
return BT_GATT_ITER_CONTINUE;
}
static int vcs_client_common_vcs_cp(struct bt_conn *conn, uint8_t opcode)
static int vcs_client_common_vcs_cp(struct bt_vcs *vcs, uint8_t opcode)
{
int err;
struct bt_vcs *vcs_inst;
CHECKIF(conn == NULL) {
CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (vcs_inst->cli.control_handle == 0) {
if (vcs->cli.control_handle == 0) {
BT_DBG("Handle not set");
return -EINVAL;
} else if (vcs_inst->cli.busy) {
} else if (vcs->cli.busy) {
return -EBUSY;
}
vcs_inst->cli.busy = true;
vcs_inst->cli.cp_val.cp.opcode = opcode;
vcs_inst->cli.cp_val.cp.counter = vcs_inst->cli.state.change_counter;
vcs_inst->cli.write_params.offset = 0;
vcs_inst->cli.write_params.data = &vcs_inst->cli.cp_val.cp;
vcs_inst->cli.write_params.length = sizeof(vcs_inst->cli.cp_val.cp);
vcs_inst->cli.write_params.handle = vcs_inst->cli.control_handle;
vcs_inst->cli.write_params.func = vcs_client_write_vcs_cp_cb;
vcs->cli.busy = true;
vcs->cli.cp_val.cp.opcode = opcode;
vcs->cli.cp_val.cp.counter = vcs->cli.state.change_counter;
vcs->cli.write_params.offset = 0;
vcs->cli.write_params.data = &vcs->cli.cp_val.cp;
vcs->cli.write_params.length = sizeof(vcs->cli.cp_val.cp);
vcs->cli.write_params.handle = vcs->cli.control_handle;
vcs->cli.write_params.func = vcs_client_write_vcs_cp_cb;
err = bt_gatt_write(conn, &vcs_inst->cli.write_params);
err = bt_gatt_write(vcs->cli.conn, &vcs->cli.write_params);
if (err == 0) {
vcs_inst->cli.busy = true;
vcs->cli.busy = true;
}
return err;
}
@ -617,7 +622,7 @@ static void aics_discover_cb(struct bt_conn *conn, struct bt_aics *inst,
if (err != 0) {
BT_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(conn, err, 0, 0);
vcs_client_cb->discover(vcs_inst, err, 0, 0);
}
}
}
@ -630,7 +635,7 @@ static void vocs_discover_cb(struct bt_vocs *inst, int err)
BT_ERR("Could not lookup vcs_inst from vocs");
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst->cli.conn,
vcs_client_cb->discover(vcs_inst,
BT_GATT_ERR(BT_ATT_ERR_UNLIKELY),
0, 0);
}
@ -647,7 +652,7 @@ static void vocs_discover_cb(struct bt_vocs *inst, int err)
if (err != 0) {
BT_DBG("Discover failed (err %d)", err);
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst->cli.conn, err, 0, 0);
vcs_client_cb->discover(vcs_inst, err, 0, 0);
}
}
}
@ -744,6 +749,7 @@ int bt_vcs_discover(struct bt_conn *conn, struct bt_vcs **vcs)
memcpy(&vcs_inst->cli.uuid, BT_UUID_VCS, sizeof(vcs_inst->cli.uuid));
vcs_inst->client_instance = true;
vcs_inst->cli.conn = conn;
vcs_inst->cli.discover_params.func = primary_discover_func;
vcs_inst->cli.discover_params.uuid = &vcs_inst->cli.uuid.uuid;
@ -813,158 +819,141 @@ int bt_vcs_client_cb_register(struct bt_vcs_cb *cb)
return 0;
}
int bt_vcs_client_included_get(struct bt_conn *conn,
int bt_vcs_client_included_get(struct bt_vcs *vcs,
struct bt_vcs_included *included)
{
uint8_t conn_index;
struct bt_vcs *vcs_inst;
CHECKIF(!included || !conn) {
CHECKIF(!included || vcs == NULL) {
return -EINVAL;
}
vcs_inst = &vcs_insts[bt_conn_index(conn)];
included->vocs_cnt = vcs->cli.vocs_inst_cnt;
included->vocs = vcs->cli.vocs;
conn_index = bt_conn_index(conn);
included->vocs_cnt = vcs_inst->cli.vocs_inst_cnt;
included->vocs = vcs_insts[conn_index].cli.vocs;
included->aics_cnt = vcs_inst->cli.aics_inst_cnt;
included->aics = vcs_insts[conn_index].cli.aics;
included->aics_cnt = vcs->cli.aics_inst_cnt;
included->aics = vcs->cli.aics;
return 0;
}
int bt_vcs_client_read_vol_state(struct bt_conn *conn)
int bt_vcs_client_read_vol_state(struct bt_vcs *vcs)
{
int err;
struct bt_vcs *vcs_inst;
CHECKIF(conn == NULL) {
CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (vcs_inst->cli.state_handle == 0) {
if (vcs->cli.state_handle == 0) {
BT_DBG("Handle not set");
return -EINVAL;
} else if (vcs_inst->cli.busy) {
} else if (vcs->cli.busy) {
return -EBUSY;
}
vcs_inst->cli.read_params.func = vcs_client_read_vol_state_cb;
vcs_inst->cli.read_params.handle_count = 1;
vcs_inst->cli.read_params.single.handle = vcs_inst->cli.state_handle;
vcs_inst->cli.read_params.single.offset = 0U;
vcs->cli.read_params.func = vcs_client_read_vol_state_cb;
vcs->cli.read_params.handle_count = 1;
vcs->cli.read_params.single.handle = vcs->cli.state_handle;
vcs->cli.read_params.single.offset = 0U;
err = bt_gatt_read(conn, &vcs_inst->cli.read_params);
err = bt_gatt_read(vcs->cli.conn, &vcs->cli.read_params);
if (err == 0) {
vcs_inst->cli.busy = true;
vcs->cli.busy = true;
}
return err;
}
int bt_vcs_client_read_flags(struct bt_conn *conn)
int bt_vcs_client_read_flags(struct bt_vcs *vcs)
{
int err;
struct bt_vcs *vcs_inst;
CHECKIF(conn == NULL) {
CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (vcs_inst->cli.flag_handle == 0) {
if (vcs->cli.flag_handle == 0) {
BT_DBG("Handle not set");
return -EINVAL;
} else if (vcs_inst->cli.busy) {
} else if (vcs->cli.busy) {
return -EBUSY;
}
vcs_inst->cli.read_params.func = vcs_client_read_flag_cb;
vcs_inst->cli.read_params.handle_count = 1;
vcs_inst->cli.read_params.single.handle = vcs_inst->cli.flag_handle;
vcs_inst->cli.read_params.single.offset = 0U;
vcs->cli.read_params.func = vcs_client_read_flag_cb;
vcs->cli.read_params.handle_count = 1;
vcs->cli.read_params.single.handle = vcs->cli.flag_handle;
vcs->cli.read_params.single.offset = 0U;
err = bt_gatt_read(conn, &vcs_inst->cli.read_params);
err = bt_gatt_read(vcs->cli.conn, &vcs->cli.read_params);
if (err == 0) {
vcs_inst->cli.busy = true;
vcs->cli.busy = true;
}
return err;
}
int bt_vcs_client_vol_down(struct bt_conn *conn)
int bt_vcs_client_vol_down(struct bt_vcs *vcs)
{
return vcs_client_common_vcs_cp(conn, BT_VCS_OPCODE_REL_VOL_DOWN);
return vcs_client_common_vcs_cp(vcs, BT_VCS_OPCODE_REL_VOL_DOWN);
}
int bt_vcs_client_vol_up(struct bt_conn *conn)
int bt_vcs_client_vol_up(struct bt_vcs *vcs)
{
return vcs_client_common_vcs_cp(conn, BT_VCS_OPCODE_REL_VOL_UP);
return vcs_client_common_vcs_cp(vcs, BT_VCS_OPCODE_REL_VOL_UP);
}
int bt_vcs_client_unmute_vol_down(struct bt_conn *conn)
int bt_vcs_client_unmute_vol_down(struct bt_vcs *vcs)
{
return vcs_client_common_vcs_cp(conn,
BT_VCS_OPCODE_UNMUTE_REL_VOL_DOWN);
return vcs_client_common_vcs_cp(vcs, BT_VCS_OPCODE_UNMUTE_REL_VOL_DOWN);
}
int bt_vcs_client_unmute_vol_up(struct bt_conn *conn)
int bt_vcs_client_unmute_vol_up(struct bt_vcs *vcs)
{
return vcs_client_common_vcs_cp(conn, BT_VCS_OPCODE_UNMUTE_REL_VOL_UP);
return vcs_client_common_vcs_cp(vcs, BT_VCS_OPCODE_UNMUTE_REL_VOL_UP);
}
int bt_vcs_client_set_volume(struct bt_conn *conn, uint8_t volume)
int bt_vcs_client_set_volume(struct bt_vcs *vcs, uint8_t volume)
{
int err;
struct bt_vcs *vcs_inst;
CHECKIF(conn == NULL) {
CHECKIF(vcs->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
vcs_inst = &vcs_insts[bt_conn_index(conn)];
if (vcs_inst->cli.control_handle == 0) {
if (vcs->cli.control_handle == 0) {
BT_DBG("Handle not set");
return -EINVAL;
} else if (vcs_inst->cli.busy) {
} else if (vcs->cli.busy) {
return -EBUSY;
}
vcs_inst->cli.cp_val.cp.opcode = BT_VCS_OPCODE_SET_ABS_VOL;
vcs_inst->cli.cp_val.cp.counter = vcs_inst->cli.state.change_counter;
vcs_inst->cli.cp_val.volume = volume;
vcs->cli.cp_val.cp.opcode = BT_VCS_OPCODE_SET_ABS_VOL;
vcs->cli.cp_val.cp.counter = vcs->cli.state.change_counter;
vcs->cli.cp_val.volume = volume;
vcs_inst->cli.busy = true;
vcs_inst->cli.write_params.offset = 0;
vcs_inst->cli.write_params.data = &vcs_inst->cli.cp_val;
vcs_inst->cli.write_params.length = sizeof(vcs_inst->cli.cp_val);
vcs_inst->cli.write_params.handle = vcs_inst->cli.control_handle;
vcs_inst->cli.write_params.func = vcs_client_write_vcs_cp_cb;
vcs->cli.busy = true;
vcs->cli.write_params.offset = 0;
vcs->cli.write_params.data = &vcs->cli.cp_val;
vcs->cli.write_params.length = sizeof(vcs->cli.cp_val);
vcs->cli.write_params.handle = vcs->cli.control_handle;
vcs->cli.write_params.func = vcs_client_write_vcs_cp_cb;
err = bt_gatt_write(conn, &vcs_inst->cli.write_params);
err = bt_gatt_write(vcs->cli.conn, &vcs->cli.write_params);
if (err == 0) {
vcs_inst->cli.busy = true;
vcs->cli.busy = true;
}
return err;
}
int bt_vcs_client_unmute(struct bt_conn *conn)
int bt_vcs_client_unmute(struct bt_vcs *vcs)
{
return vcs_client_common_vcs_cp(conn, BT_VCS_OPCODE_UNMUTE);
return vcs_client_common_vcs_cp(vcs, BT_VCS_OPCODE_UNMUTE);
}
int bt_vcs_client_mute(struct bt_conn *conn)
int bt_vcs_client_mute(struct bt_vcs *vcs)
{
return vcs_client_common_vcs_cp(conn, BT_VCS_OPCODE_MUTE);
return vcs_client_common_vcs_cp(vcs, BT_VCS_OPCODE_MUTE);
}

View file

@ -55,12 +55,12 @@ struct bt_vcs_client {
struct bt_gatt_read_params read_params;
struct bt_gatt_discover_params discover_params;
struct bt_uuid_16 uuid;
struct bt_conn *conn;
uint8_t vocs_inst_cnt;
struct bt_vocs *vocs[CONFIG_BT_VCS_CLIENT_MAX_VOCS_INST];
uint8_t aics_inst_cnt;
struct bt_aics *aics[CONFIG_BT_VCS_CLIENT_MAX_AICS_INST];
struct bt_conn *conn;
};
struct bt_vcs_server {
@ -76,25 +76,25 @@ struct bt_vcs_server {
/* Struct used as a common type for the api */
struct bt_vcs {
bool client_instance;
union {
struct bt_vcs_server srv;
struct bt_vcs_client cli;
};
};
int bt_vcs_client_included_get(struct bt_conn *conn,
int bt_vcs_client_included_get(struct bt_vcs *vcs,
struct bt_vcs_included *included);
int bt_vcs_client_read_vol_state(struct bt_conn *conn);
int bt_vcs_client_read_flags(struct bt_conn *conn);
int bt_vcs_client_vol_down(struct bt_conn *conn);
int bt_vcs_client_vol_up(struct bt_conn *conn);
int bt_vcs_client_unmute_vol_down(struct bt_conn *conn);
int bt_vcs_client_unmute_vol_up(struct bt_conn *conn);
int bt_vcs_client_set_volume(struct bt_conn *conn, uint8_t volume);
int bt_vcs_client_unmute(struct bt_conn *conn);
int bt_vcs_client_mute(struct bt_conn *conn);
int bt_vcs_client_read_vol_state(struct bt_vcs *vcs);
int bt_vcs_client_read_flags(struct bt_vcs *vcs);
int bt_vcs_client_vol_down(struct bt_vcs *vcs);
int bt_vcs_client_vol_up(struct bt_vcs *vcs);
int bt_vcs_client_unmute_vol_down(struct bt_vcs *vcs);
int bt_vcs_client_unmute_vol_up(struct bt_vcs *vcs);
int bt_vcs_client_set_volume(struct bt_vcs *vcs, uint8_t volume);
int bt_vcs_client_unmute(struct bt_vcs *vcs);
int bt_vcs_client_mute(struct bt_vcs *vcs);
bool bt_vcs_client_valid_vocs_inst(struct bt_conn *conn, struct bt_vocs *vocs);
bool bt_vcs_client_valid_aics_inst(struct bt_conn *conn, struct bt_aics *aics);
bool bt_vcs_client_valid_vocs_inst(struct bt_vcs *vcs, struct bt_vocs *vocs);
bool bt_vcs_client_valid_aics_inst(struct bt_vcs *vcs, struct bt_aics *aics);
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VCS_INTERNAL_*/

View file

@ -19,7 +19,7 @@
static struct bt_vcs *vcs;
static struct bt_vcs_included vcs_included;
static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
static void vcs_state_cb(struct bt_vcs *vcs, int err, uint8_t volume,
uint8_t mute)
{
if (err) {
@ -29,7 +29,7 @@ static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
}
}
static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
static void vcs_flags_cb(struct bt_vcs *vcs, int err, uint8_t flags)
{
if (err) {
shell_error(ctx_shell, "VCS flags get failed (%d)", err);
@ -203,7 +203,7 @@ static int cmd_vcs_init(const struct shell *sh, size_t argc, char **argv)
return result;
}
result = bt_vcs_included_get(NULL, &vcs_included);
result = bt_vcs_included_get(vcs, &vcs_included);
if (result != 0) {
shell_error(sh, "Failed to get included services: %d", result);
return result;
@ -235,7 +235,7 @@ static int cmd_vcs_volume_step(const struct shell *sh, size_t argc,
static int cmd_vcs_state_get(const struct shell *sh, size_t argc,
char **argv)
{
int result = bt_vcs_vol_get(NULL);
int result = bt_vcs_vol_get(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -247,7 +247,7 @@ static int cmd_vcs_state_get(const struct shell *sh, size_t argc,
static int cmd_vcs_flags_get(const struct shell *sh, size_t argc,
char **argv)
{
int result = bt_vcs_flags_get(NULL);
int result = bt_vcs_flags_get(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -259,7 +259,7 @@ static int cmd_vcs_flags_get(const struct shell *sh, size_t argc,
static int cmd_vcs_volume_down(const struct shell *sh, size_t argc,
char **argv)
{
int result = bt_vcs_vol_down(NULL);
int result = bt_vcs_vol_down(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -272,7 +272,7 @@ static int cmd_vcs_volume_up(const struct shell *sh, size_t argc,
char **argv)
{
int result = bt_vcs_vol_up(NULL);
int result = bt_vcs_vol_up(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -284,7 +284,7 @@ static int cmd_vcs_volume_up(const struct shell *sh, size_t argc,
static int cmd_vcs_unmute_volume_down(const struct shell *sh, size_t argc,
char **argv)
{
int result = bt_vcs_unmute_vol_down(NULL);
int result = bt_vcs_unmute_vol_down(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -296,7 +296,7 @@ static int cmd_vcs_unmute_volume_down(const struct shell *sh, size_t argc,
static int cmd_vcs_unmute_volume_up(const struct shell *sh, size_t argc,
char **argv)
{
int result = bt_vcs_unmute_vol_up(NULL);
int result = bt_vcs_unmute_vol_up(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -317,7 +317,7 @@ static int cmd_vcs_volume_set(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_vol_set(NULL, volume);
result = bt_vcs_vol_set(vcs, volume);
if (result) {
shell_print(sh, "Fail: %d", result);
}
@ -327,7 +327,7 @@ static int cmd_vcs_volume_set(const struct shell *sh, size_t argc,
static int cmd_vcs_unmute(const struct shell *sh, size_t argc, char **argv)
{
int result = bt_vcs_unmute(NULL);
int result = bt_vcs_unmute(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);
@ -338,7 +338,7 @@ static int cmd_vcs_unmute(const struct shell *sh, size_t argc, char **argv)
static int cmd_vcs_mute(const struct shell *sh, size_t argc, char **argv)
{
int result = bt_vcs_mute(NULL);
int result = bt_vcs_mute(vcs);
if (result) {
shell_print(sh, "Fail: %d", result);

View file

@ -18,7 +18,7 @@
static struct bt_vcs *vcs;
static struct bt_vcs_included vcs_included;
static void vcs_discover_cb(struct bt_conn *conn, int err, uint8_t vocs_count,
static void vcs_discover_cb(struct bt_vcs *vcs, int err, uint8_t vocs_count,
uint8_t aics_count)
{
if (err != 0) {
@ -27,13 +27,13 @@ static void vcs_discover_cb(struct bt_conn *conn, int err, uint8_t vocs_count,
shell_print(ctx_shell, "VCS discover done with %u AICS",
aics_count);
if (bt_vcs_included_get(conn, &vcs_included)) {
if (bt_vcs_included_get(vcs, &vcs_included)) {
shell_error(ctx_shell, "Could not get VCS context");
}
}
}
static void vcs_vol_down_cb(struct bt_conn *conn, int err)
static void vcs_vol_down_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS vol_down failed (%d)", err);
@ -42,7 +42,7 @@ static void vcs_vol_down_cb(struct bt_conn *conn, int err)
}
}
static void vcs_vol_up_cb(struct bt_conn *conn, int err)
static void vcs_vol_up_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS vol_up failed (%d)", err);
@ -51,7 +51,7 @@ static void vcs_vol_up_cb(struct bt_conn *conn, int err)
}
}
static void vcs_mute_cb(struct bt_conn *conn, int err)
static void vcs_mute_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS mute failed (%d)", err);
@ -60,7 +60,7 @@ static void vcs_mute_cb(struct bt_conn *conn, int err)
}
}
static void vcs_unmute_cb(struct bt_conn *conn, int err)
static void vcs_unmute_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS unmute failed (%d)", err);
@ -69,7 +69,7 @@ static void vcs_unmute_cb(struct bt_conn *conn, int err)
}
}
static void vcs_vol_down_unmute_cb(struct bt_conn *conn, int err)
static void vcs_vol_down_unmute_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS vol_down_unmute failed (%d)", err);
@ -78,7 +78,7 @@ static void vcs_vol_down_unmute_cb(struct bt_conn *conn, int err)
}
}
static void vcs_vol_up_unmute_cb(struct bt_conn *conn, int err)
static void vcs_vol_up_unmute_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS vol_up_unmute failed (%d)", err);
@ -87,7 +87,7 @@ static void vcs_vol_up_unmute_cb(struct bt_conn *conn, int err)
}
}
static void vcs_vol_set_cb(struct bt_conn *conn, int err)
static void vcs_vol_set_cb(struct bt_vcs *vcs, int err)
{
if (err != 0) {
shell_error(ctx_shell, "VCS vol_set failed (%d)", err);
@ -96,7 +96,7 @@ static void vcs_vol_set_cb(struct bt_conn *conn, int err)
}
}
static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
static void vcs_state_cb(struct bt_vcs *vcs, int err, uint8_t volume,
uint8_t mute)
{
if (err != 0) {
@ -106,7 +106,7 @@ static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
}
}
static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
static void vcs_flags_cb(struct bt_vcs *vcs, int err, uint8_t flags)
{
if (err != 0) {
shell_error(ctx_shell, "VCS flags get failed (%d)", err);
@ -368,7 +368,7 @@ static int cmd_vcs_client_state_get(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_vol_get(default_conn);
result = bt_vcs_vol_get(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -386,7 +386,7 @@ static int cmd_vcs_client_flags_get(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_flags_get(default_conn);
result = bt_vcs_flags_get(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -404,7 +404,7 @@ static int cmd_vcs_client_volume_down(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_vol_down(default_conn);
result = bt_vcs_vol_down(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -423,7 +423,7 @@ static int cmd_vcs_client_volume_up(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_vol_up(default_conn);
result = bt_vcs_vol_up(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -441,7 +441,7 @@ static int cmd_vcs_client_unmute_volume_down(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_unmute_vol_down(default_conn);
result = bt_vcs_unmute_vol_down(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -459,7 +459,7 @@ static int cmd_vcs_client_unmute_volume_up(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_unmute_vol_up(default_conn);
result = bt_vcs_unmute_vol_up(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -484,7 +484,7 @@ static int cmd_vcs_client_volume_set(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_vol_set(default_conn, volume);
result = bt_vcs_vol_set(vcs, volume);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -503,7 +503,7 @@ static int cmd_vcs_client_unmute(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_unmute(default_conn);
result = bt_vcs_unmute(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -520,7 +520,7 @@ static int cmd_vcs_client_mute(const struct shell *sh, size_t argc, char **argv)
return -ENOEXEC;
}
result = bt_vcs_mute(default_conn);
result = bt_vcs_mute(vcs);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -545,7 +545,7 @@ static int cmd_vcs_client_vocs_state_get(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_vocs_state_get(default_conn, vcs_included.vocs[index]);
result = bt_vcs_vocs_state_get(vcs, vcs_included.vocs[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -570,8 +570,7 @@ static int cmd_vcs_client_vocs_location_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_vocs_location_get(default_conn,
vcs_included.vocs[index]);
result = bt_vcs_vocs_location_get(vcs, vcs_included.vocs[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -604,8 +603,7 @@ static int cmd_vcs_client_vocs_location_set(const struct shell *sh,
}
result = bt_vcs_vocs_location_set(default_conn,
vcs_included.vocs[index],
result = bt_vcs_vocs_location_set(vcs, vcs_included.vocs[index],
location);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
@ -638,8 +636,7 @@ static int cmd_vcs_client_vocs_offset_set(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_vocs_state_set(default_conn,
vcs_included.vocs[index],
result = bt_vcs_vocs_state_set(vcs, vcs_included.vocs[index],
offset);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
@ -665,8 +662,7 @@ static int cmd_vcs_client_vocs_output_description_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_vocs_description_get(default_conn,
vcs_included.vocs[index]);
result = bt_vcs_vocs_description_get(vcs, vcs_included.vocs[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -692,8 +688,7 @@ static int cmd_vcs_client_vocs_output_description_set(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_vocs_description_set(default_conn,
vcs_included.vocs[index],
result = bt_vcs_vocs_description_set(vcs, vcs_included.vocs[index],
description);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
@ -719,7 +714,7 @@ static int cmd_vcs_client_aics_input_state_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_state_get(default_conn, vcs_included.aics[index]);
result = bt_vcs_aics_state_get(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -744,8 +739,7 @@ static int cmd_vcs_client_aics_gain_setting_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_gain_setting_get(default_conn,
vcs_included.aics[index]);
result = bt_vcs_aics_gain_setting_get(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -770,7 +764,7 @@ static int cmd_vcs_client_aics_input_type_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_type_get(default_conn, vcs_included.aics[index]);
result = bt_vcs_aics_type_get(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -795,7 +789,7 @@ static int cmd_vcs_client_aics_input_status_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_status_get(default_conn, vcs_included.aics[index]);
result = bt_vcs_aics_status_get(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -820,7 +814,7 @@ static int cmd_vcs_client_aics_input_unmute(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_unmute(default_conn, vcs_included.aics[index]);
result = bt_vcs_aics_unmute(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -845,7 +839,7 @@ static int cmd_vcs_client_aics_input_mute(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_mute(default_conn, vcs_included.aics[index]);
result = bt_vcs_aics_mute(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -870,8 +864,7 @@ static int cmd_vcs_client_aics_manual_input_gain_set(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_manual_gain_set(default_conn,
vcs_included.aics[index]);
result = bt_vcs_aics_manual_gain_set(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -896,8 +889,7 @@ static int cmd_vcs_client_aics_auto_input_gain_set(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_automatic_gain_set(default_conn,
vcs_included.aics[index]);
result = bt_vcs_aics_automatic_gain_set(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -929,8 +921,7 @@ static int cmd_vcs_client_aics_gain_set(const struct shell *sh, size_t argc,
return -ENOEXEC;
}
result = bt_vcs_aics_gain_set(default_conn,
vcs_included.aics[index], gain);
result = bt_vcs_aics_gain_set(vcs, vcs_included.aics[index], gain);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -955,8 +946,7 @@ static int cmd_vcs_client_aics_input_description_get(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_description_get(default_conn,
vcs_included.aics[index]);
result = bt_vcs_aics_description_get(vcs, vcs_included.aics[index]);
if (result != 0) {
shell_print(sh, "Fail: %d", result);
}
@ -982,8 +972,7 @@ static int cmd_vcs_client_aics_input_description_set(const struct shell *sh,
return -ENOEXEC;
}
result = bt_vcs_aics_description_set(default_conn,
vcs_included.aics[index],
result = bt_vcs_aics_description_set(vcs, vcs_included.aics[index],
description);
if (result != 0) {
shell_print(sh, "Fail: %d", result);

View file

@ -44,7 +44,7 @@ static char g_aics_desc[AICS_DESC_SIZE];
static volatile bool g_cb;
static struct bt_conn *g_conn;
static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
static void vcs_state_cb(struct bt_vcs *vcs, int err, uint8_t volume,
uint8_t mute)
{
if (err) {
@ -58,7 +58,7 @@ static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
g_cb = true;
}
static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
static void vcs_flags_cb(struct bt_vcs *vcs, int err, uint8_t flags)
{
if (err) {
FAIL("VCS flags cb err (%d)", err);
@ -209,7 +209,7 @@ static void aics_write_cb(struct bt_conn *conn, struct bt_aics *inst, int err)
g_write_complete = true;
}
static void vcs_discover_cb(struct bt_conn *conn, int err, uint8_t vocs_count,
static void vcs_discover_cb(struct bt_vcs *vcs, int err, uint8_t vocs_count,
uint8_t aics_count)
{
if (err) {
@ -220,7 +220,7 @@ static void vcs_discover_cb(struct bt_conn *conn, int err, uint8_t vocs_count,
g_discovery_complete = true;
}
static void vcs_write_cb(struct bt_conn *conn, int err)
static void vcs_write_cb(struct bt_vcs *vcs, int err)
{
if (err) {
FAIL("VCS write failed (%d)\n", err);
@ -313,7 +313,7 @@ static int test_aics(void)
printk("Getting AICS state\n");
g_cb = false;
err = bt_vcs_aics_state_get(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_state_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS state (err %d)\n", err);
return err;
@ -323,7 +323,7 @@ static int test_aics(void)
printk("Getting AICS gain setting\n");
g_cb = false;
err = bt_vcs_aics_gain_setting_get(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_gain_setting_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS gain setting (err %d)\n", err);
return err;
@ -334,7 +334,7 @@ static int test_aics(void)
printk("Getting AICS input type\n");
expected_input_type = BT_AICS_INPUT_TYPE_DIGITAL;
g_cb = false;
err = bt_vcs_aics_type_get(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_type_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS input type (err %d)\n", err);
return err;
@ -345,7 +345,7 @@ static int test_aics(void)
printk("Getting AICS status\n");
g_cb = false;
err = bt_vcs_aics_status_get(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_status_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS status (err %d)\n", err);
return err;
@ -355,7 +355,7 @@ static int test_aics(void)
printk("Getting AICS description\n");
g_cb = false;
err = bt_vcs_aics_description_get(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_description_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS description (err %d)\n", err);
return err;
@ -366,7 +366,7 @@ static int test_aics(void)
printk("Setting AICS mute\n");
expected_input_mute = BT_AICS_STATE_MUTED;
g_write_complete = g_cb = false;
err = bt_vcs_aics_mute(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_mute(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS mute (err %d)\n", err);
return err;
@ -378,7 +378,7 @@ static int test_aics(void)
printk("Setting AICS unmute\n");
expected_input_mute = BT_AICS_STATE_UNMUTED;
g_write_complete = g_cb = false;
err = bt_vcs_aics_unmute(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_unmute(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS unmute (err %d)\n", err);
return err;
@ -390,7 +390,7 @@ static int test_aics(void)
printk("Setting AICS auto mode\n");
expected_mode = BT_AICS_MODE_AUTO;
g_write_complete = g_cb = false;
err = bt_vcs_aics_automatic_gain_set(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_automatic_gain_set(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS auto mode (err %d)\n", err);
return err;
@ -401,7 +401,7 @@ static int test_aics(void)
printk("Setting AICS manual mode\n");
expected_mode = BT_AICS_MODE_MANUAL;
g_write_complete = g_cb = false;
err = bt_vcs_aics_manual_gain_set(g_conn, vcs_included.aics[0]);
err = bt_vcs_aics_manual_gain_set(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS manual mode (err %d)\n", err);
return err;
@ -412,7 +412,7 @@ static int test_aics(void)
printk("Setting AICS gain\n");
expected_gain = g_aics_gain_max - 1;
g_write_complete = g_cb = false;
err = bt_vcs_aics_gain_set(g_conn, vcs_included.aics[0], expected_gain);
err = bt_vcs_aics_gain_set(vcs, vcs_included.aics[0], expected_gain);
if (err) {
FAIL("Could not set AICS gain (err %d)\n", err);
return err;
@ -425,7 +425,7 @@ static int test_aics(void)
sizeof(expected_aics_desc));
expected_aics_desc[sizeof(expected_aics_desc) - 1] = '\0';
g_cb = false;
err = bt_vcs_aics_description_set(g_conn, vcs_included.aics[0],
err = bt_vcs_aics_description_set(vcs, vcs_included.aics[0],
expected_aics_desc);
if (err) {
FAIL("Could not set AICS Description (err %d)\n", err);
@ -461,7 +461,7 @@ static int test_vocs(void)
printk("Getting VOCS state\n");
g_cb = false;
err = bt_vcs_vocs_state_get(g_conn, vcs_included.vocs[0]);
err = bt_vcs_vocs_state_get(vcs, vcs_included.vocs[0]);
if (err) {
FAIL("Could not get VOCS state (err %d)\n", err);
return err;
@ -471,7 +471,7 @@ static int test_vocs(void)
printk("Getting VOCS location\n");
g_cb = false;
err = bt_vcs_vocs_location_get(g_conn, vcs_included.vocs[0]);
err = bt_vcs_vocs_location_get(vcs, vcs_included.vocs[0]);
if (err) {
FAIL("Could not get VOCS location (err %d)\n", err);
return err;
@ -481,7 +481,7 @@ static int test_vocs(void)
printk("Getting VOCS description\n");
g_cb = false;
err = bt_vcs_vocs_description_get(g_conn, vcs_included.vocs[0]);
err = bt_vcs_vocs_description_get(vcs, vcs_included.vocs[0]);
if (err) {
FAIL("Could not get VOCS description (err %d)\n", err);
return err;
@ -492,7 +492,7 @@ static int test_vocs(void)
printk("Setting VOCS location\n");
expected_location = g_vocs_location + 1;
g_cb = false;
err = bt_vcs_vocs_location_set(g_conn, vcs_included.vocs[0],
err = bt_vcs_vocs_location_set(vcs, vcs_included.vocs[0],
expected_location);
if (err) {
FAIL("Could not set VOCS location (err %d)\n", err);
@ -504,7 +504,7 @@ static int test_vocs(void)
printk("Setting VOCS state\n");
expected_offset = g_vocs_offset + 1;
g_write_complete = g_cb = false;
err = bt_vcs_vocs_state_set(g_conn, vcs_included.vocs[0], expected_offset);
err = bt_vcs_vocs_state_set(vcs, vcs_included.vocs[0], expected_offset);
if (err) {
FAIL("Could not set VOCS state (err %d)\n", err);
return err;
@ -517,7 +517,7 @@ static int test_vocs(void)
sizeof(expected_description));
expected_description[sizeof(expected_description) - 1] = '\0';
g_cb = false;
err = bt_vcs_vocs_description_set(g_conn, vcs_included.vocs[0],
err = bt_vcs_vocs_description_set(vcs, vcs_included.vocs[0],
expected_description);
if (err) {
FAIL("Could not set VOCS description (err %d)\n", err);
@ -583,7 +583,7 @@ static void test_main(void)
WAIT_FOR(g_discovery_complete);
err = bt_vcs_included_get(g_conn, &vcs_included);
err = bt_vcs_included_get(vcs, &vcs_included);
if (err) {
FAIL("Failed to get VCS included services (err %d)\n", err);
return;
@ -591,7 +591,7 @@ static void test_main(void)
printk("Getting VCS volume state\n");
g_cb = false;
err = bt_vcs_vol_get(g_conn);
err = bt_vcs_vol_get(vcs);
if (err) {
FAIL("Could not get VCS volume (err %d)\n", err);
return;
@ -601,7 +601,7 @@ static void test_main(void)
printk("Getting VCS flags\n");
g_cb = false;
err = bt_vcs_flags_get(g_conn);
err = bt_vcs_flags_get(vcs);
if (err) {
FAIL("Could not get VCS flags (err %d)\n", err);
return;
@ -611,7 +611,7 @@ static void test_main(void)
expected_volume = g_volume != 100 ? 100 : 101; /* ensure change */
g_write_complete = g_cb = false;
err = bt_vcs_vol_set(g_conn, expected_volume);
err = bt_vcs_vol_set(vcs, expected_volume);
if (err) {
FAIL("Could not set VCS volume (err %d)\n", err);
return;
@ -622,7 +622,7 @@ static void test_main(void)
printk("Downing VCS volume\n");
previous_volume = g_volume;
g_write_complete = g_cb = false;
err = bt_vcs_vol_down(g_conn);
err = bt_vcs_vol_down(vcs);
if (err) {
FAIL("Could not get down VCS volume (err %d)\n", err);
return;
@ -633,7 +633,7 @@ static void test_main(void)
printk("Upping VCS volume\n");
previous_volume = g_volume;
g_write_complete = g_cb = false;
err = bt_vcs_vol_up(g_conn);
err = bt_vcs_vol_up(vcs);
if (err) {
FAIL("Could not up VCS volume (err %d)\n", err);
return;
@ -644,7 +644,7 @@ static void test_main(void)
printk("Muting VCS\n");
expected_mute = 1;
g_write_complete = g_cb = false;
err = bt_vcs_mute(g_conn);
err = bt_vcs_mute(vcs);
if (err) {
FAIL("Could not mute VCS (err %d)\n", err);
return;
@ -656,7 +656,7 @@ static void test_main(void)
previous_volume = g_volume;
expected_mute = 0;
g_write_complete = g_cb = false;
err = bt_vcs_unmute_vol_down(g_conn);
err = bt_vcs_unmute_vol_down(vcs);
if (err) {
FAIL("Could not down and unmute VCS (err %d)\n", err);
return;
@ -668,7 +668,7 @@ static void test_main(void)
printk("Muting VCS\n");
expected_mute = 1;
g_write_complete = g_cb = false;
err = bt_vcs_mute(g_conn);
err = bt_vcs_mute(vcs);
if (err) {
FAIL("Could not mute VCS (err %d)\n", err);
return;
@ -680,7 +680,7 @@ static void test_main(void)
previous_volume = g_volume;
expected_mute = 0;
g_write_complete = g_cb = false;
err = bt_vcs_unmute_vol_up(g_conn);
err = bt_vcs_unmute_vol_up(vcs);
if (err) {
FAIL("Could not up and unmute VCS (err %d)\n", err);
return;
@ -692,7 +692,7 @@ static void test_main(void)
printk("Muting VCS\n");
expected_mute = 1;
g_write_complete = g_cb = false;
err = bt_vcs_mute(g_conn);
err = bt_vcs_mute(vcs);
if (err) {
FAIL("Could not mute VCS (err %d)\n", err);
return;
@ -703,7 +703,7 @@ static void test_main(void)
printk("Unmuting VCS\n");
expected_mute = 0;
g_write_complete = g_cb = false;
err = bt_vcs_unmute(g_conn);
err = bt_vcs_unmute(vcs);
if (err) {
FAIL("Could not unmute VCS (err %d)\n", err);
return;

View file

@ -44,7 +44,7 @@ static volatile bool g_cb;
static struct bt_conn *g_conn;
static bool g_is_connected;
static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
static void vcs_state_cb(struct bt_vcs *vcs, int err, uint8_t volume,
uint8_t mute)
{
if (err) {
@ -54,13 +54,10 @@ static void vcs_state_cb(struct bt_conn *conn, int err, uint8_t volume,
g_volume = volume;
g_mute = mute;
if (!conn) {
g_cb = true;
}
}
static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
static void vcs_flags_cb(struct bt_vcs *vcs, int err, uint8_t flags)
{
if (err) {
FAIL("VCS flags cb err (%d)", err);
@ -68,10 +65,7 @@ static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
}
g_flags = flags;
if (!conn) {
g_cb = true;
}
}
static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset)
@ -241,7 +235,7 @@ static int test_aics_standalone(void)
printk("Deactivating AICS\n");
expected_aics_active = false;
err = bt_vcs_aics_deactivate(vcs_included.aics[0]);
err = bt_vcs_aics_deactivate(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not deactivate AICS (err %d)\n", err);
return err;
@ -251,7 +245,7 @@ static int test_aics_standalone(void)
printk("Activating AICS\n");
expected_aics_active = true;
err = bt_vcs_aics_activate(vcs_included.aics[0]);
err = bt_vcs_aics_activate(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not activate AICS (err %d)\n", err);
return err;
@ -261,7 +255,7 @@ static int test_aics_standalone(void)
printk("Getting AICS state\n");
g_cb = false;
err = bt_vcs_aics_state_get(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_state_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS state (err %d)\n", err);
return err;
@ -271,7 +265,7 @@ static int test_aics_standalone(void)
printk("Getting AICS gain setting\n");
g_cb = false;
err = bt_vcs_aics_gain_setting_get(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_gain_setting_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS gain setting (err %d)\n", err);
return err;
@ -281,7 +275,7 @@ static int test_aics_standalone(void)
printk("Getting AICS input type\n");
expected_input_type = BT_AICS_INPUT_TYPE_DIGITAL;
err = bt_vcs_aics_type_get(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_type_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS input type (err %d)\n", err);
return err;
@ -292,7 +286,7 @@ static int test_aics_standalone(void)
printk("Getting AICS status\n");
g_cb = false;
err = bt_vcs_aics_status_get(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_status_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS status (err %d)\n", err);
return err;
@ -302,7 +296,7 @@ static int test_aics_standalone(void)
printk("Getting AICS description\n");
g_cb = false;
err = bt_vcs_aics_description_get(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_description_get(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not get AICS description (err %d)\n", err);
return err;
@ -312,7 +306,7 @@ static int test_aics_standalone(void)
printk("Setting AICS mute\n");
expected_input_mute = BT_AICS_STATE_MUTED;
err = bt_vcs_aics_mute(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_mute(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS mute (err %d)\n", err);
return err;
@ -322,7 +316,7 @@ static int test_aics_standalone(void)
printk("Setting AICS unmute\n");
expected_input_mute = BT_AICS_STATE_UNMUTED;
err = bt_vcs_aics_unmute(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_unmute(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS unmute (err %d)\n", err);
return err;
@ -332,7 +326,7 @@ static int test_aics_standalone(void)
printk("Setting AICS auto mode\n");
expected_mode = BT_AICS_MODE_AUTO;
err = bt_vcs_aics_automatic_gain_set(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_automatic_gain_set(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS auto mode (err %d)\n", err);
return err;
@ -342,7 +336,7 @@ static int test_aics_standalone(void)
printk("Setting AICS manual mode\n");
expected_mode = BT_AICS_MODE_MANUAL;
err = bt_vcs_aics_manual_gain_set(NULL, vcs_included.aics[0]);
err = bt_vcs_aics_manual_gain_set(vcs, vcs_included.aics[0]);
if (err) {
FAIL("Could not set AICS manual mode (err %d)\n", err);
return err;
@ -352,7 +346,7 @@ static int test_aics_standalone(void)
printk("Setting AICS gain\n");
expected_gain = g_aics_gain_max - 1;
err = bt_vcs_aics_gain_set(NULL, vcs_included.aics[0], expected_gain);
err = bt_vcs_aics_gain_set(vcs, vcs_included.aics[0], expected_gain);
if (err) {
FAIL("Could not set AICS gain (err %d)\n", err);
return err;
@ -365,7 +359,7 @@ static int test_aics_standalone(void)
sizeof(expected_aics_desc));
expected_aics_desc[sizeof(expected_aics_desc) - 1] = '\0';
g_cb = false;
err = bt_vcs_aics_description_set(NULL, vcs_included.aics[0],
err = bt_vcs_aics_description_set(vcs, vcs_included.aics[0],
expected_aics_desc);
if (err) {
FAIL("Could not set AICS Description (err %d)\n", err);
@ -387,7 +381,7 @@ static int test_vocs_standalone(void)
printk("Getting VOCS state\n");
g_cb = false;
err = bt_vcs_vocs_state_get(NULL, vcs_included.vocs[0]);
err = bt_vcs_vocs_state_get(vcs, vcs_included.vocs[0]);
if (err) {
FAIL("Could not get VOCS state (err %d)\n", err);
return err;
@ -397,7 +391,7 @@ static int test_vocs_standalone(void)
printk("Getting VOCS location\n");
g_cb = false;
err = bt_vcs_vocs_location_get(NULL, vcs_included.vocs[0]);
err = bt_vcs_vocs_location_get(vcs, vcs_included.vocs[0]);
if (err) {
FAIL("Could not get VOCS location (err %d)\n", err);
return err;
@ -407,7 +401,7 @@ static int test_vocs_standalone(void)
printk("Getting VOCS description\n");
g_cb = false;
err = bt_vcs_vocs_description_get(NULL, vcs_included.vocs[0]);
err = bt_vcs_vocs_description_get(vcs, vcs_included.vocs[0]);
if (err) {
FAIL("Could not get VOCS description (err %d)\n", err);
return err;
@ -417,7 +411,8 @@ static int test_vocs_standalone(void)
printk("Setting VOCS location\n");
expected_location = g_vocs_location + 1;
err = bt_vcs_vocs_location_set(NULL, vcs_included.vocs[0], expected_location);
err = bt_vcs_vocs_location_set(vcs, vcs_included.vocs[0],
expected_location);
if (err) {
FAIL("Could not set VOCS location (err %d)\n", err);
return err;
@ -427,7 +422,7 @@ static int test_vocs_standalone(void)
printk("Setting VOCS state\n");
expected_offset = g_vocs_offset + 1;
err = bt_vcs_vocs_state_set(NULL, vcs_included.vocs[0], expected_offset);
err = bt_vcs_vocs_state_set(vcs, vcs_included.vocs[0], expected_offset);
if (err) {
FAIL("Could not set VOCS state (err %d)\n", err);
return err;
@ -440,7 +435,7 @@ static int test_vocs_standalone(void)
sizeof(expected_description) - 1);
expected_description[sizeof(expected_description) - 1] = '\0';
g_cb = false;
err = bt_vcs_vocs_description_set(NULL, vcs_included.vocs[0],
err = bt_vcs_vocs_description_set(vcs, vcs_included.vocs[0],
expected_description);
if (err) {
FAIL("Could not set VOCS description (err %d)\n", err);
@ -504,7 +499,7 @@ static void test_standalone(void)
return;
}
err = bt_vcs_included_get(NULL, &vcs_included);
err = bt_vcs_included_get(vcs, &vcs_included);
if (err) {
FAIL("VCS included get failed (err %d)\n", err);
return;
@ -523,7 +518,7 @@ static void test_standalone(void)
printk("Getting VCS volume state\n");
g_cb = false;
err = bt_vcs_vol_get(NULL);
err = bt_vcs_vol_get(vcs);
if (err) {
FAIL("Could not get VCS volume (err %d)\n", err);
return;
@ -533,7 +528,7 @@ static void test_standalone(void)
printk("Getting VCS flags\n");
g_cb = false;
err = bt_vcs_flags_get(NULL);
err = bt_vcs_flags_get(vcs);
if (err) {
FAIL("Could not get VCS flags (err %d)\n", err);
return;
@ -543,7 +538,7 @@ static void test_standalone(void)
printk("Downing VCS volume\n");
expected_volume = g_volume - volume_step;
err = bt_vcs_vol_down(NULL);
err = bt_vcs_vol_down(vcs);
if (err) {
FAIL("Could not get down VCS volume (err %d)\n", err);
return;
@ -553,7 +548,7 @@ static void test_standalone(void)
printk("Upping VCS volume\n");
expected_volume = g_volume + volume_step;
err = bt_vcs_vol_up(NULL);
err = bt_vcs_vol_up(vcs);
if (err) {
FAIL("Could not up VCS volume (err %d)\n", err);
return;
@ -563,7 +558,7 @@ static void test_standalone(void)
printk("Muting VCS\n");
expected_mute = 1;
err = bt_vcs_mute(NULL);
err = bt_vcs_mute(vcs);
if (err) {
FAIL("Could not mute VCS (err %d)\n", err);
return;
@ -574,7 +569,7 @@ static void test_standalone(void)
printk("Downing and unmuting VCS\n");
expected_volume = g_volume - volume_step;
expected_mute = 0;
err = bt_vcs_unmute_vol_down(NULL);
err = bt_vcs_unmute_vol_down(vcs);
if (err) {
FAIL("Could not down and unmute VCS (err %d)\n", err);
return;
@ -585,7 +580,7 @@ static void test_standalone(void)
printk("Muting VCS\n");
expected_mute = 1;
err = bt_vcs_mute(NULL);
err = bt_vcs_mute(vcs);
if (err) {
FAIL("Could not mute VCS (err %d)\n", err);
return;
@ -596,7 +591,7 @@ static void test_standalone(void)
printk("Upping and unmuting VCS\n");
expected_volume = g_volume + volume_step;
expected_mute = 0;
err = bt_vcs_unmute_vol_up(NULL);
err = bt_vcs_unmute_vol_up(vcs);
if (err) {
FAIL("Could not up and unmute VCS (err %d)\n", err);
return;
@ -607,7 +602,7 @@ static void test_standalone(void)
printk("Muting VCS\n");
expected_mute = 1;
err = bt_vcs_mute(NULL);
err = bt_vcs_mute(vcs);
if (err) {
FAIL("Could not mute VCS (err %d)\n", err);
return;
@ -617,7 +612,7 @@ static void test_standalone(void)
printk("Unmuting VCS\n");
expected_mute = 0;
err = bt_vcs_unmute(NULL);
err = bt_vcs_unmute(vcs);
if (err) {
FAIL("Could not unmute VCS (err %d)\n", err);
return;
@ -626,7 +621,7 @@ static void test_standalone(void)
printk("VCS volume unmuted\n");
expected_volume = g_volume - 5;
err = bt_vcs_vol_set(NULL, expected_volume);
err = bt_vcs_vol_set(vcs, expected_volume);
if (err) {
FAIL("Could not set VCS volume (err %d)\n", err);
return;
@ -699,7 +694,7 @@ static void test_main(void)
bt_conn_cb_register(&conn_callbacks);
err = bt_vcs_included_get(NULL, &vcs_included);
err = bt_vcs_included_get(vcs, &vcs_included);
if (err) {
FAIL("VCS included get failed (err %d)\n", err);
return;