Bluetooth: Audio: Ignore RFU VOCS location

This commit changes VOCS set location behavior.
When an RFU location is written, VOCS ignores it.

Signed-off-by: Szymon Czapracki <szymon.czapracki@codecoup.pl>
This commit is contained in:
Szymon Czapracki 2022-10-06 14:51:46 +02:00 committed by Carles Cufí
commit 77c8cffae0
2 changed files with 44 additions and 4 deletions

View file

@ -222,6 +222,7 @@ struct bt_codec_data {
* These values are defined by the Generic Audio Assigned Numbers, bluetooth.com * These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
*/ */
enum bt_audio_location { enum bt_audio_location {
BT_AUDIO_LOCATION_PROHIBITED = 0,
BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0), BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0),
BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1), BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1),
BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2), BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2),
@ -252,6 +253,38 @@ enum bt_audio_location {
BT_AUDIO_LOCATION_RIGHT_SURROUND = BIT(27), 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. */ /** @brief Codec structure. */
struct bt_codec { struct bt_codec {
/** Data path ID /** Data path ID

View file

@ -19,6 +19,7 @@
#include "audio_internal.h" #include "audio_internal.h"
#include "vocs_internal.h" #include "vocs_internal.h"
#include "zephyr/bluetooth/audio/audio.h"
#define LOG_LEVEL CONFIG_BT_VOCS_LOG_LEVEL #define LOG_LEVEL CONFIG_BT_VOCS_LOG_LEVEL
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
@ -26,6 +27,8 @@ LOG_MODULE_REGISTER(bt_vocs);
#define VALID_VOCS_OPCODE(opcode) ((opcode) == BT_VOCS_OPCODE_SET_OFFSET) #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) #if defined(CONFIG_BT_VOCS)
static void offset_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) 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) const void *buf, uint16_t len, uint16_t offset, uint8_t flags)
{ {
struct bt_vocs *inst = BT_AUDIO_CHRC_USER_DATA(attr); 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) { if (offset) {
return BT_GATT_ERR(BT_ATT_ERR_INVALID_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); return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN);
} }
memcpy(&inst->srv.location, buf, len); new_location = sys_get_le32(buf);
LOG_DBG("%02x", inst->srv.location); 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, (void)bt_gatt_notify_uuid(NULL, BT_UUID_VOCS_LOCATION,
inst->srv.service_p->attrs, inst->srv.service_p->attrs,
&inst->srv.location, &inst->srv.location,