* [PATCH BlueZ 2/3] shared/vcp: Keep Change_Counter on operations that change nothing
2026-11-24 14:35 [PATCH BlueZ 1/3] shared/vcp: Notify Volume State on Mute Simon Mikuda
@ 2026-11-24 14:36 ` Simon Mikuda
2026-11-24 14:36 ` [PATCH BlueZ 3/3] unit/test-vcp: Add tests for Volume State changes Simon Mikuda
2026-11-24 20:43 ` [BlueZ,1/3] shared/vcp: Notify Volume State on Mute bluez.test.bot
2 siblings, 0 replies; 4+ messages in thread
From: Simon Mikuda @ 2026-11-24 14:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Simon Mikuda
VCS 3.1.3 says Change_Counter shall be incremented when Volume_Setting
or Mute changes and shall not be changed otherwise. Every Volume
Control Point operation increments it and notifies Volume State, also
a Mute when already muted, a Set Absolute Volume to the current volume
or a Volume Up at 255.
Leave Volume State as it is for an operation that changes neither
Volume_Setting nor Mute.
Fixes: b8a113ecbabc ("shared/vcp: Add initial code for handling VCP")
Assisted-by: Claude:claude-opus-5-5
---
src/shared/vcp.c | 55 ++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 51 insertions(+), 4 deletions(-)
diff --git a/src/shared/vcp.c b/src/shared/vcp.c
index d19bd9210..197084f50 100644
--- a/src/shared/vcp.c
+++ b/src/shared/vcp.c
@@ -578,6 +578,7 @@ static uint8_t vcs_rel_vol_down(struct bt_vcs *vcs, struct bt_vcp *vcp,
struct bt_vcp_db *vdb;
struct vol_state *vstate;
uint8_t *change_counter;
+ uint8_t vol_set;
DBG(vcp, "Volume Down");
@@ -602,7 +603,14 @@ static uint8_t vcs_rel_vol_down(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
- vstate->vol_set = MAX((vstate->vol_set - VCP_STEP_SIZE), 0);
+ vol_set = MAX((vstate->vol_set - VCP_STEP_SIZE), 0);
+
+ if (vol_set == vstate->vol_set) {
+ DBG(vcp, "Volume Down: already at minimum, no state change");
+ return 0;
+ }
+
+ vstate->vol_set = vol_set;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
vcp->volume = vstate->vol_set;
@@ -621,6 +629,7 @@ static uint8_t vcs_rel_vol_up(struct bt_vcs *vcs, struct bt_vcp *vcp,
struct bt_vcp_db *vdb;
struct vol_state *vstate;
uint8_t *change_counter;
+ uint8_t vol_set;
DBG(vcp, "Volume Up");
@@ -645,7 +654,14 @@ static uint8_t vcs_rel_vol_up(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
- vstate->vol_set = MIN((vstate->vol_set + VCP_STEP_SIZE), 255);
+ vol_set = MIN((vstate->vol_set + VCP_STEP_SIZE), 255);
+
+ if (vol_set == vstate->vol_set) {
+ DBG(vcp, "Volume Up: already at maximum, no state change");
+ return 0;
+ }
+
+ vstate->vol_set = vol_set;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
vcp->volume = vstate->vol_set;
@@ -664,6 +680,7 @@ static uint8_t vcs_unmute_rel_vol_down(struct bt_vcs *vcs, struct bt_vcp *vcp,
struct bt_vcp_db *vdb;
struct vol_state *vstate;
uint8_t *change_counter;
+ uint8_t vol_set;
DBG(vcp, "Un Mute and Volume Down");
@@ -688,8 +705,15 @@ static uint8_t vcs_unmute_rel_vol_down(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
+ vol_set = MAX((vstate->vol_set - VCP_STEP_SIZE), 0);
+
+ if (vol_set == vstate->vol_set && vstate->mute == 0x00) {
+ DBG(vcp, "Un Mute and Volume Down: no state change");
+ return 0;
+ }
+
vstate->mute = 0x00;
- vstate->vol_set = MAX((vstate->vol_set - VCP_STEP_SIZE), 0);
+ vstate->vol_set = vol_set;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
vcp->volume = vstate->vol_set;
@@ -708,6 +732,7 @@ static uint8_t vcs_unmute_rel_vol_up(struct bt_vcs *vcs, struct bt_vcp *vcp,
struct bt_vcp_db *vdb;
struct vol_state *vstate;
uint8_t *change_counter;
+ uint8_t vol_set;
DBG(vcp, "UN Mute and Volume Up");
@@ -732,8 +757,15 @@ static uint8_t vcs_unmute_rel_vol_up(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
+ vol_set = MIN((vstate->vol_set + VCP_STEP_SIZE), 255);
+
+ if (vol_set == vstate->vol_set && vstate->mute == 0x00) {
+ DBG(vcp, "Un Mute and Volume Up: no state change");
+ return 0;
+ }
+
vstate->mute = 0x00;
- vstate->vol_set = MIN((vstate->vol_set + VCP_STEP_SIZE), 255);
+ vstate->vol_set = vol_set;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
vcp->volume = vstate->vol_set;
@@ -776,6 +808,11 @@ static uint8_t vcs_set_absolute_vol(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
+ if (req->vol_set == vstate->vol_set) {
+ DBG(vcp, "Set Absolute Volume: no state change");
+ return 0;
+ }
+
vstate->vol_set = req->vol_set;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
vcp->volume = vstate->vol_set;
@@ -819,6 +856,11 @@ static uint8_t vcs_unmute(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
+ if (vstate->mute == 0x00) {
+ DBG(vcp, "Un Mute: already unmuted, no state change");
+ return 0;
+ }
+
vstate->mute = 0x00;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
@@ -858,6 +900,11 @@ static uint8_t vcs_mute(struct bt_vcs *vcs, struct bt_vcp *vcp,
return BT_ATT_ERROR_INVALID_CHANGE_COUNTER;
}
+ if (vstate->mute == 0x01) {
+ DBG(vcp, "Mute: already muted, no state change");
+ return 0;
+ }
+
vstate->mute = 0x01;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH BlueZ 3/3] unit/test-vcp: Add tests for Volume State changes
2026-11-24 14:35 [PATCH BlueZ 1/3] shared/vcp: Notify Volume State on Mute Simon Mikuda
2026-11-24 14:36 ` [PATCH BlueZ 2/3] shared/vcp: Keep Change_Counter on operations that change nothing Simon Mikuda
@ 2026-11-24 14:36 ` Simon Mikuda
2026-11-24 20:43 ` [BlueZ,1/3] shared/vcp: Notify Volume State on Mute bluez.test.bot
2 siblings, 0 replies; 4+ messages in thread
From: Simon Mikuda @ 2026-11-24 14:36 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Simon Mikuda
Check that a Mute notifies Volume State, and that operations which
change neither Volume_Setting nor Mute leave Change_Counter as it is.
Assisted-by: Claude:claude-opus-5-5
---
unit/test-vcp.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/unit/test-vcp.c b/unit/test-vcp.c
index 4ec4da428..ef27fda32 100644
--- a/unit/test-vcp.c
+++ b/unit/test-vcp.c
@@ -2761,12 +2761,85 @@ static void test_aics_unit_testcases(void)
}
+/* ATT: Write Request (0x12) len 4
+ * Handle: 0x0024 Type: Volume Control Point (0x2b7e)
+ * Data: 0600
+ * Opcode: Mute (0x06)
+ * Change Counter: 0
+ * ATT: Write Response (0x13) len 0
+ * ATT: Handle Value Notification (0x1b) len 5
+ * Handle: 0x0021 Type: Volume State (0x2b7d)
+ * Data: 000101
+ * Volume Setting: 0
+ * Mute: 1
+ * Change Counter: 1
+ */
+#define VCS_CP_MUTE \
+ IOV_DATA(0x12, 0x24, 0x00, 0x06, 0x00), \
+ IOV_DATA(0x13), \
+ IOV_NULL, \
+ IOV_DATA(0x1b, 0x21, 0x00, 0x00, 0x01, 0x01)
+
+/* ATT: Write Request (0x12) len 5
+ * Handle: 0x0024 Type: Volume Control Point (0x2b7e)
+ * Data: 040000
+ * Opcode: Set Absolute Volume (0x04)
+ * Change Counter: 0
+ * Volume Setting: 0
+ * ATT: Write Response (0x13) len 0
+ * ATT: Write Request (0x12) len 4
+ * Handle: 0x0024 Type: Volume Control Point (0x2b7e)
+ * Data: 0500
+ * Opcode: Unmute (0x05)
+ * Change Counter: 0
+ * ATT: Write Response (0x13) len 0
+ * ATT: Write Request (0x12) len 4
+ * Handle: 0x0024 Type: Volume Control Point (0x2b7e)
+ * Data: 0000
+ * Opcode: Relative Volume Down (0x00)
+ * Change Counter: 0
+ * ATT: Write Response (0x13) len 0
+ * ATT: Write Request (0x12) len 5
+ * Handle: 0x0024 Type: Volume Control Point (0x2b7e)
+ * Data: 040010
+ * Opcode: Set Absolute Volume (0x04)
+ * Change Counter: 0
+ * Volume Setting: 16
+ * ATT: Write Response (0x13) len 0
+ * ATT: Handle Value Notification (0x1b) len 5
+ * Handle: 0x0021 Type: Volume State (0x2b7d)
+ * Data: 100001
+ * Volume Setting: 16
+ * Mute: 0
+ * Change Counter: 1
+ */
+#define VCS_CP_NO_CHANGE \
+ IOV_DATA(0x12, 0x24, 0x00, 0x04, 0x00, 0x00), \
+ IOV_DATA(0x13), \
+ IOV_DATA(0x12, 0x24, 0x00, 0x05, 0x00), \
+ IOV_DATA(0x13), \
+ IOV_DATA(0x12, 0x24, 0x00, 0x00, 0x00), \
+ IOV_DATA(0x13), \
+ IOV_DATA(0x12, 0x24, 0x00, 0x04, 0x00, 0x10), \
+ IOV_DATA(0x13), \
+ IOV_NULL, \
+ IOV_DATA(0x1b, 0x21, 0x00, 0x10, 0x00, 0x01)
+
+static void test_vcs_unit_testcases(void)
+{
+ define_test("VCS/SR/CP/BLUEZ-1 [Mute notifies Volume State]",
+ test_server, NULL, VCS_CP_MUTE);
+ define_test("VCS/SR/CP/BLUEZ-2 [No change keeps Change Counter]",
+ test_server, NULL, VCS_CP_NO_CHANGE);
+}
+
int main(int argc, char *argv[])
{
tester_init(&argc, &argv);
test_vocs_unit_testcases();
test_aics_unit_testcases();
+ test_vcs_unit_testcases();
return tester_run();
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread