diff --git a/include/zephyr/bluetooth/audio/audio.h b/include/zephyr/bluetooth/audio/audio.h index bf571a36f32..688275c9706 100644 --- a/include/zephyr/bluetooth/audio/audio.h +++ b/include/zephyr/bluetooth/audio/audio.h @@ -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), @@ -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 diff --git a/subsys/bluetooth/audio/vocs.c b/subsys/bluetooth/audio/vocs.c index 26158b03181..48c0449c12e 100644 --- a/subsys/bluetooth/audio/vocs.c +++ b/subsys/bluetooth/audio/vocs.c @@ -19,6 +19,7 @@ #include "audio_internal.h" #include "vocs_internal.h" +#include "zephyr/bluetooth/audio/audio.h" #define LOG_LEVEL CONFIG_BT_VOCS_LOG_LEVEL #include @@ -26,6 +27,8 @@ 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) + #if defined(CONFIG_BT_VOCS) static void offset_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { @@ -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); @@ -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,