Bluetooth: Audio: VOCS remove need for bt_conn pointer

Remove the bt_conn pointer from the VOCS API, as the
instance pointer is enough to determine if it is a client
and perform client operations on the cached connection pointer.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2021-05-26 15:19:42 +02:00 committed by Carles Cufí
commit f500e0fb9c
10 changed files with 172 additions and 166 deletions

View file

@ -114,39 +114,36 @@ int bt_vocs_register(struct bt_vocs *vocs,
*
* Called when the value is read, or if the value is changed by either the server or client.
*
* @param conn Connection to peer device, or NULL if local server read.
* @param inst The instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* For notifications, this will always be 0.
* @param offset The offset value.
*/
typedef void (*bt_vocs_state_cb_t)(struct bt_conn *conn, struct bt_vocs *inst,
int err, int16_t offset);
typedef void (*bt_vocs_state_cb_t)(struct bt_vocs *inst, int err,
int16_t offset);
/**
* @brief Callback function for setting offset.
*
* @param conn Connection to peer device, or NULL if local server write.
* @param inst The instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
*/
typedef void (*bt_vocs_set_offset_cb_t)(struct bt_conn *conn, struct bt_vocs *inst, int err);
typedef void (*bt_vocs_set_offset_cb_t)(struct bt_vocs *inst, int err);
/**
* @brief Callback function for the location.
*
* Called when the value is read, or if the value is changed by either the server or client.
*
* @param conn Connection to peer device, or NULL if local server read.
* @param inst The instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* For notifications, this will always be 0.
* @param location The location value.
*/
typedef void (*bt_vocs_location_cb_t)(struct bt_conn *conn, struct bt_vocs *inst, int err,
typedef void (*bt_vocs_location_cb_t)(struct bt_vocs *inst, int err,
uint32_t location);
/**
@ -154,14 +151,13 @@ typedef void (*bt_vocs_location_cb_t)(struct bt_conn *conn, struct bt_vocs *inst
*
* Called when the value is read, or if the value is changed by either the server or client.
*
* @param conn Connection to peer device, or NULL if local server read.
* @param inst The instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* For notifications, this will always be 0.
* @param description The description as an UTF-8 encoded string.
*/
typedef void (*bt_vocs_description_cb_t)(struct bt_conn *conn, struct bt_vocs *inst, int err,
typedef void (*bt_vocs_description_cb_t)(struct bt_vocs *inst, int err,
char *description);
/**
@ -171,13 +167,12 @@ typedef void (*bt_vocs_description_cb_t)(struct bt_conn *conn, struct bt_vocs *i
* includes the Volume Control Offset Service client, and should thus not be
* set by the application.
*
* @param conn Connection to peer device, or NULL if local server read.
* @param inst The instance pointer.
* @param err Error value. 0 on success, GATT error on positive value
* or errno on negative value.
* For notifications, this will always be 0.
*/
typedef void (*bt_vocs_discover_cb_t)(struct bt_conn *conn, struct bt_vocs *inst, int err);
typedef void (*bt_vocs_discover_cb_t)(struct bt_vocs *inst, int err);
struct bt_vocs_cb {
bt_vocs_state_cb_t state;
@ -196,70 +191,63 @@ struct bt_vocs_cb {
*
* The value is returned in the bt_vocs_cb.state callback.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param inst Pointer to the Volume Offset Control Service instance.
*
* @return 0 on success, GATT error value on fail.
*/
int bt_vocs_state_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vocs_state_get(struct bt_vocs *inst);
/**
* @brief Set the Volume Offset Control Service offset state.
*
* @param conn Connection to peer device, or NULL to set local server value.
* @param inst Pointer to the Volume Offset Control Service instance.
* @param offset The offset to set (-255 to 255).
*
* @return 0 on success, GATT error value on fail.
*/
int bt_vocs_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t offset);
int bt_vocs_state_set(struct bt_vocs *inst, int16_t offset);
/**
* @brief Read the Volume Offset Control Service location.
*
* The value is returned in the bt_vocs_cb.location callback.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param inst Pointer to the Volume Offset Control Service instance.
*
* @return 0 on success, GATT error value on fail.
*/
int bt_vocs_location_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vocs_location_get(struct bt_vocs *inst);
/**
* @brief Set the Volume Offset Control Service location.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param inst Pointer to the Volume Offset Control Service instance.
* @param location The location to set.
*
* @return 0 on success, GATT error value on fail.
*/
int bt_vocs_location_set(struct bt_conn *conn, struct bt_vocs *inst, uint32_t location);
int bt_vocs_location_set(struct bt_vocs *inst, uint32_t location);
/**
* @brief Read the Volume Offset Control Service output description.
*
* The value is returned in the bt_vocs_cb.description callback.
*
* @param conn Connection to peer device, or NULL to read local server value.
* @param inst Pointer to the Volume Offset Control Service instance.
*
* @return 0 on success, GATT error value on fail.
*/
int bt_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vocs_description_get(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 inst Pointer to the Volume Offset Control Service instance.
* @param description The UTF-8 encoded string description to set.
*
* @return 0 on success, GATT error value on fail.
*/
int bt_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst,
const char *description);
int bt_vocs_description_set(struct bt_vocs *inst, const char *description);
/**
* @brief Registers the callbacks for the Volume Offset Control Service client.

View file

@ -675,11 +675,11 @@ int bt_vcs_vocs_state_get(struct bt_conn *conn, struct bt_vocs *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
return bt_vocs_state_get(conn, inst);
return bt_vocs_state_get(inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
return bt_vocs_state_get(NULL, inst);
return bt_vocs_state_get(inst);
}
return -EOPNOTSUPP;
@ -689,11 +689,11 @@ int bt_vcs_vocs_location_get(struct bt_conn *conn, struct bt_vocs *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
return bt_vocs_location_get(conn, inst);
return bt_vocs_location_get(inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
return bt_vocs_location_get(NULL, inst);
return bt_vocs_location_get(inst);
}
return -EOPNOTSUPP;
@ -704,11 +704,11 @@ int bt_vcs_vocs_location_set(struct bt_conn *conn, struct bt_vocs *inst,
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
return bt_vocs_location_set(conn, inst, location);
return bt_vocs_location_set(inst, location);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
return bt_vocs_location_set(NULL, inst, location);
return bt_vocs_location_set(inst, location);
}
return -EOPNOTSUPP;
@ -719,11 +719,11 @@ int bt_vcs_vocs_state_set(struct bt_conn *conn, struct bt_vocs *inst,
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
return bt_vocs_state_set(conn, inst, offset);
return bt_vocs_state_set(inst, offset);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
return bt_vocs_state_set(NULL, inst, offset);
return bt_vocs_state_set(inst, offset);
}
return -EOPNOTSUPP;
@ -733,11 +733,11 @@ int bt_vcs_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst)
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
return bt_vocs_description_get(conn, inst);
return bt_vocs_description_get(inst);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
return bt_vocs_description_get(NULL, inst);
return bt_vocs_description_get(inst);
}
return -EOPNOTSUPP;
@ -748,11 +748,11 @@ int bt_vcs_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst,
{
if (IS_ENABLED(CONFIG_BT_VCS_CLIENT_VOCS) &&
conn && bt_vcs_client_valid_vocs_inst(conn, inst)) {
return bt_vocs_description_set(conn, inst, description);
return bt_vocs_description_set(inst, description);
}
if (IS_ENABLED(CONFIG_BT_VCS_VOCS) && !conn && valid_vocs_inst(inst)) {
return bt_vocs_description_set(NULL, inst, description);
return bt_vocs_description_set(inst, description);
}
return -EOPNOTSUPP;

View file

@ -51,6 +51,7 @@ struct vcs_instance {
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;
};
/* Callback functions */
@ -59,6 +60,21 @@ static struct bt_vcs_cb *vcs_client_cb;
static struct vcs_instance vcs_insts[CONFIG_BT_MAX_CONN];
static int vcs_client_common_vcs_cp(struct bt_conn *conn, uint8_t opcode);
static struct vcs_instance *lookup_vcs_by_vocs(const struct bt_vocs *vocs)
{
__ASSERT(vocs != NULL, "VOCS pointer cannot be NULL");
for (int i = 0; i < ARRAY_SIZE(vcs_insts); i++) {
for (int j = 0; j < ARRAY_SIZE(vcs_insts[i].vocs); j++) {
if (vcs_insts[i].vocs[j] == vocs) {
return &vcs_insts[i];
}
}
}
return NULL;
}
bool bt_vcs_client_valid_vocs_inst(struct bt_conn *conn, struct bt_vocs *vocs)
{
uint8_t conn_index;
@ -634,20 +650,31 @@ static void aics_discover_cb(struct bt_conn *conn, struct bt_aics *inst,
}
}
static void vocs_discover_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err)
static void vocs_discover_cb(struct bt_vocs *inst, int err)
{
struct vcs_instance *vcs_inst = &vcs_insts[bt_conn_index(conn)];
struct vcs_instance *vcs_inst = lookup_vcs_by_vocs(inst);
if (vcs_inst == NULL) {
BT_ERR("Could not lookup vcs_inst from vocs");
if (vcs_client_cb && vcs_client_cb->discover) {
vcs_client_cb->discover(vcs_inst->conn,
BT_GATT_ERR(BT_ATT_ERR_UNLIKELY),
0, 0);
}
return;
}
if (err == 0) {
/* Continue discovery of included services */
err = bt_gatt_discover(conn, &vcs_inst->discover_params);
err = bt_gatt_discover(vcs_inst->conn, &vcs_inst->discover_params);
}
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->conn, err, 0, 0);
}
}
}
@ -743,6 +770,7 @@ int bt_vcs_discover(struct bt_conn *conn)
memcpy(&vcs_inst->uuid, BT_UUID_VCS, sizeof(vcs_inst->uuid));
vcs_inst->conn = conn;
vcs_inst->discover_params.func = primary_discover_func;
vcs_inst->discover_params.uuid = &vcs_inst->uuid.uuid;
vcs_inst->discover_params.type = BT_GATT_DISCOVER_PRIMARY;

View file

@ -37,7 +37,8 @@ static ssize_t read_offset_state(struct bt_conn *conn, const struct bt_gatt_attr
struct bt_vocs *inst = attr->user_data;
BT_DBG("offset %d, counter %u", inst->srv.state.offset, inst->srv.state.change_counter);
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state, sizeof(inst->srv.state));
return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->srv.state,
sizeof(inst->srv.state));
}
static void location_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
@ -71,7 +72,7 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
sizeof(inst->srv.location));
if (inst->srv.cb && inst->srv.cb->location) {
inst->srv.cb->location(NULL, inst, 0, inst->srv.location);
inst->srv.cb->location(inst, 0, inst->srv.location);
}
}
@ -147,7 +148,7 @@ static ssize_t write_vocs_control(struct bt_conn *conn, const struct bt_gatt_att
&inst->srv.state, sizeof(inst->srv.state));
if (inst->srv.cb && inst->srv.cb->state) {
inst->srv.cb->state(NULL, inst, 0, inst->srv.state.offset);
inst->srv.cb->state(inst, 0, inst->srv.state.offset);
}
}
@ -188,7 +189,7 @@ static ssize_t write_output_desc(struct bt_conn *conn, const struct bt_gatt_attr
strlen(inst->srv.output_desc));
if (inst->srv.cb && inst->srv.cb->description) {
inst->srv.cb->description(NULL, inst, 0, inst->srv.output_desc);
inst->srv.cb->description(inst, 0, inst->srv.output_desc);
}
}
@ -352,18 +353,18 @@ int bt_vocs_register(struct bt_vocs *vocs,
#if defined(CONFIG_BT_VOCS) || defined(CONFIG_BT_VOCS_CLIENT)
int bt_vocs_state_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vocs_state_get(struct bt_vocs *inst)
{
CHECKIF(!inst) {
BT_DBG("Null VOCS pointer");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && conn) {
return bt_vocs_client_state_get(conn, inst);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !conn) {
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && inst->client_instance) {
return bt_vocs_client_state_get(inst);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !inst->client_instance) {
if (inst->srv.cb && inst->srv.cb->state) {
inst->srv.cb->state(NULL, inst, 0, inst->srv.state.offset);
inst->srv.cb->state(inst, 0, inst->srv.state.offset);
}
return 0;
}
@ -371,18 +372,18 @@ int bt_vocs_state_get(struct bt_conn *conn, struct bt_vocs *inst)
return -ENOTSUP;
}
int bt_vocs_location_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vocs_location_get(struct bt_vocs *inst)
{
CHECKIF(!inst) {
BT_DBG("Null VOCS pointer");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && conn) {
return bt_vocs_client_location_get(conn, inst);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !conn) {
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && inst->client_instance) {
return bt_vocs_client_location_get(inst);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !inst->client_instance) {
if (inst->srv.cb && inst->srv.cb->location) {
inst->srv.cb->location(NULL, inst, 0, inst->srv.location);
inst->srv.cb->location(inst, 0, inst->srv.location);
}
return 0;
}
@ -390,16 +391,16 @@ int bt_vocs_location_get(struct bt_conn *conn, struct bt_vocs *inst)
return -ENOTSUP;
}
int bt_vocs_location_set(struct bt_conn *conn, struct bt_vocs *inst, uint32_t location)
int bt_vocs_location_set(struct bt_vocs *inst, uint32_t location)
{
CHECKIF(!inst) {
BT_DBG("Null VOCS pointer");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && conn) {
return bt_vocs_client_location_set(conn, inst, location);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !conn) {
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && inst->client_instance) {
return bt_vocs_client_location_set(inst, location);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !inst->client_instance) {
struct bt_gatt_attr attr;
int err;
@ -413,16 +414,16 @@ int bt_vocs_location_set(struct bt_conn *conn, struct bt_vocs *inst, uint32_t lo
return -ENOTSUP;
}
int bt_vocs_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t offset)
int bt_vocs_state_set(struct bt_vocs *inst, int16_t offset)
{
CHECKIF(!inst) {
BT_DBG("Null VOCS pointer");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && conn) {
return bt_vocs_client_state_set(conn, inst, offset);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !conn) {
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && inst->client_instance) {
return bt_vocs_client_state_set(inst, offset);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !inst->client_instance) {
struct bt_gatt_attr attr;
struct bt_vocs_control cp;
int err;
@ -441,18 +442,18 @@ int bt_vocs_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t offset
return -ENOTSUP;
}
int bt_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vocs_description_get(struct bt_vocs *inst)
{
CHECKIF(!inst) {
BT_DBG("Null VOCS pointer");
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && conn) {
return bt_vocs_client_description_get(conn, inst);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !conn) {
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && inst->client_instance) {
return bt_vocs_client_description_get(inst);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !inst->client_instance) {
if (inst->srv.cb && inst->srv.cb->description) {
inst->srv.cb->description(NULL, inst, 0, inst->srv.output_desc);
inst->srv.cb->description(inst, 0, inst->srv.output_desc);
}
return 0;
}
@ -460,7 +461,7 @@ int bt_vocs_description_get(struct bt_conn *conn, struct bt_vocs *inst)
return -ENOTSUP;
}
int bt_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst, const char *description)
int bt_vocs_description_set(struct bt_vocs *inst, const char *description)
{
CHECKIF(!inst) {
BT_DBG("Null VOCS pointer");
@ -472,9 +473,9 @@ int bt_vocs_description_set(struct bt_conn *conn, struct bt_vocs *inst, const ch
return -EINVAL;
}
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && conn) {
return bt_vocs_client_description_set(conn, inst, description);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !conn) {
if (IS_ENABLED(CONFIG_BT_VOCS_CLIENT) && inst->client_instance) {
return bt_vocs_client_description_set(inst, description);
} else if (IS_ENABLED(CONFIG_BT_VOCS) && !inst->client_instance) {
struct bt_gatt_attr attr;
int err;

View file

@ -66,7 +66,7 @@ uint8_t vocs_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
BT_DBG("Inst %p: Offset %d, counter %u", inst, inst->cli.state.offset,
inst->cli.state.change_counter);
if (inst->cli.cb && inst->cli.cb->state) {
inst->cli.cb->state(conn, inst, 0, inst->cli.state.offset);
inst->cli.cb->state(inst, 0, inst->cli.state.offset);
}
} else {
BT_DBG("Invalid state length %u", length);
@ -86,14 +86,14 @@ uint8_t vocs_client_notify_handler(struct bt_conn *conn, struct bt_gatt_subscrib
desc[length] = '\0';
BT_DBG("Inst %p: Output description: %s", inst, log_strdup(desc));
if (inst->cli.cb && inst->cli.cb->description) {
inst->cli.cb->description(conn, inst, 0, desc);
inst->cli.cb->description(inst, 0, desc);
}
} else if (handle == inst->cli.location_handle) {
if (length == sizeof(inst->cli.location)) {
memcpy(&inst->cli.location, data, length);
BT_DBG("Inst %p: Location %u", inst, inst->cli.location);
if (inst->cli.cb && inst->cli.cb->location) {
inst->cli.cb->location(conn, inst, 0, inst->cli.location);
inst->cli.cb->location(inst, 0, inst->cli.location);
}
} else {
BT_DBG("Invalid location length %u", length);
@ -137,7 +137,7 @@ static uint8_t vocs_client_read_offset_state_cb(struct bt_conn *conn, uint8_t er
}
if (inst->cli.cb && inst->cli.cb->state) {
inst->cli.cb->state(conn, inst, cb_err,
inst->cli.cb->state(inst, cb_err,
cb_err ? 0 : inst->cli.state.offset);
}
@ -178,7 +178,7 @@ static uint8_t vocs_client_read_location_cb(struct bt_conn *conn, uint8_t err,
}
if (inst->cli.cb && inst->cli.cb->location) {
inst->cli.cb->location(conn, inst, cb_err,
inst->cli.cb->location(inst, cb_err,
cb_err ? 0 : inst->cli.location);
}
@ -213,7 +213,7 @@ static uint8_t internal_read_volume_offset_state_cb(struct bt_conn *conn, uint8_
/* clear busy flag to reuse function */
inst->cli.busy = false;
write_err = bt_vocs_client_state_set(conn, inst, inst->cli.cp.offset);
write_err = bt_vocs_client_state_set(inst, inst->cli.cp.offset);
if (write_err) {
cb_err = BT_ATT_ERR_UNLIKELY;
}
@ -230,7 +230,7 @@ static uint8_t internal_read_volume_offset_state_cb(struct bt_conn *conn, uint8_
inst->cli.busy = false;
if (inst->cli.cb && inst->cli.cb->set_offset) {
inst->cli.cb->set_offset(conn, inst, err);
inst->cli.cb->set_offset(inst, err);
}
}
@ -280,7 +280,7 @@ static void vcs_client_write_vocs_cp_cb(struct bt_conn *conn, uint8_t err,
inst->cli.cp_retried = false;
if (inst->cli.cb && inst->cli.cb->set_offset) {
inst->cli.cb->set_offset(conn, inst, cb_err);
inst->cli.cb->set_offset(inst, cb_err);
}
}
@ -322,8 +322,7 @@ static uint8_t vcs_client_read_output_desc_cb(struct bt_conn *conn, uint8_t err,
}
if (inst->cli.cb && inst->cli.cb->description) {
inst->cli.cb->description(conn, inst, cb_err,
cb_err ? NULL : desc);
inst->cli.cb->description(inst, cb_err, cb_err ? NULL : desc);
}
return BT_GATT_ITER_STOP;
@ -340,8 +339,10 @@ static bool valid_inst_discovered(struct bt_vocs *inst)
static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_attr *attr,
struct bt_gatt_discover_params *params)
{
struct bt_vocs *inst = (struct bt_vocs *)CONTAINER_OF(
params, struct bt_vocs_client, discover_params);
struct bt_vocs_client *client_inst = CONTAINER_OF(params,
struct bt_vocs_client,
discover_params);
struct bt_vocs *inst = CONTAINER_OF(client_inst, struct bt_vocs, cli);
if (!attr) {
BT_DBG("Discovery complete for VOCS %p", inst);
@ -351,7 +352,7 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
if (inst->cli.cb && inst->cli.cb->discover) {
int err = valid_inst_discovered(inst) ? 0 : -ENOENT;
inst->cli.cb->discover(conn, inst, err);
inst->cli.cb->discover(inst, err);
}
return BT_GATT_ITER_STOP;
@ -418,17 +419,17 @@ static uint8_t vocs_discover_func(struct bt_conn *conn, const struct bt_gatt_att
return BT_GATT_ITER_CONTINUE;
}
int bt_vocs_client_state_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vocs_client_state_get(struct bt_vocs *inst)
{
int err;
CHECKIF(conn == NULL) {
BT_DBG("NULL conn");
CHECKIF(!inst) {
BT_DBG("NULL instance");
return -EINVAL;
}
CHECKIF(!inst) {
BT_DBG("NULL instance");
CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
@ -447,7 +448,7 @@ int bt_vocs_client_state_get(struct bt_conn *conn, struct bt_vocs *inst)
inst->cli.read_params.single.handle = inst->cli.state_handle;
inst->cli.read_params.single.offset = 0U;
err = bt_gatt_read(conn, &inst->cli.read_params);
err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params);
if (!err) {
inst->cli.busy = true;
}
@ -455,18 +456,19 @@ int bt_vocs_client_state_get(struct bt_conn *conn, struct bt_vocs *inst)
return err;
}
int bt_vocs_client_location_set(struct bt_conn *conn, struct bt_vocs *inst, uint32_t location)
int bt_vocs_client_location_set(struct bt_vocs *inst, uint32_t location)
{
CHECKIF(conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
CHECKIF(!inst) {
BT_DBG("NULL instance");
return -EINVAL;
}
CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
if (!inst->cli.location_handle) {
BT_DBG("Handle not set");
return -EINVAL;
@ -477,22 +479,23 @@ int bt_vocs_client_location_set(struct bt_conn *conn, struct bt_vocs *inst, uint
return -EPERM;
}
return bt_gatt_write_without_response(conn, inst->cli.location_handle,
return bt_gatt_write_without_response(inst->cli.conn,
inst->cli.location_handle,
&location, sizeof(location),
false);
}
int bt_vocs_client_location_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vocs_client_location_get(struct bt_vocs *inst)
{
int err;
CHECKIF(conn == NULL) {
BT_DBG("NULL conn");
CHECKIF(!inst) {
BT_DBG("NULL instance");
return -EINVAL;
}
CHECKIF(!inst) {
BT_DBG("NULL instance");
CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
@ -508,7 +511,7 @@ int bt_vocs_client_location_get(struct bt_conn *conn, struct bt_vocs *inst)
inst->cli.read_params.single.handle = inst->cli.location_handle;
inst->cli.read_params.single.offset = 0U;
err = bt_gatt_read(conn, &inst->cli.read_params);
err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params);
if (!err) {
inst->cli.busy = true;
}
@ -516,17 +519,17 @@ int bt_vocs_client_location_get(struct bt_conn *conn, struct bt_vocs *inst)
return err;
}
int bt_vocs_client_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t offset)
int bt_vocs_client_state_set(struct bt_vocs *inst, int16_t offset)
{
int err;
CHECKIF(conn == NULL) {
BT_DBG("NULL conn");
CHECKIF(!inst) {
BT_DBG("NULL instance");
return -EINVAL;
}
CHECKIF(!inst) {
BT_DBG("NULL instance");
CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
@ -547,7 +550,7 @@ int bt_vocs_client_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t
inst->cli.write_params.handle = inst->cli.control_handle;
inst->cli.write_params.func = vcs_client_write_vocs_cp_cb;
err = bt_gatt_write(conn, &inst->cli.write_params);
err = bt_gatt_write(inst->cli.conn, &inst->cli.write_params);
if (!err) {
inst->cli.busy = true;
}
@ -555,17 +558,17 @@ int bt_vocs_client_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t
return err;
}
int bt_vocs_client_description_get(struct bt_conn *conn, struct bt_vocs *inst)
int bt_vocs_client_description_get(struct bt_vocs *inst)
{
int err;
CHECKIF(conn == NULL) {
BT_DBG("NULL conn");
CHECKIF(!inst) {
BT_DBG("NULL instance");
return -EINVAL;
}
CHECKIF(!inst) {
BT_DBG("NULL instance");
CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
@ -581,7 +584,7 @@ int bt_vocs_client_description_get(struct bt_conn *conn, struct bt_vocs *inst)
inst->cli.read_params.single.handle = inst->cli.desc_handle;
inst->cli.read_params.single.offset = 0U;
err = bt_gatt_read(conn, &inst->cli.read_params);
err = bt_gatt_read(inst->cli.conn, &inst->cli.read_params);
if (!err) {
inst->cli.busy = true;
}
@ -589,16 +592,16 @@ int bt_vocs_client_description_get(struct bt_conn *conn, struct bt_vocs *inst)
return err;
}
int bt_vocs_client_description_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vocs_client_description_set(struct bt_vocs *inst,
const char *description)
{
CHECKIF(conn == NULL) {
BT_DBG("NULL conn");
CHECKIF(!inst) {
BT_DBG("NULL instance");
return -EINVAL;
}
CHECKIF(!inst) {
BT_DBG("NULL instance");
CHECKIF(inst->cli.conn == NULL) {
BT_DBG("NULL conn");
return -EINVAL;
}
@ -612,7 +615,8 @@ int bt_vocs_client_description_set(struct bt_conn *conn, struct bt_vocs *inst,
return -EPERM;
}
return bt_gatt_write_without_response(conn, inst->cli.desc_handle,
return bt_gatt_write_without_response(inst->cli.conn,
inst->cli.desc_handle,
description,
strlen(description), false);
}
@ -621,6 +625,7 @@ struct bt_vocs *bt_vocs_client_free_instance_get(void)
{
for (int i = 0; i < ARRAY_SIZE(vocs_insts); i++) {
if (!vocs_insts[i].cli.active) {
vocs_insts[i].client_instance = true;
vocs_insts[i].cli.active = true;
return &vocs_insts[i];
}

View file

@ -69,18 +69,19 @@ struct bt_vocs_server {
};
struct bt_vocs {
bool client_instance;
union {
struct bt_vocs_server srv;
struct bt_vocs_client cli;
};
};
int bt_vocs_client_state_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vocs_client_state_set(struct bt_conn *conn, struct bt_vocs *inst, int16_t offset);
int bt_vocs_client_location_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vocs_client_location_set(struct bt_conn *conn, struct bt_vocs *inst, uint32_t location);
int bt_vocs_client_description_get(struct bt_conn *conn, struct bt_vocs *inst);
int bt_vocs_client_description_set(struct bt_conn *conn, struct bt_vocs *inst,
int bt_vocs_client_state_get(struct bt_vocs *inst);
int bt_vocs_client_state_set(struct bt_vocs *inst, int16_t offset);
int bt_vocs_client_location_get(struct bt_vocs *inst);
int bt_vocs_client_location_set(struct bt_vocs *inst, uint32_t location);
int bt_vocs_client_description_get(struct bt_vocs *inst);
int bt_vocs_client_description_set(struct bt_vocs *inst,
const char *description);
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_VOCS_INTERNAL_ */

View file

@ -104,8 +104,7 @@ static void aics_description_cb(struct bt_conn *conn, struct bt_aics *inst,
inst, description);
}
}
static void vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst, int err,
int16_t offset)
static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset)
{
if (err) {
shell_error(ctx_shell, "VOCS state get failed (%d) for inst %p",
@ -115,8 +114,7 @@ static void vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst, int err,
}
}
static void vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, uint32_t location)
static void vocs_location_cb(struct bt_vocs *inst, int err, uint32_t location)
{
if (err) {
shell_error(ctx_shell,
@ -128,8 +126,8 @@ static void vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
}
}
static void vocs_description_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, char *description)
static void vocs_description_cb(struct bt_vocs *inst, int err,
char *description)
{
if (err) {
shell_error(ctx_shell,

View file

@ -244,8 +244,7 @@ static void vcs_aics_description_cb(struct bt_conn *conn, struct bt_aics *inst,
#endif /* CONFIG_BT_VCS_CLIENT_MAX_AICS_INST > 0 */
#if CONFIG_BT_VCS_CLIENT_MAX_VOCS_INST > 0
static void vcs_vocs_set_offset_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err)
static void vcs_vocs_set_offset_cb(struct bt_vocs *inst, int err)
{
if (err != 0) {
shell_error(ctx_shell, "Set offset failed (%d) for inst %p",
@ -255,8 +254,7 @@ static void vcs_vocs_set_offset_cb(struct bt_conn *conn, struct bt_vocs *inst,
}
}
static void vcs_vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, int16_t offset)
static void vcs_vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset)
{
if (err != 0) {
shell_error(ctx_shell, "VOCS state get failed (%d) for inst %p",
@ -266,8 +264,8 @@ static void vcs_vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst,
}
}
static void vcs_vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, uint32_t location)
static void vcs_vocs_location_cb(struct bt_vocs *inst, int err,
uint32_t location)
{
if (err != 0) {
shell_error(ctx_shell,
@ -279,8 +277,8 @@ static void vcs_vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
}
}
static void vcs_vocs_description_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, char *description)
static void vcs_vocs_description_cb(struct bt_vocs *inst, int err,
char *description)
{
if (err != 0) {
shell_error(ctx_shell,

View file

@ -69,8 +69,7 @@ static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
g_cb = true;
}
static void vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst, int err,
int16_t offset)
static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset)
{
if (err) {
FAIL("VOCS state cb err (%d)", err);
@ -82,8 +81,7 @@ static void vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst, int err,
g_cb = true;
}
static void vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, uint32_t location)
static void vocs_location_cb(struct bt_vocs *inst, int err, uint32_t location)
{
if (err) {
FAIL("VOCS location cb err (%d)", err);
@ -95,8 +93,8 @@ static void vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
g_cb = true;
}
static void vocs_description_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, char *description)
static void vocs_description_cb(struct bt_vocs *inst, int err,
char *description)
{
if (err) {
FAIL("VOCS description cb err (%d)", err);
@ -114,7 +112,7 @@ static void vocs_description_cb(struct bt_conn *conn, struct bt_vocs *inst,
g_cb = true;
}
static void vocs_write_cb(struct bt_conn *conn, struct bt_vocs *inst, int err)
static void vocs_write_cb(struct bt_vocs *inst, int err)
{
if (err) {
FAIL("VOCS write failed (%d)\n", err);

View file

@ -73,8 +73,7 @@ static void vcs_flags_cb(struct bt_conn *conn, int err, uint8_t flags)
}
}
static void vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst, int err,
int16_t offset)
static void vocs_state_cb(struct bt_vocs *inst, int err, int16_t offset)
{
if (err) {
FAIL("VOCS state cb err (%d)", err);
@ -82,14 +81,10 @@ static void vocs_state_cb(struct bt_conn *conn, struct bt_vocs *inst, int err,
}
g_vocs_offset = offset;
if (!conn) {
g_cb = true;
}
g_cb = true;
}
static void vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, uint32_t location)
static void vocs_location_cb(struct bt_vocs *inst, int err, uint32_t location)
{
if (err) {
FAIL("VOCS location cb err (%d)", err);
@ -97,14 +92,11 @@ static void vocs_location_cb(struct bt_conn *conn, struct bt_vocs *inst,
}
g_vocs_location = location;
if (!conn) {
g_cb = true;
}
g_cb = true;
}
static void vocs_description_cb(struct bt_conn *conn, struct bt_vocs *inst,
int err, char *description)
static void vocs_description_cb(struct bt_vocs *inst, int err,
char *description)
{
if (err) {
FAIL("VOCS description cb err (%d)", err);
@ -113,10 +105,7 @@ static void vocs_description_cb(struct bt_conn *conn, struct bt_vocs *inst,
strncpy(g_vocs_desc, description, sizeof(g_vocs_desc) - 1);
g_vocs_desc[sizeof(g_vocs_desc) - 1] = '\0';
if (!conn) {
g_cb = true;
}
g_cb = true;
}
static void aics_state_cb(struct bt_conn *conn, struct bt_aics *inst, int err,