Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions include/zephyr/bluetooth/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct bt_codec_data {
* These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
*/
enum bt_audio_location {
BT_AUDIO_LOCATION_PROHIBITED = 0,
BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0),
BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1),
BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2),
Expand Down Expand Up @@ -252,6 +253,38 @@ enum bt_audio_location {
BT_AUDIO_LOCATION_RIGHT_SURROUND = BIT(27),
};

/**
* Any known location.
*/
#define BT_AUDIO_LOCATION_ANY (BT_AUDIO_LOCATION_FRONT_LEFT | \
BT_AUDIO_LOCATION_FRONT_RIGHT | \
BT_AUDIO_LOCATION_FRONT_CENTER | \
BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_1 | \
BT_AUDIO_LOCATION_BACK_LEFT | \
BT_AUDIO_LOCATION_BACK_RIGHT | \
BT_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER | \
BT_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER | \
BT_AUDIO_LOCATION_BACK_CENTER | \
BT_AUDIO_LOCATION_LOW_FREQ_EFFECTS_2 | \
BT_AUDIO_LOCATION_SIDE_LEFT | \
BT_AUDIO_LOCATION_SIDE_RIGHT | \
BT_AUDIO_LOCATION_TOP_FRONT_LEFT | \
BT_AUDIO_LOCATION_TOP_FRONT_RIGHT | \
BT_AUDIO_LOCATION_TOP_FRONT_CENTER | \
BT_AUDIO_LOCATION_TOP_CENTER | \
BT_AUDIO_LOCATION_TOP_BACK_LEFT | \
BT_AUDIO_LOCATION_TOP_BACK_RIGHT | \
BT_AUDIO_LOCATION_TOP_SIDE_LEFT | \
BT_AUDIO_LOCATION_TOP_SIDE_RIGHT | \
BT_AUDIO_LOCATION_TOP_BACK_CENTER | \
BT_AUDIO_LOCATION_BOTTOM_FRONT_CENTER | \
BT_AUDIO_LOCATION_BOTTOM_FRONT_LEFT | \
BT_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT | \
BT_AUDIO_LOCATION_FRONT_LEFT_WIDE | \
BT_AUDIO_LOCATION_FRONT_RIGHT_WIDE | \
BT_AUDIO_LOCATION_LEFT_SURROUND | \
BT_AUDIO_LOCATION_RIGHT_SURROUND)

/** @brief Codec structure. */
struct bt_codec {
/** Data path ID
Expand Down
15 changes: 11 additions & 4 deletions subsys/bluetooth/audio/vocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

#include "audio_internal.h"
#include "vocs_internal.h"
#include "zephyr/bluetooth/audio/audio.h"

#define LOG_LEVEL CONFIG_BT_VOCS_LOG_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_vocs);

#define VALID_VOCS_OPCODE(opcode) ((opcode) == BT_VOCS_OPCODE_SET_OFFSET)

#define BT_AUDIO_LOCATION_RFU (~BT_AUDIO_LOCATION_ANY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: We should probably avoid using the BT prefix for macros that only exist in specifics source files

Suggested change
#define BT_AUDIO_LOCATION_RFU (~BT_AUDIO_LOCATION_ANY)
#define AUDIO_LOCATION_RFU (~BT_AUDIO_LOCATION_ANY)

The alternative is to move this macro to audio_internal; quite possibly it's something we may use for other modules as well. Either way works :)


#if defined(CONFIG_BT_VOCS)
static void offset_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
{
Expand Down Expand Up @@ -53,7 +56,7 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
{
struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr);
uint32_t old_location = inst->srv.location;
enum bt_audio_location new_location;

if (offset) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
Expand All @@ -63,10 +66,14 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
}

memcpy(&inst->srv.location, buf, len);
LOG_DBG("%02x", inst->srv.location);
new_location = sys_get_le32(buf);
if ((new_location & BT_AUDIO_LOCATION_RFU) > 0) {
LOG_DBG("Invalid location %u", new_location);
return 0;
}

if (old_location != inst->srv.location) {
if (new_location != inst->srv.location) {
inst->srv.location = new_location;
(void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_LOCATION,
inst->srv.service_p->attrs,
&inst->srv.location,
Expand Down