platform/upstream/bluez.git
3 months agoUpdate bluez version to 5.79 in spec file bluez_upgrade_5.79 accepted/tizen/unified/20250221.111447 accepted/tizen/unified/x/20250221.231511
Anuj Jain [Fri, 14 Feb 2025 07:46:05 +0000 (13:16 +0530)]
Update bluez version to 5.79 in spec file

Change-Id: I28a23021046153b98738918e80b8f398b4176cd1
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoRelease 5.79
Marcel Holtmann [Fri, 1 Nov 2024 19:18:33 +0000 (20:18 +0100)]
Release 5.79

Change-Id: Iaab1810e868218864c8e370dba5a79ec14907536
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotextfile: Fix possible bad memory access in find_key
Yun-Hao Chung [Fri, 1 Nov 2024 07:19:39 +0000 (15:19 +0800)]
textfile: Fix possible bad memory access in find_key

If the searched key is a prefix of the first key in the textfile,
the code will assume it's not the first line which is wrong.

The issue can be reproduced by a fuzzer. More context can be found in
https://issues.oss-fuzz.com/issues/42515619

To reproduce the issue, please kindly follow the instructions in
https://google.github.io/oss-fuzz/advanced-topics/reproducing/

Stack trace:
    #0 0x55e1c450e7ce in find_key /src/bluez/src/textfile.c:133:9
    #1 0x55e1c450e7ce in write_key /src/bluez/src/textfile.c:244:8
    #2 0x55e1c450dc33 in LLVMFuzzerTestOneInput /src/fuzz_textfile.c:61:3
    (...trace in fuzzer)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobuild: Fix missing include
Luiz Augusto von Dentz [Wed, 30 Oct 2024 13:33:59 +0000 (09:33 -0400)]
build: Fix missing include

This fixes the following build error:

profiles/input/manager.c:102:4: error: implicit declaration of function ‘free’ [-Werror=implicit-function-declaration]
  102 |    free(uhid_enabled);
      |    ^~~~

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agomain: Add call to g_dbus_set_debug
Luiz Augusto von Dentz [Tue, 29 Oct 2024 21:27:14 +0000 (17:27 -0400)]
main: Add call to g_dbus_set_debug

This adds a call to g_dbus_set_debug which enabled debugging of D-Bus
messages when dynamic debug is enabled for main.c:

bluetoothd[3672799]: [:1.38799:method_call] > org.bluez.Device1.Connect [#761]
bluetoothd[3672799]: [:1.38799:error] < org.bluez.Error.Failed [#761]

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agogdbus: Add g_dbus_set_debug
Luiz Augusto von Dentz [Tue, 29 Oct 2024 21:26:17 +0000 (17:26 -0400)]
gdbus: Add g_dbus_set_debug

This adds g_dbus_set_debug which can be used to set a debug function to
be invoked on incoming/outgoing message.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoorg.bluez.MediaTransport: Document policy for setting transport delay
Arkadiusz Bokowy [Tue, 29 Oct 2024 20:41:32 +0000 (21:41 +0100)]
org.bluez.MediaTransport: Document policy for setting transport delay

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Allow to set A2DP transport delay property
Arkadiusz Bokowy [Tue, 29 Oct 2024 20:41:31 +0000 (21:41 +0100)]
transport: Allow to set A2DP transport delay property

In order to properly synchronize audio/video playback it is required
to report audio delay to the A2DP source. This commit allows connected
media application to update the Delay property of the A2DP transport
which will inform remote source about the playback delay.

In case when the transport is not acquired, everyone is allowed to set
the delay. However, when the transport is acquired only the owner can
modify the delay. This restriction is here to prevent interference
caused by 3rd party actors.

The functionality was tested by streaming audio between two hosts
running BlueZ Bluetooth stack.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agogdbus: Add g_dbus_pending_property_get_sender
Arkadiusz Bokowy [Tue, 29 Oct 2024 20:41:30 +0000 (21:41 +0100)]
gdbus: Add g_dbus_pending_property_get_sender

This function allows to retrieve D-Bus message sender name in a property
setter callback. Message sender name might be required to limit write
access to authorized clients only.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodevice: Fix Device.Pair using wrong address type
Cheng Jiang [Tue, 29 Oct 2024 07:58:30 +0000 (15:58 +0800)]
device: Fix Device.Pair using wrong address type

For a BLE-only device, if the device is already paired and the upper
layer attempts to pair it again, the bdaddr_type will be set to
BDADDR_BREDR since the LE connection is already bonded. This causes the
device to use the BR/EDR bearer, which stalls the pairing procedure and
requires waiting for the pairing timeout.

The bluetoothctl log below shows the error result:

[bluetooth]# pair ED:8E:0E:B3:85:C1
Attempting to pair with ED:8E:0E:B3:85:C1
Pairing successful
[RAPOO BleMouse]# disconnect ED:8E:0E:B3:85:C1
Attempting to disconnect from ED:8E:0E:B3:85:C1
[RAPOO BleMouse]#
[bluetooth]# devices Paired
Device ED:8E:0E:B3:85:C1 RAPOO BleMouse
[bluetooth]# scan le
SetDiscoveryFilter success
Discovery started
[CHG] Controller 8C:FD:F0:21:84:17 Discovering: yes
[CHG] Device ED:8E:0E:B3:85:C1 RSSI: -38
[bluetooth]# scan off
Discovery stopped
[bluetooth]# pair ED:8E:0E:B3:85:C1
Attempting to pair with ED:8E:0E:B3:85:C1
[bluetooth]#
Failed to pair: org.freedesktop.DBus.Error.NoReply

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agosource: clean up outstanding AVDTP requests if the stream goes away
Daniel Beer [Fri, 25 Oct 2024 20:21:41 +0000 (09:21 +1300)]
source: clean up outstanding AVDTP requests if the stream goes away

If the stream goes IDLE while we have an outstanding request, connect_id
stays non-zero and is never cleared via a completion callback. As a
consequence, the profile on this device will never be connected
successfully again until BlueZ restarts.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agosink: clean up outstanding AVDTP requests if the stream goes away
Daniel Beer [Fri, 25 Oct 2024 20:21:40 +0000 (09:21 +1300)]
sink: clean up outstanding AVDTP requests if the stream goes away

If the stream goes IDLE while we have an outstanding request, connect_id
stays non-zero and is never cleared via a completion callback. As a
consequence, the profile on this device will never be connected
successfully again until BlueZ restarts.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: ucast streams can only have one link
Pauli Virtanen [Sat, 26 Oct 2024 10:13:39 +0000 (13:13 +0300)]
shared/bap: ucast streams can only have one link

In unicast, linked streams mean bidirectional CIS.  Ucast stream can
have at most one linked stream.

Fix ucast streams to have only single link. This fixes eg. configuring
for AC 11(i).

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoinput: Add support for UserspaceHID=persist
Luiz Augusto von Dentz [Fri, 25 Oct 2024 19:25:33 +0000 (15:25 -0400)]
input: Add support for UserspaceHID=persist

This adds support for persist mode via input.conf:UserspaceHID but
don't default to it since this appears to create more problems than
it solves.

Fixes: https://github.com/bluez/bluez/issues/983
Fixes: https://github.com/bluez/bluez/issues/977
Fixes: https://github.com/bluez/bluez/issues/949
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/player: Fix select/unselect reply prints
Iulia Tanasescu [Fri, 25 Oct 2024 14:28:42 +0000 (17:28 +0300)]
client/player: Fix select/unselect reply prints

This updates the shell print messages for the transport select/unselect
method replies. The bluetoothctl log below shows the fixed result:

client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1
Capabilities:
  03 01 ff 00 02 02 03 05 04 1a 00 f0 00 02 03 01
Metadata:
[bluetooth]# Endpoint /local/endpoint/ep0 registered
[bluetooth]# scan on
[bluetooth]# [NEW] Device 17:7A:80:64:A7:93 17-7A-80-64-A7-93
[17-7A-80-64-A7-93]# [NEW] Transport
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# transport.select
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0 State: broadcasting
[17-7A-80-64-A7-93]# Select successful
[17-7A-80-64-A7-93]# transport.unselect
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0 State: idle
[17-7A-80-64-A7-93]# Unselect successful

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Send reply to select/unselect
Iulia Tanasescu [Fri, 25 Oct 2024 14:28:41 +0000 (17:28 +0300)]
transport: Send reply to select/unselect

When a transport is selected from bluetoothctl, a reply is expected.
Currently, if the method call is successful, no reply is sent, causing
the following error message in bluetoothctl:

transport.Failed to select: org.freedesktop.DBus.Error.NoReply

The same error can be reproduced for the unselect method.

This commit updates the select and unselect methods to send reply
messages.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Unlink broadcast transport at release
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:46 +0000 (15:21 +0300)]
transport: Unlink broadcast transport at release

This updates broadcast transport release to unlink stream from all its
links.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/player: Add support to select multiple transports
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:45 +0000 (15:21 +0300)]
client/player: Add support to select multiple transports

This updates transport select to link transports together before calling
the "Select" method for each of them.

The bluetoothctl log below shows a Broadcast Sink detecting
2 streams from a source and selecting both of them. After the
first transport is acquired, the link is created and the first
transport goes active.

client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1
Capabilities:
  03 01 ff 00 02 02 03 05 04 1a 00 f0 00 02 03 01
Metadata:
[bluetooth]# Endpoint /local/endpoint/ep0 registered
[bluetooth]# scan on
[bluetooth]# [NEW] Device 17:7A:80:64:A7:93 17-7A-80-64-A7-93
[17-7A-80-64-A7-93]# [NEW] Transport
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# [NEW] Transport
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1
[17-7A-80-64-A7-93]# transport.select
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0 State: broadcasting
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1 State: broadcasting
[17-7A-80-64-A7-93]# transport.acquire
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# [CHG] Transport
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
                Links: /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1
[17-7A-80-64-A7-93]# Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0 acquiring complete
[17-7A-80-64-A7-93]# Acquire successful: fd 8 MTU 40:0
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0 State: active

The btmon log shows that sync has been established with both BISes:

< HCI Command: LE Broadcast Isochronous Group Create Sync (0x08|0x006b)
        BIG Handle: 0x00
        BIG Sync Handle: 0x0000
        Encryption: Unencrypted (0x00)
        Broadcast Code[16]: 00000000000000000000000000000000
        Maximum Number Subevents: 0x00
        Timeout: 20000 ms (0x07d0)
        Number of BIS: 2
        BIS ID: 0x01
        BIS ID: 0x02
> HCI Event: Command Status (0x0f) plen 4
      LE Broadcast Isochronous Group Create Sync (0x08|0x006b) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 19
      LE Broadcast Isochronous Group Sync Estabilished (0x1d)
        Status: Success (0x00)
        BIG Handle: 0x00
        Transport Latency: 0 us (0x000000)
        NSE: 3
        BN: 1
        PTO: 1
        IRC: 3
        Maximum PDU: 40
        ISO Interval: 10.00 msec (0x0008)
        Connection Handle #0: 6
        Connection Handle #1: 7
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
        Handle: 6
        Data Path Direction: Output (Controller to Host) (0x01)
        Data Path: HCI (0x00)
        Coding Format: Transparent (0x03)
        Company Codec ID: Ericsson Technology Licensing (0)
        Vendor Codec ID: 0
        Controller Delay: 0 us (0x000000)
        Codec Configuration Length: 0
        Codec Configuration[0]:
> HCI Event: Command Complete (0x0e) plen 6
      LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
        Status: Success (0x00)
        Handle: 6
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
        Handle: 7
        Data Path Direction: Output (Controller to Host) (0x01)
        Data Path: HCI (0x00)
        Coding Format: Transparent (0x03)
        Company Codec ID: Ericsson Technology Licensing (0)
        Vendor Codec ID: 0
        Controller Delay: 0 us (0x000000)
        Codec Configuration Length: 0
        Codec Configuration[0]:
> HCI Event: Command Complete (0x0e) plen 6
      LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
        Status: Success (0x00)
        Handle: 7

The second transport can then be acquired and it will go straight
to active, since the fd has already been set:

[17-7A-80-64-A7-93]# transport.acquire
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1
[17-7A-80-64-A7-93]# [CHG] Transport
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1
                Links: /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1 acquiring complete
[17-7A-80-64-A7-93]# Acquire successful: fd 9 MTU 40:0
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1 State: active

The transports can them be released one by one:

[17-7A-80-64-A7-93]# transport.release
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0
[17-7A-80-64-A7-93]# Transport fd disconnected
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis1/fd0 State: idle
[17-7A-80-64-A7-93]# Release successful
[17-7A-80-64-A7-93]# transport.release
                /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1
[17-7A-80-64-A7-93]# Transport fd disconnected
[17-7A-80-64-A7-93]# [CHG] Transport
    /org/bluez/hci0/dev_17_7A_80_64_A7_93/bis2/fd1 State: idle
[17-7A-80-64-A7-93]# Release successful

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/player: Handle acquiring broadcast links
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:44 +0000 (15:21 +0300)]
client/player: Handle acquiring broadcast links

This adds support for acquiring linked broadacast transports: Each link
should be acquired separately, unlike unicast.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Make transport_bap_set_state part of BAP_OPS
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:43 +0000 (15:21 +0300)]
transport: Make transport_bap_set_state part of BAP_OPS

This splits the transport set_state operation for unicast and broadcast,
by implementing it as a transport op. Unlike unicast, broadcast transports
need to be acquired/released separately, so changes in a transport state
should not affect its links.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Set bap_update_links as transport op
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:42 +0000 (15:21 +0300)]
transport: Set bap_update_links as transport op

This implements bap_update_links as transport op, since broadcast links
need to be handled differently for unicast, which only allows one link.
For broadcast, the property changed signal should be emitted everytime
a new link is added or removed.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodoc/media: Document Links property for broadcast
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:41 +0000 (15:21 +0300)]
doc/media: Document Links property for broadcast

This adds the "Links" property for broadcast.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Add Links property for broadcast transports
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:40 +0000 (15:21 +0300)]
transport: Add Links property for broadcast transports

This adds the "Links" property for broadcast transports, which allows
upper layer applications to write and link transports together.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Unset transport owner before owner free
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:39 +0000 (15:21 +0300)]
transport: Unset transport owner before owner free

This sets the transport owner back to NULL, before the owner object
is freed.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Handle multiple bcast sink streams
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:38 +0000 (15:21 +0300)]
shared/bap: Handle multiple bcast sink streams

This adds shared/bap support for enabling and starting multiple Broadcast
Sink streams. Stream enabling should fail if any other Broadcast Sink
streams are in the process of enabling or have been enabled for the same
source. Also, a stream that has been enabled and already has the fd set
should be started on the spot.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobap: Add support for syncing to multiple BISes
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:37 +0000 (15:21 +0300)]
bap: Add support for syncing to multiple BISes

This adds support for a Broadcast Sink to synchronize to multiple BISes
from a Source.

BISes selected by the user need to be linked together and then enabled one
by one. The first enabled stream will enqueue all its links in a request
for PA and BIG sync. After BIG sync is established, the confirm callback
will be called for each BIS io created in the kernel. Each fd will be set
inside the corresponding link, even the links that have not yet been
enabled. The enabled links will be started as soon as the fds are ready.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Use enabling state for bcast sink streams
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:36 +0000 (15:21 +0300)]
shared/bap: Use enabling state for bcast sink streams

This updates the stream state transition from CONFIG to ENABLING,
on enable for Broadcast Sink streams. This is done to differentiate
between streams discovered in the BASE after short-lived PA sync
and streams that have been selected and enabled by the user.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Fix broadcast set state
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:35 +0000 (15:21 +0300)]
shared/bap: Fix broadcast set state

When a stream changes state, the update is notified to other drivers
that registered a state changed callback. These callbacks might further
change the stream state, leading to the stream being freed. To avoid
use after free errors post notifications, this commit adds support to
ref/unref streams, to make sure that the stream is kept alive until all
processing is completed. This also updates the switch condition post
notifications, to handle the stream based on its current state.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Add support for handling broadcast links
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:34 +0000 (15:21 +0300)]
shared/bap: Add support for handling broadcast links

This commit implements io handling functions as stream ops, since
broadcast links need to be handled differently than unicast:
Unicast links share the same IO, while broadcast links stand for
separate BISes with independent IOs. Unicast links have different
directions, while broadcast links share the same one.

This also adds a function for unlinking broadcast streams.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Allow multiple links per stream
Iulia Tanasescu [Fri, 25 Oct 2024 12:21:33 +0000 (15:21 +0300)]
shared/bap: Allow multiple links per stream

This commit adds support to link multiple streams together, creating
the foundation for implementing broadcast links: for Broadcast Sinks,
the user could select multiple streams to receive audio from. All
selected streams need to be linked together and considered when
creating BIG sync.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/shell: Fix not displaying first prompt
Luiz Augusto von Dentz [Thu, 24 Oct 2024 15:48:05 +0000 (11:48 -0400)]
shared/shell: Fix not displaying first prompt

Sometimes the prompt is not display when it is just set once (e.g.
bluetoothctl when bluetoothd is not running).

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobex: Resolve SRM issue for PTS testcases
Amisha Jain [Wed, 23 Oct 2024 07:14:48 +0000 (12:44 +0530)]
obex: Resolve SRM issue for PTS testcases

Add check for unknown/undefined srm value.

This fix is required to pass the below the PTS testcases :
1. OPP/SR/GOEP/SRM/BI-02-C
2. FTP/SR/GOEP/SRM/BI-02-C
3. PBAP/PSE/GOEP/SRM/BI-05-C

Description - Verify that the Server ignores a SRM header with an
invalid value in the PUT/GET request and carries on with the
PUT/GET operation with SRM disabled.

Current Behaviour - Server is sending SRM enable in the response even
though receiving the unknown SRM value.

To fix this, I have added the check to verify the valid SRM values
before continuing with SRM enable.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Fix crash on bt_bap_stream_disable
Luiz Augusto von Dentz [Wed, 23 Oct 2024 14:00:42 +0000 (10:00 -0400)]
shared/bap: Fix crash on bt_bap_stream_disable

Calls to bt_bap_stream_disable with unicast stream shall result in
stream_disable if when acting as a server (!stream->client) otherwise it
may lead to the following trace:

bluetoothd[104990]: src/shared/bap.c:bap_queue_req() req 0x555555732470 (op 0x05) queue 0x55555571e850
bluetoothd[104990]: src/gatt-database.c:send_notification_to_device() GATT server sending notification
bluetoothd[104990]: src/shared/bap.c:stream_notify_state() stream 0x55555571b7f0
bluetoothd[104990]: src/shared/bap.c:stream_notify_qos() stream 0x55555571b7f0
bluetoothd[104990]: src/gatt-database.c:send_notification_to_device() GATT server sending notification
bluetoothd[104990]: src/shared/bap.c:bap_process_queue()
bluetoothd[104990]: src/shared/bap.c:bap_send() req 0x555555732470 len 3

Program received signal SIGSEGV, Segmentation fault.
bap_send (bap=bap@entry=0x555555730c50, req=req@entry=0x555555732470) at src/shared/bap.c:1490

Fixes: https://github.com/bluez/bluez/issues/991
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobuild: Fix make distcheck
Luiz Augusto von Dentz [Mon, 21 Oct 2024 20:30:48 +0000 (16:30 -0400)]
build: Fix make distcheck

This fixes the following error:

make[2]: *** No rule to make target 'doct/hci.7', needed by 'distdir-am'.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoaudio/avrcp: Only allow absolute volume call/event on category-2 peers
Marijn Suijten [Sat, 5 Oct 2024 21:43:07 +0000 (23:43 +0200)]
audio/avrcp: Only allow absolute volume call/event on category-2 peers

Restrict the use of SetAbsoluteVolume and EVENT_VOLUME_CHANGED to peers
with at least AVRCP version 1.4 and AVRCP_FEATURE_CATEGORY_2 on their
respective target or controller profiles.

For backwards-compatibility, add a (default-enabled) `VolumeCategory =
true` configuration option under `[AVRCP]` to allow optionally disabling
this new check.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoaudio/avrcp: Guard SetAbsoluteVolume without target behind config value
Marijn Suijten [Sat, 5 Oct 2024 21:43:06 +0000 (23:43 +0200)]
audio/avrcp: Guard SetAbsoluteVolume without target behind config value

Commit 179ccb936 ("avrcp: Set volume if volume changed event is
registered") invented a workaround that allows SetAbsoluteVolume to be
sent to a remote device that does _not_ implement the AVRCP TG profile,
as long as it previously registered for the EVENT_VOLUME_CHANGED
notification.  This is strange as the TG role is required to be able to
send commands to the peer, but the commit must have been applied to the
tree for a reason.

We discussed in [1] that workarounds for dubious peers and software
stacks should be guarded behind a config entry in main.conf, so this
starts out by introducing a new [AVRCP] category that will later be
extended with other workarounds.  It guards the changed functionality
behind a `VolumeWithoutTarget = false` boolean to disallow this obscure
check.

[1]: https://lore.kernel.org/linux-bluetooth/20211025210206.bkt5wovzmkmt6teg@SoMainline.org/

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodoc: Add initial HCI(7) documentation
Luiz Augusto von Dentz [Fri, 18 Oct 2024 19:36:55 +0000 (15:36 -0400)]
doc: Add initial HCI(7) documentation

This adds initial documentation for HCI sockets.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobex: Move size emit signal to plugins instead of obex.c
Amisha Jain [Thu, 17 Oct 2024 06:13:31 +0000 (11:43 +0530)]
obex: Move size emit signal to plugins instead of obex.c

Instead of emitting the property "Size" from obex_put_stream_start(),
Call the function manager_emit_transfer_property() from plugins/*.c
wherever plugin has transfer object present.
Remove the code from obex.c which is generic for all profiles.

This change resolves the type mismatch issue when calling the
manager_emit_transfer_property from obex.c. We are passing
'os->service_data' of plugin session type but the
manager_emit_transfer_property() expects the 'obex_transfer'
type, therefore size is not set properly and might cause
crash/disconnection.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotools/obexctl: Add support to connect using PSM port
Frédéric Danis [Mon, 14 Oct 2024 17:10:58 +0000 (19:10 +0200)]
tools/obexctl: Add support to connect using PSM port

Since commit 5d7d3ac25bd5 ("obexd: Add PSM support to session create")
obexd supports to connect the session using a L2CAP PSM.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/shell: Fix not handling prompt with color properly
Luiz Augusto von Dentz [Tue, 15 Oct 2024 20:40:58 +0000 (16:40 -0400)]
shared/shell: Fix not handling prompt with color properly

Colors use escape sequence that needs to be enveloped with
RL_PROMPT_START_IGNORE (\001) and RL_PROMPT_END_IGNORE (\002) in order
for readline to properly calculate the prompt length.

Fixes: https://github.com/bluez/bluez/issues/965
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoavdtp: Fix triggering disconnect_timeout while discovering capabilities
Luiz Augusto von Dentz [Tue, 15 Oct 2024 19:36:22 +0000 (15:36 -0400)]
avdtp: Fix triggering disconnect_timeout while discovering capabilities

If there are many endpoint registered it may delay the discovering of
the capabilities long enough to trigger diconnect_timeout which may
cause unexpected collisions/disconnections.

Fixes: https://github.com/bluez/bluez/issues/981
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Delay existence based on delay reporting capability
Arkadiusz Bokowy [Tue, 8 Oct 2024 20:09:26 +0000 (22:09 +0200)]
transport: Delay existence based on delay reporting capability

In case when the existence of the delay property is based on its value
not being zero it is not possible to read the delay if sink sets it to
zero on purpose (or it was not updated by the sink at all). However,
client might expect it to be readable, if SEP reports delay reporting
as available.

Instead of checking the value, we should check the capabilities of
the AVDTP stream. Also, by doing that we can allow this property to
be writable in the future - the exists() callback is used in the
properties_set() function as well.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient: Update scripts to include encrypted stream scenario
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:26 +0000 (11:01 +0300)]
client: Update scripts to include encrypted stream scenario

This updates the broadcast-assistant/scan-delegator scripts to include
the encrypted stream scenario.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Add support to request bcode from Assistant
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:25 +0000 (11:01 +0300)]
transport: Add support to request bcode from Assistant

A Broadcast Sink might scan an encrypted stream, but the user might
not know the Broadacst Code to decrypt it. However, if the Broadcast
Sink is acting as a Scan Delegator, it can request the Code from
Broadcast Assistants.

This adds support to ask for the Broadcast Code through BASS, if an
empty Code was entered by the user at transport select.

The bluetoothctl log below shows a Scan Delegator creating a media
transport for an encrypted BIS added by a Broadcast Assistant through
the Add Source operation. The user is asked to enter the Broadcast Code
at transport.select, and the "no" option is chosen, since the Code is
unknown. However, the Code is received from the Broadcast Assistant and
the transport is successfully acquired.

client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1
[bluetooth]# Endpoint /local/endpoint/ep0 registered
[bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F
[00-60-37-31-7E-3F]# [NEW] Device 23:E1:A6:85:D9:11 23-E1-A6-85-D9-11
[00-60-37-31-7E-3F]# [NEW] Transport
    /org/bluez/hci2/dev_23_E1_A6_85_D9_11/bis1/fd0
[00-60-37-31-7E-3F]# transport.select
    /org/bluez/hci2/dev_23_E1_A6_85_D9_11/bis1/fd0
[] Enter brocast code[value/no]: no
[00-60-37-31-7E-3F]# Setting broadcast code succeeded
[00-60-37-31-7E-3F]# [CHG] Transport
    /org/bluez/hci2/dev_23_E1_A6_85_D9_11/bis1/fd0 State: broadcasting
[00-60-37-31-7E-3F]# transport.acquire
    /org/bluez/hci2/dev_23_E1_A6_85_D9_11/bis1/fd0
[00-60-37-31-7E-3F]# Transport
    /org/bluez/hci2/dev_23_E1_A6_85_D9_11/bis1/fd0 acquiring complete
[00-60-37-31-7E-3F]# [CHG] Transport
    /org/bluez/hci2/dev_23_E1_A6_85_D9_11/bis1/fd0 State: active

The btmon log shows the BASS GATT write commands and notifications
exchanged between the Scan Delegator and the Broadcast Assistant:

> ACL Data RX: Handle 0 flags 0x01 dlen 1
      ATT: Write Command (0x52) len 23
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[21]: 020111d985a6e12300f9bb8502ffff010100000000
            Opcode: Add Source (0x02)
            Source_Address_Type: 1
            Source_Address: 23:E1:A6:85:D9:11
            Source_Adv_SID: 0
            Broadcast_ID: 0x85bbf9
            PA_Sync_State: Synchronize to PA - PAST not available
            PA_Interval: 0xffff
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044) plen 14
        Options: 0x0000
        Use advertising SID, Advertiser Address Type and address
        Reporting initially enabled
        SID: 0x00
        Adv address type: Random (0x01)
        Adv address: 23:E1:A6:85:D9:11 (Non-Resolvable)
        Skip: 0x0000
        Sync timeout: 20000 msec (0x07d0)
        Sync CTE type: 0x0000
> HCI Event: LE Meta Event (0x3e) plen 16
      LE Periodic Advertising Sync Established (0x0e)
        Status: Success (0x00)
        Sync handle: 0
        Advertising SID: 0x00
        Advertiser address type: Random (0x01)
        Advertiser address: 23:E1:A6:85:D9:11 (Non-Resolvable)
        Advertiser PHY: LE 2M (0x02)
        Periodic advertising interval: 10.00 msec (0x0008)
        Advertiser clock accuracy: 0x07
> HCI Event: LE Meta Event (0x3e) plen 42
      LE Periodic Advertising Report (0x0f)
        Sync handle: 0
        TX power: 127 dbm (0x7f)
        RSSI: -57 dBm (0xc7)
        CTE Type: No Constant Tone Extension (0xff)
        Data status: Complete
        Data length: 0x22
        Service Data: Basic Audio Announcement (0x1851)
          Presetation Delay: 40000
          Number of Subgroups: 1
            Subgroup #0:
            Number of BIS(s): 1
            Codec: LC3 (0x06)
            Codec Specific Configuration: #0: len 0x02 type 0x01
            Codec Specific Configuration: Sampling Frequency: 16 Khz (0x03)
            Codec Specific Configuration: #1: len 0x02 type 0x02
            Codec Specific Configuration: Frame Duration: 10 ms (0x01)
            Codec Specific Configuration: #2: len 0x03 type 0x04
            Codec Specific Configuration: Frame Length: 40 (0x0028)
            Codec Specific Configuration: #3: len 0x05 type 0x03
            Codec Specific Configuration: Location: 0x00000001
            Codec Specific Configuration: Location: Front Left (0x00000001)
              BIS #0:
              Index: 1
> HCI Event: LE Meta Event (0x3e) plen 20
      LE Broadcast Isochronous Group Info Advertising Report (0x22)
        Sync Handle: 0x0000
        Number BIS: 1
        NSE: 3
        ISO Interval: 10.00 msec (0x0008)
        BN: 1
        PTO: 1
        IRC: 3
        Maximum PDU: 40
        SDU Interval: 10000 us (0x002710)
        Maximum SDU: 40
        PHY: LE 2M (0x02)
        Framing: Unframed (0x00)
        Encryption: 0x01
bluetoothd[5431]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 010111d985a6e12300f9bb850200010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 23:E1:A6:85:D9:11
          Source_Adv_SID: 0
          Broadcast_ID: 0x85bbf9
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Not encrypted
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
bluetoothd[5431]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 010111d985a6e12300f9bb850201010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 23:E1:A6:85:D9:11
          Source_Adv_SID: 0
          Broadcast_ID: 0x85bbf9
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Broadcast_Code required
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
> ACL Data RX: Handle 0 flags 0x02 dlen 25
      ATT: Write Command (0x52) len 20
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[18]: 040161616100000000000000000000000000
            Opcode: Set Broadcast_Code (0x04)
            Source_ID: 1
            Broadcast_Code[16]: 61616100000000000000000000000000
< HCI Command: LE Broadcast Isochronous Group Create Sync (0x08|0x006b)
        BIG Handle: 0x00
        BIG Sync Handle: 0x0000
        Encryption: Encrypted (0x01)
        Broadcast Code[16]: 61616100000000000000000000000000
        Maximum Number Subevents: 0x00
        Timeout: 20000 ms (0x07d0)
        Number of BIS: 1
        BIS ID: 0x01
> HCI Event: LE Meta Event (0x3e) plen 17
      LE Broadcast Isochronous Group Sync Estabilished (0x1d)
        Status: Success (0x00)
        BIG Handle: 0x00
        Transport Latency: 960 us (0x0003c0)
        NSE: 3
        BN: 1
        PTO: 1
        IRC: 3
        Maximum PDU: 40
        ISO Interval: 10.00 msec (0x0008)
        Connection Handle #0: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
        Handle: 10
        Data Path Direction: Output (Controller to Host) (0x01)
        Data Path: HCI (0x00)
        Coding Format: Transparent (0x03)
        Company Codec ID: Ericsson Technology Licensing (0)
        Vendor Codec ID: 0
        Controller Delay: 0 us (0x000000)
        Codec Configuration Length: 0
        Codec Configuration[0]:
> HCI Event: Command Complete (0x0e) plen 6
      LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
        Status: Success (0x00)
        Handle: 10
bluetoothd[5431]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 010111d985a6e12300f9bb850202010100000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 23:E1:A6:85:D9:11
          Source_Adv_SID: 0
          Broadcast_ID: 0x85bbf9
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Decrypting
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000001

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bass: Set correct BIG enc state after sync
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:24 +0000 (11:01 +0300)]
shared/bass: Set correct BIG enc state after sync

A Scan Delegator might set the BIG encryption state of a Broadcast
Receive State characteristic to "Broadcast Code Required", to notify
Broadcast Assistants that the value is needed to decrypt the streams.

If the Broadcast Code was received and BIG sync was established, the
BIG encryption state must be transitioned to "Decrypting" state, to
inform Assistants that BIG sync was successfully established with the
correct Code.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bass: Call cp handler for the Set Broadcast Code op
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:23 +0000 (11:01 +0300)]
shared/bass: Call cp handler for the Set Broadcast Code op

This updates the Set Broadcast Code control point handler inside
shared/bass to call the handlers queued inside bt_bass.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobass: Add support to request bcode
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:22 +0000 (11:01 +0300)]
bass: Add support to request bcode

This adds support for a Scan Delegator to request the Broadcast Code
from peer Broadcast Assistants and to update a BAP stream QoS with the
value.

A BASS API is added to update the BIG encryption status of a Broadcast
Receive State characteristic and to notify peers. When a peer provides
the Code using the BASS "Set Broadcast Code" operation, the BAP stream
QoS is updated. The driver calling this API will pass a callback as
parameter, which will be called to signal that the Broadcast Code has
been received and stored in the stream QoS.

A timeout is set to wait for Broadcast Assistants to provide the Code.
If the timeout expires, the callback will be code with the appropriate
error status.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bass: Add API to set BIG enc state
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:21 +0000 (11:01 +0300)]
shared/bass: Add API to set BIG enc state

This adds a shared/bass API to set the BIG encryption state field inside
a Broadcast Receive State characteristic. Notifications are then sent to
inform all peers about the update.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/player: Add support to set empty bcode
Iulia Tanasescu [Tue, 8 Oct 2024 08:01:20 +0000 (11:01 +0300)]
client/player: Add support to set empty bcode

A Broadcast Sink might scan encrypted streams, and the user might not
know the Broadcast Code to decrypt them.

This commit adds the option to set an empty Broadcast Code when prompted
for it after transport.select, if the Code is unknown. In this case, if
the Broadcast Sink is acting as a Scan Delegator, it can ask its peer
Broadcast Assistants to provide the Code through BASS.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoavdtp: Fix state check before sending delay report
Arkadiusz Bokowy [Sat, 5 Oct 2024 21:15:10 +0000 (23:15 +0200)]
avdtp: Fix state check before sending delay report

The function which handles the incoming delay report command was fixed
in 2fd62cd. However, the function which send such command was not
updated. This commit fixes that.

Also, indicate that the stream does not support delay reporting with an
appropriate error code.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoaudio/avrcp: Extend ListItems to get more metadata
Frédéric Danis [Fri, 4 Oct 2024 14:40:43 +0000 (16:40 +0200)]
audio/avrcp: Extend ListItems to get more metadata

This allows user applications to display the playlist with
Artist, Album, Track number, Duration and Cover art handle.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoaudio/player: Clear playlist on Now Playing Changed AVRCP event
Frédéric Danis [Fri, 4 Oct 2024 14:40:42 +0000 (16:40 +0200)]
audio/player: Clear playlist on Now Playing Changed AVRCP event

Some devices reuse the item ids for the Now Playing list on playlist
change. This commit allows to clear the list and prevent to keep the
previous tracks information.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoaudio/player: Fix media_player_set_metadata item destination
Frédéric Danis [Fri, 4 Oct 2024 14:40:41 +0000 (16:40 +0200)]
audio/player: Fix media_player_set_metadata item destination

Use item provided as parameter, or mp->track if NULL which is used
by MCP.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bap: Fix load of misaligned address error
Iulia Tanasescu [Wed, 2 Oct 2024 13:35:06 +0000 (16:35 +0300)]
shared/bap: Fix load of misaligned address error

This fixes the "load of misaligned address" error that appears when
parsing PAC caps:

src/shared/bap.c:6497:7: runtime error: load of misaligned address
0x502000063639 for type 'uint16_t', which requires 2 byte alignment

0x502000063639: note: pointer points here
 02 03 05  04 1a 00 f0 00 02 03 01  02 11 00 00 08 00 00 00  a3 00 00
              ^                        00 00 00 00 00  01 00 00 00 01

src/shared/bap.c:6498:7: runtime error: load of misaligned address
0x502000063639 for type 'uint16_t', which requires 2 byte alignment

0x502000063639: note: pointer points here
 02 03 05  04 1a 00 f0 00 02 03 01  02 11 00 00 08 00 00 00  a3 00 00
              ^                        00 00 00 00 00  01 00 00 00 01
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient: Add Broadcast Assistant/Scan Delegator scripts
Iulia Tanasescu [Wed, 2 Oct 2024 14:13:45 +0000 (17:13 +0300)]
client: Add Broadcast Assistant/Scan Delegator scripts

This adds sample bluetoothctl scripts for the Broadcast
Assistant/Scan Delegator scenarios.

A test setup can be created using these 2 scripts and the
broadcast-source.bt script: The Broadcast Assistant connects
to the Scan Delegator and sends information about a broadcast
stream.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodevice: Remove device after all bearers are disconnected
Cheng Jiang [Sun, 29 Sep 2024 02:22:56 +0000 (10:22 +0800)]
device: Remove device after all bearers are disconnected

For a dual-mode remote, both BR/EDR and BLE may be connected,
RemoveDevice should be handled after all bearers are disconnects.
Otherwise, if msg is removed, but not all connection are dropped,
this function returns before *remove is updated, then after all
connections are dropped, but device->disconnects is NULL,
remove_device is not updated. Consequently *remove is not set to
true. Remove device is not performed in adapter_remove_connection.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient: Update endpoint.show and transport.show documentation
Luiz Augusto von Dentz [Mon, 30 Sep 2024 19:40:54 +0000 (15:40 -0400)]
client: Update endpoint.show and transport.show documentation

endpoint.show and transport.show argument is optional with latest
changes.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient: Update endpoint and trasport doc
nxf92481 [Mon, 30 Sep 2024 14:58:30 +0000 (17:58 +0300)]
client: Update endpoint and trasport doc

This updates the documentation for the use of endpoints and
transports according to the latest changes in their design.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/player: Make transport.show print all transports with no argument
Luiz Augusto von Dentz [Fri, 27 Sep 2024 19:50:44 +0000 (15:50 -0400)]
client/player: Make transport.show print all transports with no argument

This makes transport.show arguments optional and in case none is given
print all configured transports:

[bluetooth]# transport.show
Transport /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/sep4/fd0
UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
Codec: 0x02 (2)
Media Codec: MPEG24
Object Types: MPEG-2 AAC LC
Frequencies: 48kHz
Channels: 2
Bitrate: 320000
VBR: Yes
Device: /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX
State: active
Delay: 0x06a4 (1700)
Volume: 0x0059 (89)
Endpoint: /org/bluez/hci0/dev_94_XX_XX_XX_XX_XX/sep4

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/player: Make endpoint.show print all endpoint with no argument
Luiz Augusto von Dentz [Fri, 27 Sep 2024 16:56:25 +0000 (12:56 -0400)]
client/player: Make endpoint.show print all endpoint with no argument

This makes endpoint.show arguments optional and in case none is given
print all (local and remote) endpoints:

[bluetooth]# endpoint.show
Endpoint /local/endpoint/a2dp_src/sbc
UUID 0000110a-0000-1000-8000-00805f9b34fb
Codec 0x00 (0)
Media Codec: SBC
Channel Modes: Mono DualChannel Stereo JointStereo
Frequencies: 16Khz 32Khz 44.1Khz 48Khz
Subbands: 4 8
Blocks: 4 8 12 16
Bitpool Range: 2-64
Endpoint /local/endpoint/a2dp_snk/sbc
UUID 0000110b-0000-1000-8000-00805f9b34fb
Codec 0x00 (0)
Media Codec: SBC
Channel Modes: Mono DualChannel Stereo JointStereo
Frequencies: 16Khz 32Khz 44.1Khz 48Khz
Subbands: 4 8
Blocks: 4 8 12 16
Bitpool Range: 2-64

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/shell: Allow script command to be used within scripts
Luiz Augusto von Dentz [Wed, 25 Sep 2024 18:22:53 +0000 (14:22 -0400)]
shared/shell: Allow script command to be used within scripts

This makes script command to allow the usage of script within the
script file by saving existing execute queue and then replacing the
line with script command with the lines of the input file.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoadapter: Cancel the service authorization when remote is disconnected
Cheng Jiang [Sun, 22 Sep 2024 03:04:17 +0000 (11:04 +0800)]
adapter: Cancel the service authorization when remote is disconnected

If the remote device drops the connection before DUT confirm the
service authorization, the DUT still must wait for service
authorization timeout before processing future request.

Cancel the service authorization request when connection is dropped.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobap: Set bap debug func at broadcast probe
Iulia Tanasescu [Thu, 19 Sep 2024 08:20:46 +0000 (11:20 +0300)]
bap: Set bap debug func at broadcast probe

When a Broadcast Sink acting as a Scan Delegator probes a Broadcaster with
the help of a Broadcast Assistant, a new BAP session is added for the
Broadcaster device before additional session information is initialized
(like the bt_bap session). This causes the bap debug func to not be set
in bap_data_add.

This commit adds an explicit call to set the function after the bt_bap
session is created.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agomesh: Move local basename into utility file
Khem Raj [Tue, 17 Sep 2024 03:17:45 +0000 (20:17 -0700)]
mesh: Move local basename into utility file

Defining an override via a missing.h can prove difficult when a file
needs to use basename and dirname both the APIs and needs to include
libgen.h for them, in such situations there will be signature clash
for basename function.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoorg.bluez.Device: Add documentation for GetServiceRecords()
Vibhav Pant [Sat, 7 Sep 2024 21:33:01 +0000 (03:03 +0530)]
org.bluez.Device: Add documentation for GetServiceRecords()

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodevice: Add method GetServiceRecords
Vibhav Pant [Sat, 7 Sep 2024 21:33:00 +0000 (03:03 +0530)]
device: Add method GetServiceRecords

GetServiceRecords returns all currently known BR/EDR service records
for the device, as an array of array of bytes. Each individual byte
array represents a raw SDP record, as defined by the Bluetooth Service
Discovery Protocol spec.
This method is intended to be only used by compatibility layers like
Wine, that need to provide access to raw SDP records to implement the
Win32 Bluetooth API. Applications should instead use the Profile API
for services-related functionality.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoFix missing inclusion of <limits.h>
Ismael Luceno [Sun, 15 Sep 2024 20:23:20 +0000 (22:23 +0200)]
Fix missing inclusion of <limits.h>

Needed for PATH_MAX.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agocontribution: add b4 config
Celeste Liu [Sat, 14 Sep 2024 14:28:53 +0000 (22:28 +0800)]
contribution: add b4 config

Add b4[1] config so b4 user can contribute more smoothly, especially
send prefix.

[1]: https://github.com/mricon/b4

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoorg.bluez.Adapter: Add documentation for the Connectable property.
Vibhav Pant [Wed, 11 Sep 2024 14:51:14 +0000 (20:21 +0530)]
org.bluez.Adapter: Add documentation for the Connectable property.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoadapter: Add support for the Connectable property.
Vibhav Pant [Wed, 11 Sep 2024 14:51:13 +0000 (20:21 +0530)]
adapter: Add support for the Connectable property.

To not break previous behavior, allow enabling the Discoverable
property even if Connectable is currently false.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/print: Add decoding for UUID properties
Luiz Augusto von Dentz [Wed, 18 Sep 2024 19:03:22 +0000 (15:03 -0400)]
client/print: Add decoding for UUID properties

This adds proper decoding for UUID properties with usage of
bt_uuidstr_to_str so it can print the 'friendly' name as bellow:

bluetoothctl# transport.show /org/bluez/hci0/dev_94_DB_56_F7_F2_88/sep4/fd0
Transport /org/bluez/hci0/dev_94_DB_56_F7_F2_88/sep4/fd0
UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
...

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodoc: Remove Pygments dependency from manpage
Luiz Augusto von Dentz [Wed, 18 Sep 2024 18:47:12 +0000 (14:47 -0400)]
doc: Remove Pygments dependency from manpage

This patch removes the Pygments dependency from l2cap/rfcomm.rst file.
When the code-block type is specified, the rst2man throws a warning
asking for Pygments package.

Fixes: https://github.com/bluez/bluez/issues/950
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agodoc: Add description of org.bluez.obex.Image
Frédéric Danis [Tue, 17 Sep 2024 07:42:17 +0000 (09:42 +0200)]
doc: Add description of org.bluez.obex.Image

This new interface allows to get the image referenced in the audio
metadata ImgHandle available in org.bluez.MediaPlayer track properties.
The image handle is only available in track info if an OBEX session is
connected to the ObexPort port provided in  org.bluez.MediaPlayer
properties.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoavrcp: Update controller SDP record with cover art support
Frédéric Danis [Tue, 17 Sep 2024 07:42:16 +0000 (09:42 +0200)]
avrcp: Update controller SDP record with cover art support

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobexd: Add Get to org.bluez.obex.Image
Frédéric Danis [Tue, 17 Sep 2024 07:42:15 +0000 (09:42 +0200)]
obexd: Add Get to org.bluez.obex.Image

Retrieves the image corresponding to the handle and the description,
as one of the descriptions retrieved by Properties, and store it in
a local file.

If the "transform" property description exists it should be set
to one of the value listed by Properties for this description.

Change-Id: I70bd6f6694d20855796074b5ae1fc91f10dcff1f
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobexd: Add Properties to org.bluez.obex.Image
Frédéric Danis [Tue, 17 Sep 2024 07:42:14 +0000 (09:42 +0200)]
obexd: Add Properties to org.bluez.obex.Image

This allows to get the different version of the image provided by
the remote device to chose the one to use with Get.

This bip-common.[ch] files are based on previous work done by
Jakub Adamek for GSoC 2011, see [1] and [2].

[1] https://www.bluez.org/gsoc-basic-image-profilebip/
[2] https://github.com/enkait/Basic-Imaging-Profile-in-obexd/blob/gsoc_final/plugins/bip_util.c

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobexd: Add BIP client for AVRCP cover art download
Frédéric Danis [Tue, 17 Sep 2024 07:42:13 +0000 (09:42 +0200)]
obexd: Add BIP client for AVRCP cover art download

The cover art image handle is available in the metadata of the track
when the OBEX BIP session is connected to the PSM port provided
in AVRCP SDP record and available as org.bluez.MediaPlayer property.

This service allows to get the thumbnail.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient: Respect --timeout when bluetoothd isn't running
Bastien Nocera [Thu, 12 Sep 2024 09:20:11 +0000 (11:20 +0200)]
client: Respect --timeout when bluetoothd isn't running

Exit after <timeout> seconds if bluetoothd isn't available. This
functionality is useful for non-interactive uses of bluetoothctl.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/shell: Add bt_shell_get_timeout()
Bastien Nocera [Thu, 12 Sep 2024 09:20:10 +0000 (11:20 +0200)]
shared/shell: Add bt_shell_get_timeout()

Make it possible to get the value of the general --timeout option.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agomonitor: fix buffer overflow when terminal width > 255
Celeste Liu [Tue, 17 Sep 2024 06:30:46 +0000 (14:30 +0800)]
monitor: fix buffer overflow when terminal width > 255

In current code, we create line buffer with size 256, which can contains
255 ASCII characters. But in modern system, terminal can have larger
width. It may cause buffer overflow in snprintf() text.

limits.h provides constant LINE_MAX.

    {LINE_MAX}
        Unless otherwise noted, the maximum length, in bytes, of a
        utility's input line (either standard input or another
        file), when the utility is described as processing text
        files. The length includes room for the trailing <newline>.
        Minimum Acceptable Value: {_POSIX2_LINE_MAX}

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotest-uhid: Add call to bt_uhid_unregister_all
Luiz Augusto von Dentz [Mon, 16 Sep 2024 20:21:17 +0000 (16:21 -0400)]
test-uhid: Add call to bt_uhid_unregister_all

This adds a call to bt_uhid_unregister_all so it tests if notification
callback end up calling that.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/uhid: Fix crash after bt_uhid_unregister_all
Luiz Augusto von Dentz [Mon, 16 Sep 2024 20:00:31 +0000 (16:00 -0400)]
shared/uhid: Fix crash after bt_uhid_unregister_all

This fixes the following crash which happens when
bt_uhid_unregister_all is called from a notification callback:

Invalid read of size 8
   at 0x1D9EFF: queue_foreach (queue.c:206)
   by 0x1DEE58: uhid_read_handler (uhid.c:164)
 Address 0x51286d8 is 8 bytes inside a block of size 16 free'd
   at 0x48478EF: free (vg_replace_malloc.c:989)
   by 0x1DA08D: queue_remove_if (queue.c:292)
   by 0x1DA12F: queue_remove_all (queue.c:321)
   by 0x1DE592: bt_uhid_unregister_all (uhid.c:300)

Fixes: https://github.com/bluez/bluez/issues/952
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobexd: Add support for specific headers in obex transfer
Frédéric Danis [Mon, 16 Sep 2024 13:28:08 +0000 (15:28 +0200)]
obexd: Add support for specific headers in obex transfer

The BIP is using the Image Handle Tag header to set the file handle
to transfer.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoplayer: Add image handle support property
Frédéric Danis [Mon, 16 Sep 2024 13:28:07 +0000 (15:28 +0200)]
player: Add image handle support property

This is part of the metadata when the AVRCP target supports covert
art download and a OBEX BIP session is connected.
The image handle references the cover art associated to the track,
and is valid only during OBEX BIP session.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoplayer: Add OBEX PSM port for cover art support
Frédéric Danis [Mon, 16 Sep 2024 13:28:06 +0000 (15:28 +0200)]
player: Add OBEX PSM port for cover art support

This parse the AVRCP Target SDP record for the L2CAP PSM to use with
the OBEX session to get the cover art.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoobexd: Add PSM support to session create
Frédéric Danis [Mon, 16 Sep 2024 13:28:05 +0000 (15:28 +0200)]
obexd: Add PSM support to session create

An OBEX session can be connected to a RFCOMM channel or a L2CAP PSM.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient: Print a warning when setting discoverable without a timeout
Luiz Augusto von Dentz [Thu, 12 Sep 2024 20:40:22 +0000 (16:40 -0400)]
client: Print a warning when setting discoverable without a timeout

This makes command discoverable to print a warning if
discoverable-timeout is not set(0):

[bluetooth]# discoverable-timeout 0
[bluetooth]# Changing discoverable-timeout 0 succeeded
[bluetooth]# [CHG] Controller 4C:49:6C:44:F5:E7 DiscoverableTimeout: 0x00000000 (0)
[bluetooth]# discoverable on
Warning: setting discoverable while discoverable-timeout not set(0) is not recommended

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobuild: Fix distcheck
Luiz Augusto von Dentz [Wed, 11 Sep 2024 17:19:54 +0000 (13:19 -0400)]
build: Fix distcheck

This fixes the following errors like the following:

../../mesh/mesh-config-json.c:31:10: fatal error: mesh/missing.h: No such file or directory
   31 | #include "mesh/missing.h"
      |          ^~~~~~~~~~~~~~~~

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agogobex: Replace g_convert by utf16_to_utf8
Frédéric Danis [Tue, 10 Sep 2024 15:44:50 +0000 (17:44 +0200)]
gobex: Replace g_convert by utf16_to_utf8

The glibc's iconv implementation is based around plug in modules
for specific translations which may not been built on the platform
and prevent to use g_convert().
This commit replaces it by a function similar to the existing
utf8_to_utf16() function.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agomesh: Provide GNU basename compatible implementation
Khem Raj [Wed, 28 Aug 2024 06:09:26 +0000 (23:09 -0700)]
mesh: Provide GNU basename compatible implementation

Call to basename() relies on a GNU extension
to take a const char * vs a char *. Let's define
a trivial helper function to ensure compatibility
with musl.

Fixes: https://github.com/bluez/bluez/issues/843
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agotransport: Fix broadcast sink check
Vlad Pruteanu [Thu, 5 Sep 2024 14:13:40 +0000 (17:13 +0300)]
transport: Fix broadcast sink check

In transport_update_playing a check is performed to guard the path
which contains the TRANSPORT_STATE_BROADCASTING state. This branch
should be taken only when the device on which the code runs is a
broadcast sink. Thus, the UUID check is wrong, and this patch
updates it appropriately.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobluetoothctl-assistant.1: Update push command example
Iulia Tanasescu [Thu, 29 Aug 2024 13:25:07 +0000 (16:25 +0300)]
bluetoothctl-assistant.1: Update push command example

This updates the push command example to enter the Broadcast Code,
since it should be entered as a string instead of a byte array.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoclient/assistant: Enter Broadcast Code as string
Iulia Tanasescu [Thu, 29 Aug 2024 13:25:06 +0000 (16:25 +0300)]
client/assistant: Enter Broadcast Code as string

Currently, the user sets the Broadcast Code as an array of bytes
when prompted from the assistant submenu. However, the Bluetooth
Core Specification requires that, on the UI level, the Broadcast
Code shall be represented as a string (Vol 3, Part C, 3.2.6).

This commit makes the Broadcast Code be parsed as a string from
the assistant prompt. The bluetoothctl log below shows a Broadcast
Assistant pushing an encrypted stream to a peer:

client/bluetoothctl
[bluetooth]# [CHG] Controller 00:60:37:31:7E:3F Pairable: yes
[bluetooth]# AdvertisementMonitor path registered
[bluetooth]# scan on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F
[bluetooth]# connect 00:60:37:31:7E:3F
Attempting to connect to 00:60:37:31:7E:3F
[CHG] Device 00:60:37:31:7E:3F Connected: yes
[00-60-37-31-7E-3F]# Connection successful
[00-60-37-31-7E-3F]# [NEW] Device 19:9A:7A:71:E5:8B 19-9A-7A-71-E5-8B
[00-60-37-31-7E-3F]# [NEW] Assistant
    /org/bluez/hci0/src_19_9A_7A_71_E5_8B/dev_00_60_37_31_7E_3F/bis1
[00-60-37-31-7E-3F]# assistant.push
    /org/bluez/hci0/src_19_9A_7A_71_E5_8B/dev_00_60_37_31_7E_3F/bis1
[Assistant] Enter Metadata (auto/value): a
[Assistant] Enter Broadcast Code (auto/value): Borne House
[00-60-37-31-7E-3F]# [CHG] Assistant
    /org/bluez/hci0/src_19_9A_7A_71_E5_8B/dev_00_60_37_31_7E_3F/bis1
    State: pending
[00-60-37-31-7E-3F]# Assistant
    /org/bluez/hci0/src_19_9A_7A_71_E5_8B/dev_00_60_37_31_7E_3F/bis1
    pushed
[00-60-37-31-7E-3F]# [CHG] Assistant
    /org/bluez/hci0/src_19_9A_7A_71_E5_8B/dev_00_60_37_31_7E_3F/bis1
    State: requesting
[00-60-37-31-7E-3F]# [CHG] Assistant
    /org/bluez/hci0/src_19_9A_7A_71_E5_8B/dev_00_60_37_31_7E_3F/bis1
    State: active

The btmon log below shows the way the Broadcast Code string is converted
into a byte array and sent to the peer via GATT:

bluetoothd[6013]: < ACL Data TX: Handle 0 flags 0x00 dlen 28
      ATT: Write Command (0x52) len 23
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[21]: 02018be5717a9a1900db5e3a02ffff010100000000
            Opcode: Add Source (0x02)
            Source_Address_Type: 1
            Source_Address: 19:9A:7A:71:E5:8B
            Source_Adv_SID: 0
            Broadcast_ID: 0x3a5edb
            PA_Sync_State: Synchronize to PA - PAST not available
            PA_Interval: 0xffff
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000001
> ACL Data RX: Handle 0 flags 0x01 dlen 2
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 01018be5717a9a1900db5e3a0201010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 19:9A:7A:71:E5:8B
          Source_Adv_SID: 0
          Broadcast_ID: 0x3a5edb
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Broadcast_Code required
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
bluetoothd[6013]: < ACL Data TX: Handle 0 flags 0x00 dlen 25
      ATT: Write Command (0x52) len 20
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[18]: 040142c3b8726e6520486f75736500000000
            Opcode: Set Broadcast_Code (0x04)
            Source_ID: 1
            Broadcast_Code[16]: 426f726e6520486f7573650000000000
> ACL Data RX: Handle 0 flags 0x01 dlen 2
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 01018be5717a9a1900db5e3a0202010100000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 19:9A:7A:71:E5:8B
          Source_Adv_SID: 0
          Broadcast_ID: 0x3a5edb
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Decrypting
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000001

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobap: Create streams for required BISes
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:18 +0000 (15:49 +0300)]
bap: Create streams for required BISes

If a BAP Broadcast Sink is acting as a Scan Delegator and it has performed
long-lived PA sync with a Broadcaster added by a Broadcast Assistant, the
BASE should be parsed and streams need to be created only for BISes
requested by the Assistant.

This adds a BASS check inside parse_base, to filter out BISes that do not
require streams.

The bluetoothctl log below shows a Scan Delegator registering a Broadcast
Sink PAC and connecting to a Broadcast Assistant:

client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 3
[/local/endpoint/ep0] Supported Context (value): 1
[bluetooth]# Endpoint /local/endpoint/ep0 registered
[bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F

The btmon log shows the Scan Delegator receiving the Add Source command
from a Broadcast Assistant, requesting to sync to BIS index 2 of the
provided Broadcaster. After PA sync, the BASE shows that the Broadcaster
is streaming 2 BISes, both matching the audio capabilities supported by
the Scan Delegator:

> ACL Data RX: Handle 0 flags 0x01 dlen 1
      ATT: Write Command (0x52) len 23
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[21]: 02014605638ad50e004dda9b02ffff010200000000
            Opcode: Add Source (0x02)
            Source_Address_Type: 1
            Source_Address: 0E:D5:8A:63:05:46
            Source_Adv_SID: 0
            Broadcast_ID: 0x9bda4d
            PA_Sync_State: Synchronize to PA - PAST not available
            PA_Interval: 0xffff
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000002
> HCI Event: LE Meta Event (0x3e) plen 50
      LE Periodic Advertising Report (0x0f)
        Sync handle: 0
        TX power: 127 dbm (0x7f)
        RSSI: -60 dBm (0xc4)
        CTE Type: No Constant Tone Extension (0xff)
        Data status: Complete
        Data length: 0x2a
        Service Data: Basic Audio Announcement (0x1851)
          Presetation Delay: 40000
          Number of Subgroups: 1
            Subgroup #0:
            Number of BIS(s): 2
            Codec: LC3 (0x06)
            Codec Specific Configuration: #0: len 0x02 type 0x01
            Codec Specific Configuration: Sampling Frequency: 16 Khz
                                          (0x03)
            Codec Specific Configuration: #1: len 0x02 type 0x02
            Codec Specific Configuration: Frame Duration: 10 ms (0x01)
            Codec Specific Configuration: #2: len 0x03 type 0x04
            Codec Specific Configuration: Frame Length: 40 (0x0028)
            Codec Specific Configuration: #3: len 0x05 type 0x03
            Codec Specific Configuration: Location: 0x00000001
            Codec Specific Configuration: Location: Front Left
                                          (0x00000001)
              BIS #0:
              Index: 1
              BIS #1:
              Index: 2
              Codec Specific Configuration: #0: len 0x05 type 0x03
              Codec Specific Configuration: Location: 0x00000002
              Codec Specific Configuration: Location: Front Right
                                            (0x00000002)

Only one transport will be created, for BIS index 2, since it was
the only one requested in the Add Source command:

[00-60-37-31-7E-3F]# [NEW] Device 0E:D5:8A:63:05:46 0E-D5-8A-63-05-46
[00-60-37-31-7E-3F]# [NEW] Transport
    /org/bluez/hci0/dev_0E_D5_8A_63_05_46/bis2/fd0

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobass: Add API to check BIS required for sync
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:17 +0000 (15:49 +0300)]
bass: Add API to check BIS required for sync

This adds a wrapper over bt_bass_check_bis, which receives a Broadcaster
device and a BIS index and checks is the Delegator has been instructed
to sync with the specific BIS transmitted by the Source.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bass: Add API to check BIS required for sync
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:16 +0000 (15:49 +0300)]
shared/bass: Add API to check BIS required for sync

This adds a shared/bass API to check if a BIS index of a Broadcast Source
has been requested by the Broadcast Assistant to be synced with. This will
be used by BAP after parsing the BASE, to filter out the streams that don't
need to be created.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobass: Register BAP state changed cb
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:15 +0000 (15:49 +0300)]
bass: Register BAP state changed cb

This registers a BAP stream state changed callback inside BASS, to monitor
the state of BAP streams created by the Scan Delegator and to notify
the peer Broadcast Assistants about updates.

The bluetoothctl log below shows a Scan Delegator creating a media
transport for a BIS added by a Broadcast Assistant through the
Add Source operation. The transport is then acquired and then
released:

client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1
[bluetooth]# Endpoint /local/endpoint/ep0 registered
[bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F
[00-60-37-31-7E-3F]# [NEW] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA
[00-60-37-31-7E-3F]# [NEW] Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Endpoint: SetConfiguration
[00-60-37-31-7E-3F]# Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Properties.Device:
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA
[00-60-37-31-7E-3F]# Auto Accepting...
[00-60-37-31-7E-3F]# transport.select
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# [CHG] Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: broadcasting
[00-60-37-31-7E-3F]# transport.acquire
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
auto acquiring...
Transport /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 acquiring
[00-60-37-31-7E-3F]# Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 acquiring complete
[00-60-37-31-7E-3F]# Acquire successful: fd 8 MTU 40:0
[00-60-37-31-7E-3F]# [CHG] Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: active
[00-60-37-31-7E-3F]# transport.release
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Transport fd disconnected
[00-60-37-31-7E-3F]# [CHG] Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: idle
[00-60-37-31-7E-3F]# Release successful

The btmon log below shows the Scan Delegator notifying the
peer each time the state of the stream changes:

> ACL Data RX: Handle 0 flags 0x01 dlen 1
      ATT: Write Command (0x52) len 23
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[21]: 0201da5711c0e203001a2d5602ffff010100000000
            Opcode: Add Source (0x02)
            Source_Address_Type: 1
            Source_Address: 03:E2:C0:11:57:DA
            Source_Adv_SID: 0
            Broadcast_ID: 0x562d1a
            PA_Sync_State: Synchronize to PA - PAST not available
            PA_Interval: 0xffff
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044)
        Options: 0x0000
        Use advertising SID, Advertiser Address Type and address
        Reporting initially enabled
        SID: 0x00
        Adv address type: Random (0x01)
        Adv address: 03:E2:C0:11:57:DA (Non-Resolvable)
        Skip: 0x0000
        Sync timeout: 20000 msec (0x07d0)
        Sync CTE type: 0x0000
> HCI Event: Command Status (0x0f) plen 4
      LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 16
      LE Periodic Advertising Sync Established (0x0e)
        Status: Success (0x00)
        Sync handle: 0
        Advertising SID: 0x00
        Advertiser address type: Random (0x01)
        Advertiser address: 03:E2:C0:11:57:DA (Non-Resolvable)
        Advertiser PHY: LE 2M (0x02)
        Periodic advertising interval: 10.00 msec (0x0008)
        Advertiser clock accuracy: 0x07
> HCI Event: LE Meta Event (0x3e) plen 42
      LE Periodic Advertising Report (0x0f)
        Sync handle: 0
        TX power: 127 dbm (0x7f)
        RSSI: -64 dBm (0xc0)
        CTE Type: No Constant Tone Extension (0xff)
        Data status: Complete
        Data length: 0x22
        Service Data: Basic Audio Announcement (0x1851)
          Presetation Delay: 40000
          Number of Subgroups: 1
            Subgroup #0:
            Number of BIS(s): 1
            Codec: LC3 (0x06)
            Codec Specific Configuration: #0: len 0x02 type 0x01
            Codec Specific Configuration: Sampling Frequency: 16 Khz
            Codec Specific Configuration: #1: len 0x02 type 0x02
            Codec Specific Configuration: Frame Duration: 10 ms (0x01)
            Codec Specific Configuration: #2: len 0x03 type 0x04
            Codec Specific Configuration: Frame Length: 40 (0x0028)
            Codec Specific Configuration: #3: len 0x05 type 0x03
            Codec Specific Configuration: Location: 0x00000001
            Codec Specific Configuration: Location: Front Left
              BIS #0:
              Index: 1
> HCI Event: LE Meta Event (0x3e) plen 20
      LE Broadcast Isochronous Group Info Advertising Report (0x22)
        Sync Handle: 0x0000
        Number BIS: 1
        NSE: 3
        ISO Interval: 10.00 msec (0x0008)
        BN: 1
        PTO: 1
        IRC: 3
        Maximum PDU: 40
        SDU Interval: 10000 us (0x002710)
        Maximum SDU: 40
        PHY: LE 2M (0x02)
        Framing: Unframed (0x00)
        Encryption: 0x00
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 0101da5711c0e203001a2d560200010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 03:E2:C0:11:57:DA
          Source_Adv_SID: 0
          Broadcast_ID: 0x562d1a
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Not encrypted
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
< HCI Command: LE Broadcast Isochronous Group Create Sync (0x08|0x006b)
        BIG Handle: 0x00
        BIG Sync Handle: 0x0000
        Encryption: Unencrypted (0x00)
        Broadcast Code[16]: 00000000000000000000000000000000
        Maximum Number Subevents: 0x00
        Timeout: 20000 ms (0x07d0)
        Number of BIS: 1
        BIS ID: 0x01
> HCI Event: Command Status (0x0f) plen 4
      LE Broadcast Isochronous Group Create Sync (0x08|0x006b) ncmd 1
        Status: Success (0x00
> HCI Event: LE Meta Event (0x3e) plen 17
      LE Broadcast Isochronous Group Sync Estabilished (0x1d)
        Status: Success (0x00)
        BIG Handle: 0x00
        Transport Latency: 912 us (0x000390)
        NSE: 3
        BN: 1
        PTO: 1
        IRC: 3
        Maximum PDU: 40
        ISO Interval: 10.00 msec (0x0008)
        Connection Handle #0: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
        Handle: 10
        Data Path Direction: Output (Controller to Host) (0x01)
        Data Path: HCI (0x00)
        Coding Format: Transparent (0x03)
        Company Codec ID: Ericsson Technology Licensing (0)
        Vendor Codec ID: 0
        Controller Delay: 0 us (0x000000)
        Codec Configuration Length: 0
        Codec Configuration[0]:
> HCI Event: Command Complete (0x0e) plen 6
      LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
        Status: Success (0x00)
        Handle: 10
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 0101da5711c0e203001a2d560200010100000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 03:E2:C0:11:57:DA
          Source_Adv_SID: 0
          Broadcast_ID: 0x562d1a
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Not encrypted
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000001
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 0101da5711c0e203001a2d560200010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 03:E2:C0:11:57:DA
          Source_Adv_SID: 0
          Broadcast_ID: 0x562d1a
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Not encrypted
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
< HCI Command: LE Broadcast Isochronous Group Terminate Sync (0x08|0x006c)
        BIG Handle: 0x00
> HCI Event: Command Complete (0x0e) plen 5
      LE Broadcast Isochronous Group Terminate Sync (0x08|0x006c) ncmd 1
        Status: Success (0x00)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agoshared/bass: Add APIs to set/clear BIS sync bits
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:14 +0000 (15:49 +0300)]
shared/bass: Add APIs to set/clear BIS sync bits

This adds shared/bass APIs to set/clear bits inside the BIS sync bitmask
of Broadcast Receive State characteristics. Notifications are sent to the
peers each time the characteristic is updated.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobap: Probe Broadcasters with BASS
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:13 +0000 (15:49 +0300)]
bap: Probe Broadcasters with BASS

After long-lived PA sync, this adds a call to probe the bap session
with the Broadcaster with BASS.

This also adds a call to notify BASS about a session with a Broadcaster
being removed, in bap_bcast_remove.

The bluetoothctl log below shows a Scan Delegator creating a media
transport for a BIS added by a Broadcast Assistant through the
Add Source command, and then disconnecting from the Broadcaster:

client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[/local/endpoint/ep0] Auto Accept (yes/no): y
[/local/endpoint/ep0] Max Transports (auto/value): a
[/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1
[bluetooth]# Endpoint /local/endpoint/ep0 registered
[bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F
[00-60-37-31-7E-3F]# [NEW] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA
[00-60-37-31-7E-3F]# [NEW] Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# disconnect 03:E2:C0:11:57:DA
Attempting to disconnect from 03:E2:C0:11:57:DA
[00-60-37-31-7E-3F]# [DEL] Transport
    /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# [DEL] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA

The btmon log below shows that after PA sync is established inside
the BAP plugin, the Scan Delegator sends a GATT notification to
inform the Broadcast Assistant that PA sync has been established.
Once the Broadcaster device is deleted, PA sync is terminated and
the Scan Delegator once again notifies the peer about the update:

> ACL Data RX: Handle 0 flags 0x01 dlen 1
      ATT: Write Command (0x52) len 23
        Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
          Data[21]: 0201da5711c0e203001a2d5602ffff010100000000
            Opcode: Add Source (0x02)
            Source_Address_Type: 1
            Source_Address: 03:E2:C0:11:57:DA
            Source_Adv_SID: 0
            Broadcast_ID: 0x562d1a
            PA_Sync_State: Synchronize to PA - PAST not available
            PA_Interval: 0xffff
            Num_Subgroups: 1
            Subgroup #0:
              BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044)
        Options: 0x0000
        Use advertising SID, Advertiser Address Type and address
        Reporting initially enabled
        SID: 0x00
        Adv address type: Random (0x01)
        Adv address: 03:E2:C0:11:57:DA (Non-Resolvable)
        Skip: 0x0000
        Sync timeout: 20000 msec (0x07d0)
        Sync CTE type: 0x0000
> HCI Event: Command Status (0x0f) plen 4
      LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
        Status: Success (0x00)
> HCI Event: LE Meta Event (0x3e) plen 16
      LE Periodic Advertising Sync Established (0x0e)
        Status: Success (0x00)
        Sync handle: 0
        Advertising SID: 0x00
        Advertiser address type: Random (0x01)
        Advertiser address: 03:E2:C0:11:57:DA (Non-Resolvable)
        Advertiser PHY: LE 2M (0x02)
        Periodic advertising interval: 10.00 msec (0x0008)
        Advertiser clock accuracy: 0x07
> HCI Event: LE Meta Event (0x3e) plen 42
      LE Periodic Advertising Report (0x0f)
        Sync handle: 0
        TX power: 127 dbm (0x7f)
        RSSI: -64 dBm (0xc0)
        CTE Type: No Constant Tone Extension (0xff)
        Data status: Complete
        Data length: 0x22
        Service Data: Basic Audio Announcement (0x1851)
          Presetation Delay: 40000
          Number of Subgroups: 1
            Subgroup #0:
            Number of BIS(s): 1
            Codec: LC3 (0x06)
            Codec Specific Configuration: #0: len 0x02 type 0x01
            Codec Specific Configuration: Sampling Frequency: 16 Khz
            Codec Specific Configuration: #1: len 0x02 type 0x02
            Codec Specific Configuration: Frame Duration: 10 ms (0x01)
            Codec Specific Configuration: #2: len 0x03 type 0x04
            Codec Specific Configuration: Frame Length: 40 (0x0028)
            Codec Specific Configuration: #3: len 0x05 type 0x03
            Codec Specific Configuration: Location: 0x00000001
            Codec Specific Configuration: Location: Front Left
              BIS #0:
              Index: 1
> HCI Event: LE Meta Event (0x3e) plen 20
      LE Broadcast Isochronous Group Info Advertising Report (0x22)
        Sync Handle: 0x0000
        Number BIS: 1
        NSE: 3
        ISO Interval: 10.00 msec (0x0008)
        BN: 1
        PTO: 1
        IRC: 3
        Maximum PDU: 40
        SDU Interval: 10000 us (0x002710)
        Maximum SDU: 40
        PHY: LE 2M (0x02)
        Framing: Unframed (0x00)
        Encryption: 0x00
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 0101da5711c0e203001a2d560200010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 03:E2:C0:11:57:DA
          Source_Adv_SID: 0
          Broadcast_ID: 0x562d1a
          PA_Sync_State: Synchronized to PA
          BIG_Encryption: Not encrypted
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
bluetoothd[70621]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
      ATT: Handle Multiple Value Notification (0x23) len 24
        Length: 0x0014
        Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
          Data[20]: 0101dd7c8046f72a00f863f00000010000000000
          Source_ID: 1
          Source_Address_Type: 1
          Source_Address: 2A:F7:46:80:7C:DD
          Source_Adv_SID: 0
          Broadcast_ID: 0xf063f8
          PA_Sync_State: Not synchronized to PA
          BIG_Encryption: Not encrypted
          Num_Subgroups: 1
          Subgroup #0:
            BIS_Sync State: 0x00000000
< HCI Command: LE Periodic Advertising Terminate Sync (0x08|0x0046) plen 2
        Sync handle: 0x0000
> HCI Event: Command Complete (0x0e) plen 4
      LE Periodic Advertising Terminate Sync (0x08|0x0046) ncmd 1
        Status: Success (0x00

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
3 months agobass: Add APIs to probe/remove Broadcasters
Iulia Tanasescu [Thu, 29 Aug 2024 12:49:12 +0000 (15:49 +0300)]
bass: Add APIs to probe/remove Broadcasters

This adds BASS APIs to probe/remove Broadcasters probed by BAP.

The BAP plugin might probe Broadcasters that were either scanned
autonomously, or that were added by a Broadcast Assistant through
BASS.

After performing long-lived PA sync with a Broadcaster added by a
Broadcast Assistant, the BAP plugin will call the BASS probe API,
to inform BASS that PA has been established with the Broadcast Source
and to provide a reference to the created bt_bap session. Once a
Broadcaster has been probed, BASS will update the PA sync state inside
the corresponding Broadcast Receive State characteristic and
the peer Broadcast Assistant will be notified about the update.

Once the BAP session with a Broadcaster is deleted, the BASS remove
API will be called, to inform BASS that the Source is no longer active.
The BASS plugin will update the PA sync field of the corresponding
Broadcast Receive State characteristic and it will notify the peer
Broadcast Assistant that PA sync is no longer established with the
Source.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>