Skip to content

Commit f3fdb1f

Browse files
fredrikdanebjercarlescufi
authored andcommitted
Bluetooth: Audio: Make VCS optional notify characteristics optional
This change makes VCS Volume Flag characteristic Notify property optional and selectable through Kconfig. Signed-off-by: Fredrik Danebjer <frdn@demant.com>
1 parent 303a0af commit f3fdb1f

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

subsys/bluetooth/audio/Kconfig.vcp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ config BT_VCP_VOL_REND_AICS
4747
This hidden option makes it possible to easily check if AICS is
4848
enabled for VCS.
4949

50+
config BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE
51+
bool "Volume Flags notifiable support"
52+
help
53+
This option enables support for clients to subscribe for notifications
54+
on the Volume Flags characteristic.
55+
5056
endif # BT_VCP_VOL_REND
5157

5258
################### Volume Control Profile Volume Controller ###################

subsys/bluetooth/audio/vcp_vol_rend.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
192192
if (volume_change && !vol_rend.flags) {
193193
vol_rend.flags = 1;
194194

195-
bt_gatt_notify_uuid(NULL, BT_UUID_VCS_FLAGS,
196-
vol_rend.service_p->attrs,
197-
&vol_rend.flags, sizeof(vol_rend.flags));
195+
if (IS_ENABLED(CONFIG_BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE)) {
196+
bt_gatt_notify_uuid(NULL, BT_UUID_VCS_FLAGS,
197+
vol_rend.service_p->attrs,
198+
&vol_rend.flags, sizeof(vol_rend.flags));
199+
}
198200

199201
if (vol_rend.cb && vol_rend.cb->flags) {
200202
vol_rend.cb->flags(0, vol_rend.flags);
@@ -203,10 +205,12 @@ static ssize_t write_vcs_control(struct bt_conn *conn,
203205
return len;
204206
}
205207

208+
#if defined(CONFIG_BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE)
206209
static void flags_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value)
207210
{
208211
LOG_DBG("value 0x%04x", value);
209212
}
213+
#endif /* CONFIG_BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE */
210214

211215
static ssize_t read_flags(struct bt_conn *conn, const struct bt_gatt_attr *attr,
212216
void *buf, uint16_t len, uint16_t offset)
@@ -220,26 +224,34 @@ static ssize_t read_flags(struct bt_conn *conn, const struct bt_gatt_attr *attr,
220224
#define VOCS_INCLUDES(cnt) LISTIFY(cnt, DUMMY_INCLUDE, ())
221225
#define AICS_INCLUDES(cnt) LISTIFY(cnt, DUMMY_INCLUDE, ())
222226

223-
#define BT_VCS_DEFINITION \
224-
BT_GATT_PRIMARY_SERVICE(BT_UUID_VCS), \
225-
VOCS_INCLUDES(CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT) \
226-
AICS_INCLUDES(CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT) \
227-
BT_AUDIO_CHRC(BT_UUID_VCS_STATE, \
228-
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
229-
BT_GATT_PERM_READ_ENCRYPT, \
230-
read_vol_state, NULL, NULL), \
231-
BT_AUDIO_CCC(volume_state_cfg_changed), \
232-
BT_AUDIO_CHRC(BT_UUID_VCS_CONTROL, \
233-
BT_GATT_CHRC_WRITE, \
234-
BT_GATT_PERM_WRITE_ENCRYPT, \
235-
NULL, write_vcs_control, NULL), \
236-
BT_AUDIO_CHRC(BT_UUID_VCS_FLAGS, \
237-
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \
238-
BT_GATT_PERM_READ_ENCRYPT, \
239-
read_flags, NULL, NULL), \
227+
/* Volume Control Service GATT Attributes */
228+
static struct bt_gatt_attr vcs_attrs[] = {
229+
BT_GATT_PRIMARY_SERVICE(BT_UUID_VCS),
230+
VOCS_INCLUDES(CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT)
231+
AICS_INCLUDES(CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT)
232+
BT_AUDIO_CHRC(BT_UUID_VCS_STATE,
233+
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
234+
BT_GATT_PERM_READ_ENCRYPT,
235+
read_vol_state, NULL, NULL),
236+
BT_AUDIO_CCC(volume_state_cfg_changed),
237+
BT_AUDIO_CHRC(BT_UUID_VCS_CONTROL,
238+
BT_GATT_CHRC_WRITE,
239+
BT_GATT_PERM_WRITE_ENCRYPT,
240+
NULL, write_vcs_control, NULL),
241+
#if defined(CONFIG_BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE)
242+
BT_AUDIO_CHRC(BT_UUID_VCS_FLAGS,
243+
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
244+
BT_GATT_PERM_READ_ENCRYPT,
245+
read_flags, NULL, NULL),
240246
BT_AUDIO_CCC(flags_cfg_changed)
247+
#else
248+
BT_AUDIO_CHRC(BT_UUID_VCS_FLAGS,
249+
BT_GATT_CHRC_READ,
250+
BT_GATT_PERM_READ_ENCRYPT,
251+
read_flags, NULL, NULL)
252+
#endif /* CONFIG_BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE */
253+
};
241254

242-
static struct bt_gatt_attr vcs_attrs[] = { BT_VCS_DEFINITION };
243255
static struct bt_gatt_service vcs_svc;
244256

245257
static int prepare_vocs_inst(struct bt_vcp_vol_rend_register_param *param)

tests/bluetooth/shell/audio.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ CONFIG_BT_VCP_VOL_REND_AICS_INSTANCE_COUNT=1
8080
CONFIG_BT_VCP_VOL_CTLR=y
8181
CONFIG_BT_VCP_VOL_CTLR_MAX_VOCS_INST=1
8282
CONFIG_BT_VCP_VOL_CTLR_MAX_AICS_INST=1
83+
CONFIG_BT_VCP_VOL_REND_VOL_FLAGS_NOTIFIABLE=y
8384

8485
CONFIG_BT_MICP_MIC_DEV=y
8586
CONFIG_BT_MICP_MIC_DEV_AICS_INSTANCE_COUNT=1

0 commit comments

Comments
 (0)