* [PATCH BlueZ 1/3] shared/vcp: Notify Volume State on Mute
@ 2026-11-24 14:35 Simon Mikuda
2026-11-24 14:36 ` [PATCH BlueZ 2/3] shared/vcp: Keep Change_Counter on operations that change nothing Simon Mikuda
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Simon Mikuda @ 2026-11-24 14:35 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Simon Mikuda
A Mute operation on the Volume Control Point sets Mute and increments
Change_Counter, but unlike every other operation it does not notify
Volume State. A client that keeps Change_Counter from the notifications
then writes its next operation with a stale value and gets Invalid
Change Counter.
Fixes: b8a113ecbabc ("shared/vcp: Add initial code for handling VCP")
Assisted-by: Claude:claude-opus-5-5
---
src/shared/vcp.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/shared/vcp.c b/src/shared/vcp.c
index c7f74956e..d19bd9210 100644
--- a/src/shared/vcp.c
+++ b/src/shared/vcp.c
@@ -861,6 +861,9 @@ static uint8_t vcs_mute(struct bt_vcs *vcs, struct bt_vcp *vcp,
vstate->mute = 0x01;
vstate->counter = -~vstate->counter; /*Increment Change Counter*/
+ gatt_db_attribute_notify(vdb->vcs->vs, (void *)vstate,
+ sizeof(struct vol_state),
+ bt_vcp_get_att(vcp));
return 0;
}
base-commit: 1608f836188610aabeff5a3164169ebe0360e443
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [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
* RE: [BlueZ,1/3] shared/vcp: Notify Volume State on Mute
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 ` [PATCH BlueZ 3/3] unit/test-vcp: Add tests for Volume State changes Simon Mikuda
@ 2026-11-24 20:43 ` bluez.test.bot
2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2026-11-24 20:43 UTC (permalink / raw)
To: linux-bluetooth, simon.mikuda
[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1220967/
---Test result---
Test Summary:
CheckPatch PASS 1.05 seconds
GitLint PASS 0.77 seconds
BuildEll PASS 14.67 seconds
BluezMake PASS 190.23 seconds
MakeCheck PASS 13.21 seconds
MakeDistcheck PASS 107.64 seconds
CheckValgrind PASS 255.87 seconds
CheckSmatch PASS 199.57 seconds
bluezmakeextell PASS 64.45 seconds
TestFunctional PASS 906.35 seconds
IncrementalBuild PASS 208.24 seconds
ScanBuild PASS 647.44 seconds
https://github.com/bluez/bluez/pull/2906
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-24 20:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox