* [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
@ 2025-06-24 6:04 Yang Li via B4 Relay
2025-06-24 7:39 ` [BlueZ,bluez] " bluez.test.bot
2025-06-24 13:08 ` [PATCH BlueZ bluez] " Luiz Augusto von Dentz
0 siblings, 2 replies; 8+ messages in thread
From: Yang Li via B4 Relay @ 2025-06-24 6:04 UTC (permalink / raw)
To: Linux Bluetooth; +Cc: Yang Li
From: Yang Li <yang.li@amlogic.com>
When the CIS link is disconnected, the ASE status transitions from Releasing to
Idle.
> HCI Event: Disconnect Complete (0x05) plen 4 #1484 [hci0] 67.947425
Status: Success (0x00)
Handle: 512 Address: 5C:B1:E1:2F:01:B9 (Resolvable)
Identity type: Random (0x01)
Identity: E8:D5:2B:59:57:A6 (Static)
Reason: Remote User Terminated Connection (0x13)
= bluetoothd: src/shared/bap.c:stream_io_disconnected() stream 0x.. 67.948018
= bluetoothd: src/shared/bap.c:bap_ucast_set_state() stream 0xdff.. 67.948145
= bluetoothd: src/shared/bap.c:stream_notify() stream 0xdffda8 st.. 67.948275
= bluetoothd: src/gatt-database.c:send_notification_to_device() G.. 67.948525
= bluetoothd: profiles/audio/bap.c:bap_state() stream 0xdffda8: r.. 67.948679
= bluetoothd: profiles/audio/transport.c:bap_state_changed() stre.. 67.948967
= bluetoothd: profiles/audio/transport.c:transport_update_playing.. 67.949061
= bluetoothd: profiles/audio/transport.c:media_transport_remove_o.. 67.949106
= bluetoothd: profiles/audio/transport.c:media_owner_free() Owner.. 67.949149
= bluetoothd: profiles/audio/transport.c:media_transport_suspend(.. 67.949375
= bluetoothd: profiles/audio/transport.c:transport_set_state() St.. 67.949423
= bluetoothd: src/shared/bap.c:bap_ucast_detach() stream 0xdffda8.. 67.949574
= bluetoothd: profiles/audio/media.c:pac_clear() endpoint 0xdd2d2.. 67.949710
When BIG sync is lost, the stream status transitions from Streaming to Idle.
> HCI Event: LE Meta Event (0x3e) plen 3 #3189 [hci0] 118.870863
LE Broadcast Isochronous Group Sync Lost (0x1e)
BIG Handle: 0x00
Reason: Remote User Terminated Connection (0x13)
= bluetoothd: src/shared/bap.c:stream_io_disconnected() stream 0.. 118.871183
= bluetoothd: src/shared/bap.c:bap_bcast_set_state() stream 0xdf.. 118.871227
= bluetoothd: profiles/audio/bap.c:bap_state_bcast_sink() stream.. 118.871258
= bluetoothd: profiles/audio/bass.c:bap_state_changed() stream 0.. 118.871307
= bluetoothd: src/gatt-database.c:send_notification_to_device()... 118.871384
= bluetoothd: profiles/audio/transport.c:bap_state_changed() str.. 118.871452
= bluetoothd: profiles/audio/transport.c:transport_bap_update_li.. 118.871509
= bluetoothd: profiles/audio/transport.c:transport_update_playin.. 118.871555
= bluetoothd: profiles/audio/transport.c:transport_set_state() S.. 118.871610
= bluetoothd: src/shared/bap.c:bap_bcast_sink_detach() stream 0x.. 118.871660
= bluetoothd: profiles/audio/media.c:pac_clear() endpoint 0xdd25.. 118.871689
Fixes: https://github.com/bluez/bluez/issues/1343
Signed-off-by: Yang Li <yang.li@amlogic.com>
---
src/shared/bap.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/src/shared/bap.c b/src/shared/bap.c
index bccbc73ff..d51f3106e 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -6584,10 +6584,8 @@ static bool stream_io_disconnected(struct io *io, void *user_data)
DBG(stream->bap, "stream %p io disconnected", stream);
- if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
- stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
+ stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
- bt_bap_stream_set_io(stream, -1);
return false;
}
---
base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
Best regards,
--
Yang Li <yang.li@amlogic.com>
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [BlueZ,bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-24 6:04 [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected Yang Li via B4 Relay
@ 2025-06-24 7:39 ` bluez.test.bot
2025-06-24 13:08 ` [PATCH BlueZ bluez] " Luiz Augusto von Dentz
1 sibling, 0 replies; 8+ messages in thread
From: bluez.test.bot @ 2025-06-24 7:39 UTC (permalink / raw)
To: linux-bluetooth, yang.li
[-- Attachment #1: Type: text/plain, Size: 1864 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/project/bluetooth/list/?series=975123
---Test result---
Test Summary:
CheckPatch PENDING 0.39 seconds
GitLint PENDING 0.30 seconds
BuildEll PASS 20.22 seconds
BluezMake PASS 2596.17 seconds
MakeCheck PASS 19.83 seconds
MakeDistcheck PASS 199.48 seconds
CheckValgrind PASS 277.04 seconds
CheckSmatch WARNING 306.05 seconds
bluezmakeextell PASS 128.05 seconds
IncrementalBuild PENDING 0.30 seconds
ScanBuild PASS 908.89 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/bap.c:317:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:317:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:317:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structures
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-24 6:04 [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected Yang Li via B4 Relay
2025-06-24 7:39 ` [BlueZ,bluez] " bluez.test.bot
@ 2025-06-24 13:08 ` Luiz Augusto von Dentz
2025-06-25 5:24 ` Yang Li
1 sibling, 1 reply; 8+ messages in thread
From: Luiz Augusto von Dentz @ 2025-06-24 13:08 UTC (permalink / raw)
To: yang.li; +Cc: Linux Bluetooth
Hi,
On Tue, Jun 24, 2025 at 2:04 AM Yang Li via B4 Relay
<devnull+yang.li.amlogic.com@kernel.org> wrote:
>
> From: Yang Li <yang.li@amlogic.com>
>
> When the CIS link is disconnected, the ASE status transitions from Releasing to
> Idle.
>
> > HCI Event: Disconnect Complete (0x05) plen 4 #1484 [hci0] 67.947425
> Status: Success (0x00)
> Handle: 512 Address: 5C:B1:E1:2F:01:B9 (Resolvable)
> Identity type: Random (0x01)
> Identity: E8:D5:2B:59:57:A6 (Static)
> Reason: Remote User Terminated Connection (0x13)
> = bluetoothd: src/shared/bap.c:stream_io_disconnected() stream 0x.. 67.948018
> = bluetoothd: src/shared/bap.c:bap_ucast_set_state() stream 0xdff.. 67.948145
> = bluetoothd: src/shared/bap.c:stream_notify() stream 0xdffda8 st.. 67.948275
> = bluetoothd: src/gatt-database.c:send_notification_to_device() G.. 67.948525
> = bluetoothd: profiles/audio/bap.c:bap_state() stream 0xdffda8: r.. 67.948679
> = bluetoothd: profiles/audio/transport.c:bap_state_changed() stre.. 67.948967
> = bluetoothd: profiles/audio/transport.c:transport_update_playing.. 67.949061
> = bluetoothd: profiles/audio/transport.c:media_transport_remove_o.. 67.949106
> = bluetoothd: profiles/audio/transport.c:media_owner_free() Owner.. 67.949149
> = bluetoothd: profiles/audio/transport.c:media_transport_suspend(.. 67.949375
> = bluetoothd: profiles/audio/transport.c:transport_set_state() St.. 67.949423
> = bluetoothd: src/shared/bap.c:bap_ucast_detach() stream 0xdffda8.. 67.949574
> = bluetoothd: profiles/audio/media.c:pac_clear() endpoint 0xdd2d2.. 67.949710
>
> When BIG sync is lost, the stream status transitions from Streaming to Idle.
>
> > HCI Event: LE Meta Event (0x3e) plen 3 #3189 [hci0] 118.870863
> LE Broadcast Isochronous Group Sync Lost (0x1e)
> BIG Handle: 0x00
> Reason: Remote User Terminated Connection (0x13)
> = bluetoothd: src/shared/bap.c:stream_io_disconnected() stream 0.. 118.871183
> = bluetoothd: src/shared/bap.c:bap_bcast_set_state() stream 0xdf.. 118.871227
> = bluetoothd: profiles/audio/bap.c:bap_state_bcast_sink() stream.. 118.871258
> = bluetoothd: profiles/audio/bass.c:bap_state_changed() stream 0.. 118.871307
> = bluetoothd: src/gatt-database.c:send_notification_to_device()... 118.871384
> = bluetoothd: profiles/audio/transport.c:bap_state_changed() str.. 118.871452
> = bluetoothd: profiles/audio/transport.c:transport_bap_update_li.. 118.871509
> = bluetoothd: profiles/audio/transport.c:transport_update_playin.. 118.871555
> = bluetoothd: profiles/audio/transport.c:transport_set_state() S.. 118.871610
> = bluetoothd: src/shared/bap.c:bap_bcast_sink_detach() stream 0x.. 118.871660
> = bluetoothd: profiles/audio/media.c:pac_clear() endpoint 0xdd25.. 118.871689
>
> Fixes: https://github.com/bluez/bluez/issues/1343
>
> Signed-off-by: Yang Li <yang.li@amlogic.com>
> ---
> src/shared/bap.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/src/shared/bap.c b/src/shared/bap.c
> index bccbc73ff..d51f3106e 100644
> --- a/src/shared/bap.c
> +++ b/src/shared/bap.c
> @@ -6584,10 +6584,8 @@ static bool stream_io_disconnected(struct io *io, void *user_data)
>
> DBG(stream->bap, "stream %p io disconnected", stream);
>
> - if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
> - stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
This is actually on purpose for unicast since that supports caching
the configuration, now perhaps this is not the case for broadcast
since the BIG may have been terminated so we probably need to check if
this is a broadcast stream or a unicast stream, or add a dedicated
callback for each type.
> + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
>
> - bt_bap_stream_set_io(stream, -1);
> return false;
> }
>
>
> ---
> base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
> change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
>
> Best regards,
> --
> Yang Li <yang.li@amlogic.com>
>
>
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-24 13:08 ` [PATCH BlueZ bluez] " Luiz Augusto von Dentz
@ 2025-06-25 5:24 ` Yang Li
2025-06-25 15:10 ` Pauli Virtanen
0 siblings, 1 reply; 8+ messages in thread
From: Yang Li @ 2025-06-25 5:24 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: Linux Bluetooth
在 2025/6/24 21:08, Luiz Augusto von Dentz 写道:
> [ EXTERNAL EMAIL ]
>
> Hi,
>
> On Tue, Jun 24, 2025 at 2:04 AM Yang Li via B4 Relay
> <devnull+yang.li.amlogic.com@kernel.org> wrote:
>> From: Yang Li <yang.li@amlogic.com>
>>
>> When the CIS link is disconnected, the ASE status transitions from Releasing to
>> Idle.
>>
>> > HCI Event: Disconnect Complete (0x05) plen 4 #1484 [hci0] 67.947425
>> Status: Success (0x00)
>> Handle: 512 Address: 5C:B1:E1:2F:01:B9 (Resolvable)
>> Identity type: Random (0x01)
>> Identity: E8:D5:2B:59:57:A6 (Static)
>> Reason: Remote User Terminated Connection (0x13)
>> = bluetoothd: src/shared/bap.c:stream_io_disconnected() stream 0x.. 67.948018
>> = bluetoothd: src/shared/bap.c:bap_ucast_set_state() stream 0xdff.. 67.948145
>> = bluetoothd: src/shared/bap.c:stream_notify() stream 0xdffda8 st.. 67.948275
>> = bluetoothd: src/gatt-database.c:send_notification_to_device() G.. 67.948525
>> = bluetoothd: profiles/audio/bap.c:bap_state() stream 0xdffda8: r.. 67.948679
>> = bluetoothd: profiles/audio/transport.c:bap_state_changed() stre.. 67.948967
>> = bluetoothd: profiles/audio/transport.c:transport_update_playing.. 67.949061
>> = bluetoothd: profiles/audio/transport.c:media_transport_remove_o.. 67.949106
>> = bluetoothd: profiles/audio/transport.c:media_owner_free() Owner.. 67.949149
>> = bluetoothd: profiles/audio/transport.c:media_transport_suspend(.. 67.949375
>> = bluetoothd: profiles/audio/transport.c:transport_set_state() St.. 67.949423
>> = bluetoothd: src/shared/bap.c:bap_ucast_detach() stream 0xdffda8.. 67.949574
>> = bluetoothd: profiles/audio/media.c:pac_clear() endpoint 0xdd2d2.. 67.949710
>>
>> When BIG sync is lost, the stream status transitions from Streaming to Idle.
>>
>> > HCI Event: LE Meta Event (0x3e) plen 3 #3189 [hci0] 118.870863
>> LE Broadcast Isochronous Group Sync Lost (0x1e)
>> BIG Handle: 0x00
>> Reason: Remote User Terminated Connection (0x13)
>> = bluetoothd: src/shared/bap.c:stream_io_disconnected() stream 0.. 118.871183
>> = bluetoothd: src/shared/bap.c:bap_bcast_set_state() stream 0xdf.. 118.871227
>> = bluetoothd: profiles/audio/bap.c:bap_state_bcast_sink() stream.. 118.871258
>> = bluetoothd: profiles/audio/bass.c:bap_state_changed() stream 0.. 118.871307
>> = bluetoothd: src/gatt-database.c:send_notification_to_device()... 118.871384
>> = bluetoothd: profiles/audio/transport.c:bap_state_changed() str.. 118.871452
>> = bluetoothd: profiles/audio/transport.c:transport_bap_update_li.. 118.871509
>> = bluetoothd: profiles/audio/transport.c:transport_update_playin.. 118.871555
>> = bluetoothd: profiles/audio/transport.c:transport_set_state() S.. 118.871610
>> = bluetoothd: src/shared/bap.c:bap_bcast_sink_detach() stream 0x.. 118.871660
>> = bluetoothd: profiles/audio/media.c:pac_clear() endpoint 0xdd25.. 118.871689
>>
>> Fixes: https://github.com/bluez/bluez/issues/1343
>>
>> Signed-off-by: Yang Li <yang.li@amlogic.com>
>> ---
>> src/shared/bap.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/src/shared/bap.c b/src/shared/bap.c
>> index bccbc73ff..d51f3106e 100644
>> --- a/src/shared/bap.c
>> +++ b/src/shared/bap.c
>> @@ -6584,10 +6584,8 @@ static bool stream_io_disconnected(struct io *io, void *user_data)
>>
>> DBG(stream->bap, "stream %p io disconnected", stream);
>>
>> - if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
>> - stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
> This is actually on purpose for unicast since that supports caching
> the configuration, now perhaps this is not the case for broadcast
> since the BIG may have been terminated so we probably need to check if
> this is a broadcast stream or a unicast stream, or add a dedicated
> callback for each type.
Regarding the Unicast caching configuration you mentioned, there is
currently an issue in the code flow. The relevant log is shown below:
When music is paused on the pixel 9 phone, the CIS link gets
disconnected. As the transport state changes from ACTIVE to IDLE, the
stream state transitions from config to qos.
> HCI Event: Disconnect Complete (0x05) plen 4 #1425 [hci0]
49.572089
Status: Success (0x00)
Handle: 512 Address: 6A:AB:51:47:3B:80 (Resolvable)
Identity type: Random (0x01)
Identity: E8:D5:2B:59:57:A6 (Static)
Reason: Remote User Terminated Connection (0x13)
bluetoothd[2313]: src/shared/bap.c:stream_io_disconnected() stream
0x1f9fc20 io disconnected
bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
0x1f9fc20 dir 0x01: releasing -> config
bluetoothd[2313]: src/shared/bap.c:stream_notify() stream 0x1f9fc20
state 1
bluetoothd[2313]: profiles/audio/transport.c:bap_state_changed()
stream 0x1f9fc20: releasing(6) -> config(1)
bluetoothd[2313]:
profiles/audio/transport.c:transport_update_playing()
/org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 State=TRANSPORT_STATE_ACTIVE
Playing=0
bluetoothd[2313]:
profiles/audio/transport.c:media_transport_remove_owner() Transport
/org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner :1.1
bluetoothd[2313]: profiles/audio/transport.c:media_owner_free() Owner
:1.1
bluetoothd[2313]:
profiles/audio/transport.c:media_transport_suspend() Transport
/org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner
bluetoothd[2313]: profiles/audio/transport.c:transport_set_state()
State changed /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1:
TRANSPORT_STATE_ACTIVE -> TRANSPORT_STATE_IDLE
bluetoothd[2313]: src/shared/bap.c:stream_disable() stream 0x1f9fc20
bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
0x1f9fc20 dir 0x01: config -> qos
ATTbluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1426
[hci0] 49.585656
ATT: Handle Value Notification (0x1b) len 46
Handle: 0x007b Type: Sink ASE (0x2bc4)
Data[44]:
01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
ASE ID: 1
State: Codec Configured (0x01)
Framing: Unframed PDUs supported (0x00)
PHY: 0x02
LE 2M PHY preffered (0x02)
RTN: 5
Max Transport Latency: 10
Presentation Delay Min: 20000 us
...
bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 24 #1427 [hci0]
49.585725
ATT: Handle Value Notification (0x1b) len 19
Handle: 0x007b Type: Sink ASE (0x2bc4)
Data[17]: 0102010010270000025000050a00204e00
ASE ID: 1
State: QoS Configured (0x02)
CIG ID: 0x01
CIS ID: 0x00
...
when playback resumes on the phone, it attempts to set the ASE state to
Codec. However, since the stream has already transitioned from config to
qos, the phone ends up disconnecting the connection.
bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 12 #1433 [hci0]
60.216004
ATT: Handle Value Notification (0x1b) len 7
Handle: 0x0087 Type: ASE Control Point (0x2bc6)
Data[5]: 0101010000
Opcode: Codec Configuration (0x01)
Number of ASE(s): 1
ASE: #0
ASE ID: 0x01
ASE Response Code: Success (0x00)
ASE Response Reason: None (0x00)
bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1434 [hci0]
60.226086
ATT: Handle Value Notification (0x1b) len 46
Handle: 0x007b Type: Sink ASE (0x2bc4)
Data[44]:
01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
ASE ID: 1
State: Codec Configured (0x01)
Framing: Unframed PDUs supported (0x00)
PHY: 0x02
LE 2M PHY preffered (0x02)
RTN: 5
Max Transport Latency: 10
Presentation Delay Min: 20000 us
Presentation Delay Max: 40000 us
Preferred Presentation Delay Min: 20000 us
Preferred Presentation Delay Max: 40000 us
Codec: LC3 (0x06)
Codec Specific Configuration: #0: len 0x02 type 0x01
Sampling Frequency: 16 Khz (0x03)
Codec Specific Configuration: #1: len 0x02 type 0x02
Frame Duration: 10 ms (0x01)
Codec Specific Configuration: #2: len 0x05 type 0x03
Location: 0x00000003
Front Left (0x00000001)
Front Right (0x00000002)
Codec Specific Configuration: #3: len 0x03 type 0x04
Frame Length: 40 (0x0028)
Codec Specific Configuration: #4: len 0x02 type 0x05
Frame Blocks per SDU: 1 (0x01)
...
> HCI Event: Disconnect Complete (0x05) plen 4 #1445 [hci0]
63.651497
Status: Success (0x00)
Handle: 16 Address: 6A:AB:51:47:3B:80 (Resolvable)
Identity type: Random (0x01)
Identity: E8:D5:2B:59:57:A6 (Static)
Reason: Remote User Terminated Connection (0x13)
Introducing a check in the stream logic to distinguish between Unicast
and Broadcast would indeed make it easier to handle different stream
types cleanly.
However, if we temporarily ignore Unicast caching, a simpler and cleaner
approach would be to transition the stream directly to IDLE when I/O is
disconnected.
Once the Unicast caching issue is properly resolved, we can revisit and
introduce stream-type-based handling accordingly.
>> + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
>>
>> - bt_bap_stream_set_io(stream, -1);
>> return false;
>> }
>>
>>
>> ---
>> base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
>> change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
>>
>> Best regards,
>> --
>> Yang Li <yang.li@amlogic.com>
>>
>>
>>
>
> --
> Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-25 5:24 ` Yang Li
@ 2025-06-25 15:10 ` Pauli Virtanen
2025-06-26 4:19 ` Yang Li
0 siblings, 1 reply; 8+ messages in thread
From: Pauli Virtanen @ 2025-06-25 15:10 UTC (permalink / raw)
To: Yang Li, Luiz Augusto von Dentz; +Cc: Linux Bluetooth
Hi,
ke, 2025-06-25 kello 13:24 +0800, Yang Li kirjoitti:
>
[clip]
> When music is paused on the pixel 9 phone, the CIS link gets
> disconnected. As the transport state changes from ACTIVE to IDLE, the
> stream state transitions from config to qos.
>
> > HCI Event: Disconnect Complete (0x05) plen 4 #1425 [hci0]
> 49.572089
> Status: Success (0x00)
> Handle: 512 Address: 6A:AB:51:47:3B:80 (Resolvable)
> Identity type: Random (0x01)
> Identity: E8:D5:2B:59:57:A6 (Static)
> Reason: Remote User Terminated Connection (0x13)
> bluetoothd[2313]: src/shared/bap.c:stream_io_disconnected() stream
> 0x1f9fc20 io disconnected
> bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
> 0x1f9fc20 dir 0x01: releasing -> config
> bluetoothd[2313]: src/shared/bap.c:stream_notify() stream 0x1f9fc20
> state 1
> bluetoothd[2313]: profiles/audio/transport.c:bap_state_changed()
> stream 0x1f9fc20: releasing(6) -> config(1)
> bluetoothd[2313]:
> profiles/audio/transport.c:transport_update_playing()
> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 State=TRANSPORT_STATE_ACTIVE
> Playing=0
> bluetoothd[2313]:
> profiles/audio/transport.c:media_transport_remove_owner() Transport
> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner :1.1
> bluetoothd[2313]: profiles/audio/transport.c:media_owner_free() Owner
> :1.1
> bluetoothd[2313]:
> profiles/audio/transport.c:media_transport_suspend() Transport
> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner
> bluetoothd[2313]: profiles/audio/transport.c:transport_set_state()
> State changed /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1:
> TRANSPORT_STATE_ACTIVE -> TRANSPORT_STATE_IDLE
> bluetoothd[2313]: src/shared/bap.c:stream_disable() stream 0x1f9fc20
AFAICS the bug appears to be:
- bap.c:stream_disable() should do nothing if stream is
not ENABLING or STREAMING
since it's called from bt_bap_stream_disable() which is called on
transport suspend which should be noop for BAP server if stream is
already gone.
> bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
> 0x1f9fc20 dir 0x01: config -> qos
> ATTbluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1426
> [hci0] 49.585656
> ATT: Handle Value Notification (0x1b) len 46
> Handle: 0x007b Type: Sink ASE (0x2bc4)
> Data[44]:
> 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
> ASE ID: 1
> State: Codec Configured (0x01)
> Framing: Unframed PDUs supported (0x00)
> PHY: 0x02
> LE 2M PHY preffered (0x02)
> RTN: 5
> Max Transport Latency: 10
> Presentation Delay Min: 20000 us
> ...
> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 24 #1427 [hci0]
> 49.585725
> ATT: Handle Value Notification (0x1b) len 19
> Handle: 0x007b Type: Sink ASE (0x2bc4)
> Data[17]: 0102010010270000025000050a00204e00
> ASE ID: 1
> State: QoS Configured (0x02)
> CIG ID: 0x01
> CIS ID: 0x00
> ...
>
> when playback resumes on the phone, it attempts to set the ASE state to
> Codec. However, since the stream has already transitioned from config to
> qos, the phone ends up disconnecting the connection.
>
> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 12 #1433 [hci0]
> 60.216004
> ATT: Handle Value Notification (0x1b) len 7
> Handle: 0x0087 Type: ASE Control Point (0x2bc6)
> Data[5]: 0101010000
> Opcode: Codec Configuration (0x01)
> Number of ASE(s): 1
> ASE: #0
> ASE ID: 0x01
> ASE Response Code: Success (0x00)
> ASE Response Reason: None (0x00)
> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1434 [hci0]
> 60.226086
> ATT: Handle Value Notification (0x1b) len 46
> Handle: 0x007b Type: Sink ASE (0x2bc4)
> Data[44]:
> 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
> ASE ID: 1
> State: Codec Configured (0x01)
> Framing: Unframed PDUs supported (0x00)
> PHY: 0x02
> LE 2M PHY preffered (0x02)
> RTN: 5
> Max Transport Latency: 10
> Presentation Delay Min: 20000 us
> Presentation Delay Max: 40000 us
> Preferred Presentation Delay Min: 20000 us
> Preferred Presentation Delay Max: 40000 us
> Codec: LC3 (0x06)
> Codec Specific Configuration: #0: len 0x02 type 0x01
> Sampling Frequency: 16 Khz (0x03)
> Codec Specific Configuration: #1: len 0x02 type 0x02
> Frame Duration: 10 ms (0x01)
> Codec Specific Configuration: #2: len 0x05 type 0x03
> Location: 0x00000003
> Front Left (0x00000001)
> Front Right (0x00000002)
> Codec Specific Configuration: #3: len 0x03 type 0x04
> Frame Length: 40 (0x0028)
> Codec Specific Configuration: #4: len 0x02 type 0x05
> Frame Blocks per SDU: 1 (0x01)
>
> ...
>
> > HCI Event: Disconnect Complete (0x05) plen 4 #1445 [hci0]
> 63.651497
> Status: Success (0x00)
> Handle: 16 Address: 6A:AB:51:47:3B:80 (Resolvable)
> Identity type: Random (0x01)
> Identity: E8:D5:2B:59:57:A6 (Static)
> Reason: Remote User Terminated Connection (0x13)
>
> Introducing a check in the stream logic to distinguish between Unicast
> and Broadcast would indeed make it easier to handle different stream
> types cleanly.
> However, if we temporarily ignore Unicast caching, a simpler and cleaner
> approach would be to transition the stream directly to IDLE when I/O is
> disconnected.
This disconnect callback is used for all the roles: unicast client,
unicast server, broadcast. All of those require different handling, so
it's probably most clear to split it.
For unicast server:
The behavior has to follow BAP v1.0.2 Sec. 5.6.8 and ASCS Table 3.2.
Transition to IDLE is only allowed from RELEASING --- but one can as
well go to CONFIG like it is in current master.
CIS loss from STREAMING should go to QOS, and I think it currently does
so, via bap_stream_set_io.
From a brief look, the current version in master is maybe OK, although
one could test the above case again with stream_disable() fix.
For unicast client:
The current version in master is probably OK, although one could double
check it again.
>
> Once the Unicast caching issue is properly resolved, we can revisit and
> introduce stream-type-based handling accordingly.
>
> > > + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
> > >
> > > - bt_bap_stream_set_io(stream, -1);
> > > return false;
> > > }
> > >
> > >
> > > ---
> > > base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
> > > change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
> > >
> > > Best regards,
> > > --
> > > Yang Li <yang.li@amlogic.com>
> > >
> > >
> > >
> >
> > --
> > Luiz Augusto von Dentz
--
Pauli Virtanen
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-25 15:10 ` Pauli Virtanen
@ 2025-06-26 4:19 ` Yang Li
2025-06-26 16:00 ` Pauli Virtanen
0 siblings, 1 reply; 8+ messages in thread
From: Yang Li @ 2025-06-26 4:19 UTC (permalink / raw)
To: Pauli Virtanen, Luiz Augusto von Dentz; +Cc: Linux Bluetooth
Hi Pauli,
> [ EXTERNAL EMAIL ]
>
> Hi,
>
> ke, 2025-06-25 kello 13:24 +0800, Yang Li kirjoitti:
>
> [clip]
>> When music is paused on the pixel 9 phone, the CIS link gets
>> disconnected. As the transport state changes from ACTIVE to IDLE, the
>> stream state transitions from config to qos.
>>
>> > HCI Event: Disconnect Complete (0x05) plen 4 #1425 [hci0]
>> 49.572089
>> Status: Success (0x00)
>> Handle: 512 Address: 6A:AB:51:47:3B:80 (Resolvable)
>> Identity type: Random (0x01)
>> Identity: E8:D5:2B:59:57:A6 (Static)
>> Reason: Remote User Terminated Connection (0x13)
>> bluetoothd[2313]: src/shared/bap.c:stream_io_disconnected() stream
>> 0x1f9fc20 io disconnected
>> bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
>> 0x1f9fc20 dir 0x01: releasing -> config
>> bluetoothd[2313]: src/shared/bap.c:stream_notify() stream 0x1f9fc20
>> state 1
>> bluetoothd[2313]: profiles/audio/transport.c:bap_state_changed()
>> stream 0x1f9fc20: releasing(6) -> config(1)
>> bluetoothd[2313]:
>> profiles/audio/transport.c:transport_update_playing()
>> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 State=TRANSPORT_STATE_ACTIVE
>> Playing=0
>> bluetoothd[2313]:
>> profiles/audio/transport.c:media_transport_remove_owner() Transport
>> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner :1.1
>> bluetoothd[2313]: profiles/audio/transport.c:media_owner_free() Owner
>> :1.1
>> bluetoothd[2313]:
>> profiles/audio/transport.c:media_transport_suspend() Transport
>> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner
>> bluetoothd[2313]: profiles/audio/transport.c:transport_set_state()
>> State changed /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1:
>> TRANSPORT_STATE_ACTIVE -> TRANSPORT_STATE_IDLE
>> bluetoothd[2313]: src/shared/bap.c:stream_disable() stream 0x1f9fc20
> AFAICS the bug appears to be:
>
> - bap.c:stream_disable() should do nothing if stream is
> not ENABLING or STREAMING
>
> since it's called from bt_bap_stream_disable() which is called on
> transport suspend which should be noop for BAP server if stream is
> already gone.
Following your suggestion, I updated the |stream_disable()| function,
which successfully resolved the issue.
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2059,7 +2059,9 @@ static uint8_t stream_disable(struct bt_bap_stream
*stream, struct iovec *rsp)
/* Sink can autonomously transit to QOS while source needs to go to
* Disabling until BT_ASCS_STOP is received.
*/
- if (stream->ep->dir == BT_BAP_SINK)
+ if (stream->ep->dir == BT_BAP_SINK &&
+ (stream->ep->state == BT_ASCS_ASE_STATE_ENABLING ||
+ stream->ep->state == BT_ASCS_ASE_STATE_STREAMING))
stream_set_state(stream, BT_BAP_STREAM_STATE_QOS);
>> bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
>> 0x1f9fc20 dir 0x01: config -> qos
>> ATTbluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1426
>> [hci0] 49.585656
>> ATT: Handle Value Notification (0x1b) len 46
>> Handle: 0x007b Type: Sink ASE (0x2bc4)
>> Data[44]:
>> 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
>> ASE ID: 1
>> State: Codec Configured (0x01)
>> Framing: Unframed PDUs supported (0x00)
>> PHY: 0x02
>> LE 2M PHY preffered (0x02)
>> RTN: 5
>> Max Transport Latency: 10
>> Presentation Delay Min: 20000 us
>> ...
>> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 24 #1427 [hci0]
>> 49.585725
>> ATT: Handle Value Notification (0x1b) len 19
>> Handle: 0x007b Type: Sink ASE (0x2bc4)
>> Data[17]: 0102010010270000025000050a00204e00
>> ASE ID: 1
>> State: QoS Configured (0x02)
>> CIG ID: 0x01
>> CIS ID: 0x00
>> ...
>>
>> when playback resumes on the phone, it attempts to set the ASE state to
>> Codec. However, since the stream has already transitioned from config to
>> qos, the phone ends up disconnecting the connection.
>>
>> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 12 #1433 [hci0]
>> 60.216004
>> ATT: Handle Value Notification (0x1b) len 7
>> Handle: 0x0087 Type: ASE Control Point (0x2bc6)
>> Data[5]: 0101010000
>> Opcode: Codec Configuration (0x01)
>> Number of ASE(s): 1
>> ASE: #0
>> ASE ID: 0x01
>> ASE Response Code: Success (0x00)
>> ASE Response Reason: None (0x00)
>> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1434 [hci0]
>> 60.226086
>> ATT: Handle Value Notification (0x1b) len 46
>> Handle: 0x007b Type: Sink ASE (0x2bc4)
>> Data[44]:
>> 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
>> ASE ID: 1
>> State: Codec Configured (0x01)
>> Framing: Unframed PDUs supported (0x00)
>> PHY: 0x02
>> LE 2M PHY preffered (0x02)
>> RTN: 5
>> Max Transport Latency: 10
>> Presentation Delay Min: 20000 us
>> Presentation Delay Max: 40000 us
>> Preferred Presentation Delay Min: 20000 us
>> Preferred Presentation Delay Max: 40000 us
>> Codec: LC3 (0x06)
>> Codec Specific Configuration: #0: len 0x02 type 0x01
>> Sampling Frequency: 16 Khz (0x03)
>> Codec Specific Configuration: #1: len 0x02 type 0x02
>> Frame Duration: 10 ms (0x01)
>> Codec Specific Configuration: #2: len 0x05 type 0x03
>> Location: 0x00000003
>> Front Left (0x00000001)
>> Front Right (0x00000002)
>> Codec Specific Configuration: #3: len 0x03 type 0x04
>> Frame Length: 40 (0x0028)
>> Codec Specific Configuration: #4: len 0x02 type 0x05
>> Frame Blocks per SDU: 1 (0x01)
>>
>> ...
>>
>> > HCI Event: Disconnect Complete (0x05) plen 4 #1445 [hci0]
>> 63.651497
>> Status: Success (0x00)
>> Handle: 16 Address: 6A:AB:51:47:3B:80 (Resolvable)
>> Identity type: Random (0x01)
>> Identity: E8:D5:2B:59:57:A6 (Static)
>> Reason: Remote User Terminated Connection (0x13)
>>
>> Introducing a check in the stream logic to distinguish between Unicast
>> and Broadcast would indeed make it easier to handle different stream
>> types cleanly.
>> However, if we temporarily ignore Unicast caching, a simpler and cleaner
>> approach would be to transition the stream directly to IDLE when I/O is
>> disconnected.
> This disconnect callback is used for all the roles: unicast client,
> unicast server, broadcast. All of those require different handling, so
> it's probably most clear to split it.
>
>
> For unicast server:
>
> The behavior has to follow BAP v1.0.2 Sec. 5.6.8 and ASCS Table 3.2.
> Transition to IDLE is only allowed from RELEASING --- but one can as
> well go to CONFIG like it is in current master.
>
> CIS loss from STREAMING should go to QOS, and I think it currently does
> so, via bap_stream_set_io.
>
> From a brief look, the current version in master is maybe OK, although
> one could test the above case again with stream_disable() fix.
>
>
> For unicast client:
>
> The current version in master is probably OK, although one could double
> check it again.
I've added type checking and made the following modifications. Please
check if this meets the requirements. I believe that unicast source and
broadcast source are active behaviors, so there's no need to change the
stream state through I/O status.
@@ -6584,10 +6584,15 @@ static bool stream_io_disconnected(struct io
*io, void *user_data)
DBG(stream->bap, "stream %p io disconnected", stream);
- if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
+ if (stream->lpac->type == BT_BAP_SINK &&
+ bt_bap_stream_get_state(stream) ==
BT_ASCS_ASE_STATE_RELEASING) {
stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
+ bt_bap_stream_set_io(stream, -1);
+ }
+
+ if (stream->lpac->type == BT_BAP_BCAST_SINK)
+ stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
- bt_bap_stream_set_io(stream, -1);
return false;
}
>> Once the Unicast caching issue is properly resolved, we can revisit and
>> introduce stream-type-based handling accordingly.
>>
>>>> + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
>>>>
>>>> - bt_bap_stream_set_io(stream, -1);
>>>> return false;
>>>> }
>>>>
>>>>
>>>> ---
>>>> base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
>>>> change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
>>>>
>>>> Best regards,
>>>> --
>>>> Yang Li <yang.li@amlogic.com>
>>>>
>>>>
>>>>
>>> --
>>> Luiz Augusto von Dentz
> --
> Pauli Virtanen
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-26 4:19 ` Yang Li
@ 2025-06-26 16:00 ` Pauli Virtanen
2025-06-30 7:20 ` Yang Li
0 siblings, 1 reply; 8+ messages in thread
From: Pauli Virtanen @ 2025-06-26 16:00 UTC (permalink / raw)
To: Yang Li, Luiz Augusto von Dentz; +Cc: Linux Bluetooth
Hi,
to, 2025-06-26 kello 12:19 +0800, Yang Li kirjoitti:
> Hi Pauli,
> > [ EXTERNAL EMAIL ]
> >
> > Hi,
> >
> > ke, 2025-06-25 kello 13:24 +0800, Yang Li kirjoitti:
> >
> > [clip]
> > > When music is paused on the pixel 9 phone, the CIS link gets
> > > disconnected. As the transport state changes from ACTIVE to IDLE, the
> > > stream state transitions from config to qos.
> > >
> > > > HCI Event: Disconnect Complete (0x05) plen 4 #1425 [hci0]
> > > 49.572089
> > > Status: Success (0x00)
> > > Handle: 512 Address: 6A:AB:51:47:3B:80 (Resolvable)
> > > Identity type: Random (0x01)
> > > Identity: E8:D5:2B:59:57:A6 (Static)
> > > Reason: Remote User Terminated Connection (0x13)
> > > bluetoothd[2313]: src/shared/bap.c:stream_io_disconnected() stream
> > > 0x1f9fc20 io disconnected
> > > bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
> > > 0x1f9fc20 dir 0x01: releasing -> config
> > > bluetoothd[2313]: src/shared/bap.c:stream_notify() stream 0x1f9fc20
> > > state 1
> > > bluetoothd[2313]: profiles/audio/transport.c:bap_state_changed()
> > > stream 0x1f9fc20: releasing(6) -> config(1)
> > > bluetoothd[2313]:
> > > profiles/audio/transport.c:transport_update_playing()
> > > /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 State=TRANSPORT_STATE_ACTIVE
> > > Playing=0
> > > bluetoothd[2313]:
> > > profiles/audio/transport.c:media_transport_remove_owner() Transport
> > > /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner :1.1
> > > bluetoothd[2313]: profiles/audio/transport.c:media_owner_free() Owner
> > > :1.1
> > > bluetoothd[2313]:
> > > profiles/audio/transport.c:media_transport_suspend() Transport
> > > /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner
> > > bluetoothd[2313]: profiles/audio/transport.c:transport_set_state()
> > > State changed /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1:
> > > TRANSPORT_STATE_ACTIVE -> TRANSPORT_STATE_IDLE
> > > bluetoothd[2313]: src/shared/bap.c:stream_disable() stream 0x1f9fc20
> > AFAICS the bug appears to be:
> >
> > - bap.c:stream_disable() should do nothing if stream is
> > not ENABLING or STREAMING
> >
> > since it's called from bt_bap_stream_disable() which is called on
> > transport suspend which should be noop for BAP server if stream is
> > already gone.
>
> Following your suggestion, I updated the |stream_disable()| function,
> which successfully resolved the issue.
>
> --- a/src/shared/bap.c
> +++ b/src/shared/bap.c
> @@ -2059,7 +2059,9 @@ static uint8_t stream_disable(struct bt_bap_stream
> *stream, struct iovec *rsp)
> /* Sink can autonomously transit to QOS while source needs to go to
> * Disabling until BT_ASCS_STOP is received.
> */
> - if (stream->ep->dir == BT_BAP_SINK)
> + if (stream->ep->dir == BT_BAP_SINK &&
> + (stream->ep->state == BT_ASCS_ASE_STATE_ENABLING ||
> + stream->ep->state == BT_ASCS_ASE_STATE_STREAMING))
> stream_set_state(stream, BT_BAP_STREAM_STATE_QOS);
Same applies to BT_BAP_SOURCE too. Only the check on top of function
needs change.
>
> > > bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
> > > 0x1f9fc20 dir 0x01: config -> qos
> > > ATTbluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1426
> > > [hci0] 49.585656
> > > ATT: Handle Value Notification (0x1b) len 46
> > > Handle: 0x007b Type: Sink ASE (0x2bc4)
> > > Data[44]:
> > > 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
> > > ASE ID: 1
> > > State: Codec Configured (0x01)
> > > Framing: Unframed PDUs supported (0x00)
> > > PHY: 0x02
> > > LE 2M PHY preffered (0x02)
> > > RTN: 5
> > > Max Transport Latency: 10
> > > Presentation Delay Min: 20000 us
> > > ...
> > > bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 24 #1427 [hci0]
> > > 49.585725
> > > ATT: Handle Value Notification (0x1b) len 19
> > > Handle: 0x007b Type: Sink ASE (0x2bc4)
> > > Data[17]: 0102010010270000025000050a00204e00
> > > ASE ID: 1
> > > State: QoS Configured (0x02)
> > > CIG ID: 0x01
> > > CIS ID: 0x00
> > > ...
> > >
> > > when playback resumes on the phone, it attempts to set the ASE state to
> > > Codec. However, since the stream has already transitioned from config to
> > > qos, the phone ends up disconnecting the connection.
> > >
> > > bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 12 #1433 [hci0]
> > > 60.216004
> > > ATT: Handle Value Notification (0x1b) len 7
> > > Handle: 0x0087 Type: ASE Control Point (0x2bc6)
> > > Data[5]: 0101010000
> > > Opcode: Codec Configuration (0x01)
> > > Number of ASE(s): 1
> > > ASE: #0
> > > ASE ID: 0x01
> > > ASE Response Code: Success (0x00)
> > > ASE Response Reason: None (0x00)
> > > bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1434 [hci0]
> > > 60.226086
> > > ATT: Handle Value Notification (0x1b) len 46
> > > Handle: 0x007b Type: Sink ASE (0x2bc4)
> > > Data[44]:
> > > 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
> > > ASE ID: 1
> > > State: Codec Configured (0x01)
> > > Framing: Unframed PDUs supported (0x00)
> > > PHY: 0x02
> > > LE 2M PHY preffered (0x02)
> > > RTN: 5
> > > Max Transport Latency: 10
> > > Presentation Delay Min: 20000 us
> > > Presentation Delay Max: 40000 us
> > > Preferred Presentation Delay Min: 20000 us
> > > Preferred Presentation Delay Max: 40000 us
> > > Codec: LC3 (0x06)
> > > Codec Specific Configuration: #0: len 0x02 type 0x01
> > > Sampling Frequency: 16 Khz (0x03)
> > > Codec Specific Configuration: #1: len 0x02 type 0x02
> > > Frame Duration: 10 ms (0x01)
> > > Codec Specific Configuration: #2: len 0x05 type 0x03
> > > Location: 0x00000003
> > > Front Left (0x00000001)
> > > Front Right (0x00000002)
> > > Codec Specific Configuration: #3: len 0x03 type 0x04
> > > Frame Length: 40 (0x0028)
> > > Codec Specific Configuration: #4: len 0x02 type 0x05
> > > Frame Blocks per SDU: 1 (0x01)
> > >
> > > ...
> > >
> > > > HCI Event: Disconnect Complete (0x05) plen 4 #1445 [hci0]
> > > 63.651497
> > > Status: Success (0x00)
> > > Handle: 16 Address: 6A:AB:51:47:3B:80 (Resolvable)
> > > Identity type: Random (0x01)
> > > Identity: E8:D5:2B:59:57:A6 (Static)
> > > Reason: Remote User Terminated Connection (0x13)
> > >
> > > Introducing a check in the stream logic to distinguish between Unicast
> > > and Broadcast would indeed make it easier to handle different stream
> > > types cleanly.
> > > However, if we temporarily ignore Unicast caching, a simpler and cleaner
> > > approach would be to transition the stream directly to IDLE when I/O is
> > > disconnected.
> > This disconnect callback is used for all the roles: unicast client,
> > unicast server, broadcast. All of those require different handling, so
> > it's probably most clear to split it.
> >
> >
> > For unicast server:
> >
> > The behavior has to follow BAP v1.0.2 Sec. 5.6.8 and ASCS Table 3.2.
> > Transition to IDLE is only allowed from RELEASING --- but one can as
> > well go to CONFIG like it is in current master.
> >
> > CIS loss from STREAMING should go to QOS, and I think it currently does
> > so, via bap_stream_set_io.
> >
> > From a brief look, the current version in master is maybe OK, although
> > one could test the above case again with stream_disable() fix.
> >
> >
> > For unicast client:
> >
> > The current version in master is probably OK, although one could double
> > check it again.
>
>
> I've added type checking and made the following modifications. Please
> check if this meets the requirements. I believe that unicast source and
> broadcast source are active behaviors, so there's no need to change the
> stream state through I/O status.
Please don't change the unicast behavior, unless you are fixing a
deviation from the specification, or can explicitly show there is no
change in behavior.
I understand this patch is about fixing the behavior on BIS loss.
> @@ -6584,10 +6584,15 @@ static bool stream_io_disconnected(struct io
> *io, void *user_data)
>
> DBG(stream->bap, "stream %p io disconnected", stream);
>
> - if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
> + if (stream->lpac->type == BT_BAP_SINK &&
> + bt_bap_stream_get_state(stream) ==
> BT_ASCS_ASE_STATE_RELEASING) {
> stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
> + bt_bap_stream_set_io(stream, -1);
> + }
> +
> + if (stream->lpac->type == BT_BAP_BCAST_SINK)
> + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
>
> - bt_bap_stream_set_io(stream, -1);
This doesn't look right vs. unicast server. What performs the
transitions to IDLE/CONFIG/QOS for unicast Source? See BAP Sec 5.6.7
and 5.6.8.
> return false;
> }
>
> > > Once the Unicast caching issue is properly resolved, we can revisit and
> > > introduce stream-type-based handling accordingly.
> > >
> > > > > + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
> > > > >
> > > > > - bt_bap_stream_set_io(stream, -1);
> > > > > return false;
> > > > > }
> > > > >
> > > > >
> > > > > ---
> > > > > base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
> > > > > change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
> > > > >
> > > > > Best regards,
> > > > > --
> > > > > Yang Li <yang.li@amlogic.com>
> > > > >
> > > > >
> > > > >
> > > > --
> > > > Luiz Augusto von Dentz
> > --
> > Pauli Virtanen
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected
2025-06-26 16:00 ` Pauli Virtanen
@ 2025-06-30 7:20 ` Yang Li
0 siblings, 0 replies; 8+ messages in thread
From: Yang Li @ 2025-06-30 7:20 UTC (permalink / raw)
To: Pauli Virtanen, Luiz Augusto von Dentz; +Cc: Linux Bluetooth
Hi,
> [ EXTERNAL EMAIL ]
>
> Hi,
>
> to, 2025-06-26 kello 12:19 +0800, Yang Li kirjoitti:
>> Hi Pauli,
>>> [ EXTERNAL EMAIL ]
>>>
>>> Hi,
>>>
>>> ke, 2025-06-25 kello 13:24 +0800, Yang Li kirjoitti:
>>>
>>> [clip]
>>>> When music is paused on the pixel 9 phone, the CIS link gets
>>>> disconnected. As the transport state changes from ACTIVE to IDLE, the
>>>> stream state transitions from config to qos.
>>>>
>>>> > HCI Event: Disconnect Complete (0x05) plen 4 #1425 [hci0]
>>>> 49.572089
>>>> Status: Success (0x00)
>>>> Handle: 512 Address: 6A:AB:51:47:3B:80 (Resolvable)
>>>> Identity type: Random (0x01)
>>>> Identity: E8:D5:2B:59:57:A6 (Static)
>>>> Reason: Remote User Terminated Connection (0x13)
>>>> bluetoothd[2313]: src/shared/bap.c:stream_io_disconnected() stream
>>>> 0x1f9fc20 io disconnected
>>>> bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
>>>> 0x1f9fc20 dir 0x01: releasing -> config
>>>> bluetoothd[2313]: src/shared/bap.c:stream_notify() stream 0x1f9fc20
>>>> state 1
>>>> bluetoothd[2313]: profiles/audio/transport.c:bap_state_changed()
>>>> stream 0x1f9fc20: releasing(6) -> config(1)
>>>> bluetoothd[2313]:
>>>> profiles/audio/transport.c:transport_update_playing()
>>>> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 State=TRANSPORT_STATE_ACTIVE
>>>> Playing=0
>>>> bluetoothd[2313]:
>>>> profiles/audio/transport.c:media_transport_remove_owner() Transport
>>>> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner :1.1
>>>> bluetoothd[2313]: profiles/audio/transport.c:media_owner_free() Owner
>>>> :1.1
>>>> bluetoothd[2313]:
>>>> profiles/audio/transport.c:media_transport_suspend() Transport
>>>> /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1 Owner
>>>> bluetoothd[2313]: profiles/audio/transport.c:transport_set_state()
>>>> State changed /org/bluez/hci0/dev_6A_AB_51_47_3B_80/fd1:
>>>> TRANSPORT_STATE_ACTIVE -> TRANSPORT_STATE_IDLE
>>>> bluetoothd[2313]: src/shared/bap.c:stream_disable() stream 0x1f9fc20
>>> AFAICS the bug appears to be:
>>>
>>> - bap.c:stream_disable() should do nothing if stream is
>>> not ENABLING or STREAMING
>>>
>>> since it's called from bt_bap_stream_disable() which is called on
>>> transport suspend which should be noop for BAP server if stream is
>>> already gone.
>> Following your suggestion, I updated the |stream_disable()| function,
>> which successfully resolved the issue.
>>
>> --- a/src/shared/bap.c
>> +++ b/src/shared/bap.c
>> @@ -2059,7 +2059,9 @@ static uint8_t stream_disable(struct bt_bap_stream
>> *stream, struct iovec *rsp)
>> /* Sink can autonomously transit to QOS while source needs to go to
>> * Disabling until BT_ASCS_STOP is received.
>> */
>> - if (stream->ep->dir == BT_BAP_SINK)
>> + if (stream->ep->dir == BT_BAP_SINK &&
>> + (stream->ep->state == BT_ASCS_ASE_STATE_ENABLING ||
>> + stream->ep->state == BT_ASCS_ASE_STATE_STREAMING))
>> stream_set_state(stream, BT_BAP_STREAM_STATE_QOS);
> Same applies to BT_BAP_SOURCE too. Only the check on top of function
> needs change.
Will do.
I will submit a new patch to address the ASE state issue.
>>>> bluetoothd[2313]: src/shared/bap.c:bap_ucast_set_state() stream
>>>> 0x1f9fc20 dir 0x01: config -> qos
>>>> ATTbluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1426
>>>> [hci0] 49.585656
>>>> ATT: Handle Value Notification (0x1b) len 46
>>>> Handle: 0x007b Type: Sink ASE (0x2bc4)
>>>> Data[44]:
>>>> 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
>>>> ASE ID: 1
>>>> State: Codec Configured (0x01)
>>>> Framing: Unframed PDUs supported (0x00)
>>>> PHY: 0x02
>>>> LE 2M PHY preffered (0x02)
>>>> RTN: 5
>>>> Max Transport Latency: 10
>>>> Presentation Delay Min: 20000 us
>>>> ...
>>>> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 24 #1427 [hci0]
>>>> 49.585725
>>>> ATT: Handle Value Notification (0x1b) len 19
>>>> Handle: 0x007b Type: Sink ASE (0x2bc4)
>>>> Data[17]: 0102010010270000025000050a00204e00
>>>> ASE ID: 1
>>>> State: QoS Configured (0x02)
>>>> CIG ID: 0x01
>>>> CIS ID: 0x00
>>>> ...
>>>>
>>>> when playback resumes on the phone, it attempts to set the ASE state to
>>>> Codec. However, since the stream has already transitioned from config to
>>>> qos, the phone ends up disconnecting the connection.
>>>>
>>>> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 12 #1433 [hci0]
>>>> 60.216004
>>>> ATT: Handle Value Notification (0x1b) len 7
>>>> Handle: 0x0087 Type: ASE Control Point (0x2bc6)
>>>> Data[5]: 0101010000
>>>> Opcode: Codec Configuration (0x01)
>>>> Number of ASE(s): 1
>>>> ASE: #0
>>>> ASE ID: 0x01
>>>> ASE Response Code: Success (0x00)
>>>> ASE Response Reason: None (0x00)
>>>> bluetoothd[2313]: < ACL Data TX: H.. flags 0x00 dlen 51 #1434 [hci0]
>>>> 60.226086
>>>> ATT: Handle Value Notification (0x1b) len 46
>>>> Handle: 0x007b Type: Sink ASE (0x2bc4)
>>>> Data[44]:
>>>> 01010002050a00204e00409c00204e00409c0006000000001302010302020105030300000003042800020501
>>>> ASE ID: 1
>>>> State: Codec Configured (0x01)
>>>> Framing: Unframed PDUs supported (0x00)
>>>> PHY: 0x02
>>>> LE 2M PHY preffered (0x02)
>>>> RTN: 5
>>>> Max Transport Latency: 10
>>>> Presentation Delay Min: 20000 us
>>>> Presentation Delay Max: 40000 us
>>>> Preferred Presentation Delay Min: 20000 us
>>>> Preferred Presentation Delay Max: 40000 us
>>>> Codec: LC3 (0x06)
>>>> Codec Specific Configuration: #0: len 0x02 type 0x01
>>>> Sampling Frequency: 16 Khz (0x03)
>>>> Codec Specific Configuration: #1: len 0x02 type 0x02
>>>> Frame Duration: 10 ms (0x01)
>>>> Codec Specific Configuration: #2: len 0x05 type 0x03
>>>> Location: 0x00000003
>>>> Front Left (0x00000001)
>>>> Front Right (0x00000002)
>>>> Codec Specific Configuration: #3: len 0x03 type 0x04
>>>> Frame Length: 40 (0x0028)
>>>> Codec Specific Configuration: #4: len 0x02 type 0x05
>>>> Frame Blocks per SDU: 1 (0x01)
>>>>
>>>> ...
>>>>
>>>> > HCI Event: Disconnect Complete (0x05) plen 4 #1445 [hci0]
>>>> 63.651497
>>>> Status: Success (0x00)
>>>> Handle: 16 Address: 6A:AB:51:47:3B:80 (Resolvable)
>>>> Identity type: Random (0x01)
>>>> Identity: E8:D5:2B:59:57:A6 (Static)
>>>> Reason: Remote User Terminated Connection (0x13)
>>>>
>>>> Introducing a check in the stream logic to distinguish between Unicast
>>>> and Broadcast would indeed make it easier to handle different stream
>>>> types cleanly.
>>>> However, if we temporarily ignore Unicast caching, a simpler and cleaner
>>>> approach would be to transition the stream directly to IDLE when I/O is
>>>> disconnected.
>>> This disconnect callback is used for all the roles: unicast client,
>>> unicast server, broadcast. All of those require different handling, so
>>> it's probably most clear to split it.
>>>
>>>
>>> For unicast server:
>>>
>>> The behavior has to follow BAP v1.0.2 Sec. 5.6.8 and ASCS Table 3.2.
>>> Transition to IDLE is only allowed from RELEASING --- but one can as
>>> well go to CONFIG like it is in current master.
>>>
>>> CIS loss from STREAMING should go to QOS, and I think it currently does
>>> so, via bap_stream_set_io.
>>>
>>> From a brief look, the current version in master is maybe OK, although
>>> one could test the above case again with stream_disable() fix.
>>>
>>>
>>> For unicast client:
>>>
>>> The current version in master is probably OK, although one could double
>>> check it again.
>>
>> I've added type checking and made the following modifications. Please
>> check if this meets the requirements. I believe that unicast source and
>> broadcast source are active behaviors, so there's no need to change the
>> stream state through I/O status.
> Please don't change the unicast behavior, unless you are fixing a
> deviation from the specification, or can explicitly show there is no
> change in behavior.
>
> I understand this patch is about fixing the behavior on BIS loss.
OK, for this revision I only added the handling for BT_BAP_BCAST_SINK.
@@ -6584,6 +6586,11 @@ static bool stream_io_disconnected(struct io *io,
void *user_data)
DBG(stream->bap, "stream %p io disconnected", stream);
+ if (stream->lpac->type == BT_BAP_BCAST_SINK) {
+ stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
+ return false;
+ }
+
if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
>> @@ -6584,10 +6584,15 @@ static bool stream_io_disconnected(struct io
>> *io, void *user_data)
>>
>> DBG(stream->bap, "stream %p io disconnected", stream);
>>
>> - if (stream->ep->state == BT_ASCS_ASE_STATE_RELEASING)
>> + if (stream->lpac->type == BT_BAP_SINK &&
>> + bt_bap_stream_get_state(stream) ==
>> BT_ASCS_ASE_STATE_RELEASING) {
>> stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
>> + bt_bap_stream_set_io(stream, -1);
>> + }
>> +
>> + if (stream->lpac->type == BT_BAP_BCAST_SINK)
>> + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
>>
>> - bt_bap_stream_set_io(stream, -1);
> This doesn't look right vs. unicast server. What performs the
> transitions to IDLE/CONFIG/QOS for unicast Source? See BAP Sec 5.6.7
> and 5.6.8.
I got it.
>> return false;
>> }
>>
>>>> Once the Unicast caching issue is properly resolved, we can revisit and
>>>> introduce stream-type-based handling accordingly.
>>>>
>>>>>> + stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE);
>>>>>>
>>>>>> - bt_bap_stream_set_io(stream, -1);
>>>>>> return false;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> ---
>>>>>> base-commit: ae1b7f6ba805f82742bbc32ff275e268248ef9f8
>>>>>> change-id: 20250624-bap_for_big_sync_lost-63476c679dbb
>>>>>>
>>>>>> Best regards,
>>>>>> --
>>>>>> Yang Li <yang.li@amlogic.com>
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> Luiz Augusto von Dentz
>>> --
>>> Pauli Virtanen
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-06-30 7:21 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-24 6:04 [PATCH BlueZ bluez] shared/bap: Set stream to idle when I/O is disconnected Yang Li via B4 Relay
2025-06-24 7:39 ` [BlueZ,bluez] " bluez.test.bot
2025-06-24 13:08 ` [PATCH BlueZ bluez] " Luiz Augusto von Dentz
2025-06-25 5:24 ` Yang Li
2025-06-25 15:10 ` Pauli Virtanen
2025-06-26 4:19 ` Yang Li
2025-06-26 16:00 ` Pauli Virtanen
2025-06-30 7:20 ` Yang Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox