shared/vcp: Notify Volume State on Mute
PATCH 1/3 shared/vcp: Notify Volume State on Mute
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.
--- src/shared/vcp.c | 3 +++ 1 file changed, 3 insertions(+)
src/shared/vcp.c +3 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 2/3 shared/vcp: Keep Change_Counter on operations that change nothing
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.
--- src/shared/vcp.c | 55 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-)
src/shared/vcp.c +51 -4
@@ -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*/
Signature · 1 line
2.43.0
PATCH 3/3 unit/test-vcp: Add tests for Volume State changes
In reply to Simon MikudaCheck that a Mute notifies Volume State, and that operations which change neither Volume_Setting nor Mute leave Change_Counter as it is.
--- unit/test-vcp.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
unit/test-vcp.c +73 -0
@@ -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 (); }
Signature · 1 line
2.43.0
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
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 10 lines · On Tue, 24 Nov 2026 15:35:59 +0100 you wrote:
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 keepsChange_Counterfrom 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[...]
Here is the summary with links:
- [BlueZ,1/3] shared/vcp: Notify Volume State on Mute
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7f8bdd8ec535 - [BlueZ,2/3] shared/vcp: Keep Change_Counter on operations that change nothing https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a270559b0012 - [BlueZ,3/3] unit/test-vcp: Add tests for Volume State changes https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=eb36d50744e5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html