platform/upstream/bluez.git
5 months agobuild: Update library version
Marcel Holtmann [Thu, 24 Aug 2023 13:54:03 +0000 (15:54 +0200)]
build: Update library version

5 months agoisotest: Add defer setup support for Broadcast Receiver
Iulia Tanasescu [Wed, 23 Aug 2023 15:11:25 +0000 (18:11 +0300)]
isotest: Add defer setup support for Broadcast Receiver

This adds defer setup support for the Broadcast Receiver scenario.

In order to create a Broadcast Receiver with the defer setup option,
the -W command line parameter should be used, as described in
isotest.rst.

5 months agoadapter: Fix UUID name advertised for bcast source
Claudia Draghicescu [Tue, 22 Aug 2023 14:29:35 +0000 (17:29 +0300)]
adapter: Fix UUID name advertised for bcast source

Fix UUID name typo.

5 months agoclient/player: Remove Broadcast parameter
Claudia Draghicescu [Tue, 22 Aug 2023 14:29:34 +0000 (17:29 +0300)]
client/player: Remove Broadcast parameter

Remove unused gdbus parameter.
Fix length for Codec Specific Configuration.

5 months agotransport: Update transport properties for a broadcast stream
Claudia Draghicescu [Tue, 22 Aug 2023 14:29:33 +0000 (17:29 +0300)]
transport: Update transport properties for a broadcast stream

This patch gets the QOS broadcast stream parameters and passes them
to upper layers.

5 months agomedia: Add broadcast sink media endpoint
Claudia Draghicescu [Tue, 22 Aug 2023 14:29:32 +0000 (17:29 +0300)]
media: Add broadcast sink media endpoint

This patch adds the possibility to register a broadcast
media endpoint if the controller has support for ISO Sync Receiver.

5 months agobap: Add support for BAP broadcast sink
Claudia Draghicescu [Tue, 22 Aug 2023 14:29:31 +0000 (17:29 +0300)]
bap: Add support for BAP broadcast sink

This adds support for BAP broadcast sink, creates a remote endpoint when a
broadcast source is discovered and synchronizes with the source upon
endpoint configuration.
This feature was tested using bluetoothctl with the following commands:

[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[bluetooth]# scan on
[NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
[bluetooth]# endpoint.config
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
/local/endpoint/ep0 16_2_1

5 months agoshared/bap: Add support for BAP broadcast sink
Claudia Draghicescu [Tue, 22 Aug 2023 14:29:30 +0000 (17:29 +0300)]
shared/bap: Add support for BAP broadcast sink

This adds support for BAP broadcast sink, creates a remote endpoint when a
broadcast source is discovered and synchronizes with the source upon
endpoint configuration.
This feature was tested using bluetoothctl with the following commands:

[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[bluetooth]# scan on
[NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
[bluetooth]# endpoint.config
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
/local/endpoint/ep0 16_2_1

5 months agoclient: Add agent auto argument support
Luiz Augusto von Dentz [Wed, 23 Aug 2023 20:31:07 +0000 (13:31 -0700)]
client: Add agent auto argument support

This adds "auto" capability which behaves like "on" but instead of
asking user to confirm/autorize it automatically accepts, which is
not secure to be used thus a warning is printed when user selects it.

Usage:

  [bluetoothctl]# agent auto
  Warning: setting auto response is not secure, it bypass user
  confirmation/authorization, it shall only be used for test automation.

  or

  client/bluetoothctl -a auto

5 months agomonitor/intel: Add decoding of PPAG Enable command
Lokendra Singh [Fri, 18 Aug 2023 04:45:43 +0000 (10:15 +0530)]
monitor/intel: Add decoding of PPAG Enable command

Add decoding support for Intel PPAG Enable
command.

btmon log:
< HCI Command: Intel PPAG Enable (0x3f|0x020b) plen 4
        Enable: 0x00000002 (China)
> HCI Event: Command Complete (0x0e) plen 4
      Intel PPAG Enable (0x3f|0x020b) ncmd 1
        Status: Success (0x00)

5 months agoadapter: wait for kernel exp features in adapter initialization
Pauli Virtanen [Sun, 20 Aug 2023 11:47:06 +0000 (14:47 +0300)]
adapter: wait for kernel exp features in adapter initialization

Things like BAP depend on ISO sockets being enabled in kernel.  It is
possible the MGMT commands enabling experimental kernel features do not
complete, before BAP etc. initialization and probing starts, in which
case BAP will be mostly nonfunctional.

This was observed to occur always when running BlueZ in a Fedora VM,
requiring bluetoothd restart after every boot for BAP to work,
log containing lines in the order:

bluetoothd[981]: src/adapter.c:read_exp_features_complete() 6fbaf188-05e0-496a-9885-d6ddfdb4e03e flags 0 action 1
bluetoothd[981]: src/adapter.c:read_info_complete() index 0 status 0x00
bluetoothd[981]: profiles/audio/bap.c:bap_probe() BAP requires ISO Socket which is not enabled
bluetoothd[981]: src/adapter.c:iso_socket_complete() ISO Socket successfully set

Fix by waiting in adapter initialization that all MGMT exp feature
requests are done, before proceeding to read adapter information.

Also fix canceling MGMT_OP_SET_EXP_FEATURE for ISO sockets.

5 months agoiso-tester: add test for ACL disconnect before ISO created
Pauli Virtanen [Sat, 19 Aug 2023 13:31:23 +0000 (16:31 +0300)]
iso-tester: add test for ACL disconnect before ISO created

Simulate ACL being disconnected when connecting ISO, before LE Create
CIS got sent.  The kernel shall indicate connection failure for the ISO
socket immediately when the ACL is gone, since connecting the ISO can no
longer proceed.

ISO Connect ACL Disconnect - Failure

5 months agosco-tester: add test for ACL disconnect before SCO established
Pauli Virtanen [Sat, 19 Aug 2023 13:31:22 +0000 (16:31 +0300)]
sco-tester: add test for ACL disconnect before SCO established

Simulate ACL being disconnected before SCO is established.  Kernel shall
not crash.

eSCO ACL Disconnect - Failure

Link: https://lore.kernel.org/linux-bluetooth/00000000000013b93805fbbadc50@google.com/
5 months agohciemu: Add hciemu_flush_client_events for ordering VHCI vs bthost
Pauli Virtanen [Sat, 19 Aug 2023 13:31:21 +0000 (16:31 +0300)]
hciemu: Add hciemu_flush_client_events for ordering VHCI vs bthost

bthost commands execute with a delay because events may be sitting in
the socketpair queues.  This makes it difficult to ensure, when writing
tests, that certain bthost commands have been handled, before any new
events from VHCI are processed.

To make event ordering possible, add a function that flushes client
bthost/btdev socketpair queues, before processing any new VHCI events.
This is done by pausing VHCI input processing until the kernel
socketpair queues are empty.

5 months agovhci: Add function to pause processing input from vhci
Pauli Virtanen [Sat, 19 Aug 2023 13:31:20 +0000 (16:31 +0300)]
vhci: Add function to pause processing input from vhci

Add function to pause (temporarily) reading data from vhci.  This can be
used to synchronously pause handling of btdev commands from the kernel.

5 months agodevice: Restart temporary timer while connecting
Luiz Augusto von Dentz [Thu, 17 Aug 2023 22:31:08 +0000 (15:31 -0700)]
device: Restart temporary timer while connecting

If the device is temporary restart its timer when attempt to connect to
it since it can interrupt the connection attempt prematurely while it
still scanning, etc.

5 months agodevice: Don't attempt to set auto_connect for devices using RPAs
Luiz Augusto von Dentz [Thu, 17 Aug 2023 22:27:24 +0000 (15:27 -0700)]
device: Don't attempt to set auto_connect for devices using RPAs

Device using private address cannot be programmed into the auto_connect
list without them being paired and its IRK being distributed otherwise
there is no way to resolve it address and the command will fail.

5 months agoprofile: Remove probe_on_discover
Luiz Augusto von Dentz [Thu, 17 Aug 2023 20:06:54 +0000 (13:06 -0700)]
profile: Remove probe_on_discover

The concept of probing not connected devices is already supported when
loading devices from storage, so drivers shall already be capabable of
handling such a thing as there are dedicated callbacks to indicate when
there is a new connection in the form of .accept callback.

5 months agobap: Set auto_connect
Luiz Augusto von Dentz [Thu, 17 Aug 2023 20:11:09 +0000 (13:11 -0700)]
bap: Set auto_connect

Patch 2a4cf63f2152 has reset the flag back to false when it shouldn't
so this revert it to its original behavior.

5 months agoiso-tester: Add test for bcast receiver defer setup
Iulia Tanasescu [Thu, 17 Aug 2023 06:48:53 +0000 (09:48 +0300)]
iso-tester: Add test for bcast receiver defer setup

This adds the following test to validate defer setup support for the
Broadcast Receiver scenario:

ISO Broadcaster Receiver Defer - Success

5 months agomonitor: Detect LE-ACL connections
Luiz Augusto von Dentz [Wed, 16 Aug 2023 22:28:41 +0000 (15:28 -0700)]
monitor: Detect LE-ACL connections

This enables LE-ACL connections to be detected by processing its events
otherwise they would be assumed to be BR-ACL. Also make sure that LE-ISO
address is set based on its ACL link.

5 months agomonitor: Fix not printing latency information with -r
Luiz Augusto von Dentz [Wed, 16 Aug 2023 21:34:34 +0000 (14:34 -0700)]
monitor: Fix not printing latency information with -r

When reading a log from file hci_devba may not work, also store link
information so assign_handle can use use the parent (ACL) destination.

5 months agobuild: Fix make distcheck
Luiz Augusto von Dentz [Wed, 16 Aug 2023 00:11:02 +0000 (17:11 -0700)]
build: Fix make distcheck

This fixes the following errors:

make[2]: *** No rule to make target 'doc/test-runner.txt',
needed by 'distdir-am'.  Stop.
make[1]: *** [Makefile:11708: distdir] Error 2
make: *** [Makefile:11784: dist] Error 2

5 months agoiso-tester: Add suspend tests
Luiz Augusto von Dentz [Tue, 15 Aug 2023 22:15:03 +0000 (15:15 -0700)]
iso-tester: Add suspend tests

This adds the following test which attempt to trigger suspend code path
while ISO sockets are connecting or have been connected:

ISO Connect Suspend - Success
ISO Connected Suspend - Success
ISO Connect2 Suspend - Success
ISO Connected2 Suspend - Success

5 months agodoc/test-runner: Update documentation using rst format
Luiz Augusto von Dentz [Mon, 14 Aug 2023 19:13:12 +0000 (12:13 -0700)]
doc/test-runner: Update documentation using rst format

This updates test-runner documentation with a few examples using rst
format.

5 months agoshared/gatt-server: Fix not allowing valid attribute writes
Bart Philips [Wed, 9 Aug 2023 20:27:23 +0000 (22:27 +0200)]
shared/gatt-server: Fix not allowing valid attribute writes

The length check shall not consider the command header, just its
payload.

5 months agodevice: Fix not probing drivers at startup
Luiz Augusto von Dentz [Wed, 9 Aug 2023 19:31:25 +0000 (12:31 -0700)]
device: Fix not probing drivers at startup

Patch 67a26abe53bf ("profile: Add probe_on_discover flag") introduced a
regression which prevents drivers to be properly loaded at startup since
at that point they are not connected when code shall testing if
the devide is temporary instead.

5 months agoconfigure.ac: Bump minimum D-Bus version to 1.10
Gioele Barabucci [Wed, 9 Aug 2023 06:51:42 +0000 (08:51 +0200)]
configure.ac: Bump minimum D-Bus version to 1.10

D-Bus 1.10, released in 2015, is the first version that supports reading
policy files from `/usr/share/dbus-1` in addition to `/etc/dbus-1`.

The previous minimum version, 1.6, was released in 2012.

5 months agoprofile: Add probe_on_discover flag
Luiz Augusto von Dentz [Tue, 8 Aug 2023 11:50:37 +0000 (14:50 +0300)]
profile: Add probe_on_discover flag

This adds probe_on_discover flag which indicates if profile needs to be
probed when the remote_uuid is discovered and changes device logic to
attempt to probe driver when a new UUID is discovered and
probe_on_discover is set.

5 months agoadapter: Do not filter out broadcast advertiser
Claudia Draghicescu [Tue, 8 Aug 2023 11:50:36 +0000 (14:50 +0300)]
adapter: Do not filter out broadcast advertiser

This allows a broadcast advertiser to be passed up to application,
if the adapter has the capability of being a Synchronized Receiver.

5 months agoeir: Add eir_get_service_data
Luiz Augusto von Dentz [Tue, 8 Aug 2023 23:47:55 +0000 (16:47 -0700)]
eir: Add eir_get_service_data

This adds eir_get_service_data function which can be used to get a
specific service data.

5 months agobtio: Add support for getsockopt(BT_ISO_BASE)
Claudia Draghicescu [Tue, 8 Aug 2023 11:50:35 +0000 (14:50 +0300)]
btio: Add support for getsockopt(BT_ISO_BASE)

This adds the posibility for a broadcast sink to retrieve the
BASE information received from a source afeter a PA synchronization,
using the getsockopt(BT_ISO_BASE) function.
This needs the patch from bluetooth-next:
Bluetooth: ISO: Add support for periodic adv reports processing

5 months agoclient/player: Add broadcast sink endpoint
Claudia Draghicescu [Tue, 8 Aug 2023 11:50:34 +0000 (14:50 +0300)]
client/player: Add broadcast sink endpoint

Added support for broadcast sink registration using the 0x1851 UUID.
Added support for remote endpoint creation when a broadcast source
is discovered.
Added support for creating a local endpoint when the broadcast sink
endpoint was registered from an external application (Pipewire).
To test this feature use the following commands:

[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[bluetooth]# scan on
[NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
[bluetooth]# endpoint.config
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
/local/endpoint/ep0 16_2_1

5 months agoiso-tester: test busy CIG error does not drop existing connections
Pauli Virtanen [Sat, 5 Aug 2023 12:29:07 +0000 (15:29 +0300)]
iso-tester: test busy CIG error does not drop existing connections

A second connection made with same CIG while the CIG is busy, shall not
disconnect the first already existing connection.

Add test for this:

ISO Connect2 Busy CIG 0x01 - Success/Invalid

This was the original intent of "ISO Connect2 CIG 0x01 -
Success/Invalid", but the busy check should not be made synchronously in
connect() (to maintain ordering with Remove CIG etc), but must be done
in hci_sync. So the test needs to check the error async and explictly
that the first conn is not dropped.

5 months agobtdev: fix CIG ID on Set CIG Parameters error response
Pauli Virtanen [Sat, 5 Aug 2023 12:29:06 +0000 (15:29 +0300)]
btdev: fix CIG ID on Set CIG Parameters error response

Set CIG Parameters shall return correct CIG ID in Command_Complete also
when it errors.

5 months agoa2dp: Expose "Key missing" error
Simon Mikuda [Sun, 6 Aug 2023 08:01:09 +0000 (10:01 +0200)]
a2dp: Expose "Key missing" error

This error is not expected and retries will likely end up with same error.

5 months agoerror: Add "Invalid exchange" mapping
Simon Mikuda [Sun, 6 Aug 2023 08:01:08 +0000 (10:01 +0200)]
error: Add "Invalid exchange" mapping

This error is returned on this event:
> HCI Event: Auth Complete (0x06) plen 3
        Status: PIN or Key Missing (0x06)
        Handle: 11 Address: 00:00:00:00:00:00 (OUI 00-00-00)

5 months agomonitor: Plot RX information with -a/--analyze
Luiz Augusto von Dentz [Mon, 7 Aug 2023 21:45:34 +0000 (14:45 -0700)]
monitor: Plot RX information with -a/--analyze

This attempts to plot the RX information just as TX:

  Found BR-ACL connection with handle 256
        Address: XX:XX:XX:XX:XX:XX
        RX packets: 60/60
        RX Latency: 0-39040 msec (~20294 msec)
        RX size: 6-344 octets (~34 octets)
        RX speed: ~0 Kb/s

  100 +-+------------------------------------------------------------------+
       +|                                                                  |
       +|                                                       RX +-----+ |
       +|                                                                  |
       +|                                                                  |
       +|                                                                  |
        |                                                                  |
        |                                                                  |
   10 +-|                                                                  |
       +|                                                                  |
       +|                                                                  |
       +|                                                                  |
       +|                                                                  |
       +|                                                                  |
        |                                                                  |
        |                                                                  |
    1 +-|  + +                                                           + |
       +|  | |                                                           | |
       ++------------------------------------------------------------------+
        +       +        +       +        +       +       +        +       +
        0      5000    10000   15000    20000   25000   30000    35000   40000
                                   Latency (ms)

        TX packets: 22548/22547
        TX Latency: 3-73 msec (~11 msec)
        TX size: 6-850 octets (~847 octets)
        TX speed: ~568 Kb/s

5 months agoiso-tester: Fix test ISO Connect2 CIG 0x01 - Success/Invalid
Luiz Augusto von Dentz [Fri, 4 Aug 2023 21:51:54 +0000 (14:51 -0700)]
iso-tester: Fix test ISO Connect2 CIG 0x01 - Success/Invalid

This test shall succeed rather than fail as this appears to be a bug in
the kernel code preventing Set CIG Parameters to work properly when
there are concurrent tasks only one CIS is being programmed.

5 months agoiso-tester: add tests checking Remove CIG is emitted
Pauli Virtanen [Tue, 1 Aug 2023 16:38:42 +0000 (19:38 +0300)]
iso-tester: add tests checking Remove CIG is emitted

Kernel should send LE Remove CIG after all CIS are shut down.  Add tests
checking this, closing either immediately or after waiting connection to
complete.

ISO Defer Close - Success
ISO Connect Close - Success
ISO Defer Wait Close - Success
ISO Connect Wait Close - Success

5 months agoiso-tester: test with large CIS_ID and invalid CIG_ID/CIS_ID
Pauli Virtanen [Tue, 1 Aug 2023 16:38:41 +0000 (19:38 +0300)]
iso-tester: test with large CIS_ID and invalid CIG_ID/CIS_ID

Add test with a large CIS_ID and multiple CIS so it hits an error
condition in current kernels (which is why the AC configuration is
used).

Add tests for invalid configurations with bad or duplicate IDs, and for
trying to connect two CIS in same CIG without BT_DEFER_SETUP.

ISO QoS CIG 0xF0 - Invalid
ISO QoS CIS 0xF0 - Invalid
ISO Connect2 CIG 0x01 - Success/Invalid
ISO AC 6(ii) CIS 0xEF/auto - Success
ISO AC 6(ii) CIS 0xEF/0xEF - Invalid

5 months agosco-tester: test local and remote disconnecting simultaneously
Pauli Virtanen [Tue, 1 Aug 2023 16:38:40 +0000 (19:38 +0300)]
sco-tester: test local and remote disconnecting simultaneously

Demonstrate a kernel race condition when remote side disconnects at the
same time as local side tries to cancel the connection. I.e.

[controller] > HCI Synchronous Connect Complete
[controller] > HCI Disconnection Complete (from remote)
[user] shutdown(sco_socket)
[kernel] hci_conn_abort(SCO handle)
[kernel] > HCI Create Connection Cancel
[kernel] < HCI Synchronous Connect Complete
[kernel] < HCI Disconnect Complete
[controller] < HCI Create Connection Cancel
[controller] > HCI Command Status (Create Connection Cancel)
[kernel] < HCI Command Status (Create Connection Cancel)

and then we get BUG: KASAN: slab-use-after-free in hci_conn_failed when
hci_conn_abort tries to delete the same connection a second time.

This type of crash is probably not limited to the sequence here, but for
this one it was possible to get the timing right in the emulator.

Add a test that hits this in the emulator environment (pretty narrow
window to hit on real hardware):

eSCO Simultaneous Disconnect - Failure

5 months agobtdev: fix Command Status command opcodes for Setup Sync Conn
Pauli Virtanen [Tue, 1 Aug 2023 16:38:39 +0000 (19:38 +0300)]
btdev: fix Command Status command opcodes for Setup Sync Conn

The command opcode should be the CMD, not EVT.

5 months agobtdev: check error conditions for HCI_Create_Connection_Cancel
Pauli Virtanen [Tue, 1 Aug 2023 16:38:38 +0000 (19:38 +0300)]
btdev: check error conditions for HCI_Create_Connection_Cancel

Create Connection Cancel shall return Command Complete with error status
when there is no Create Connection that can be canceled.  In these
cases, we should not send a (spurious) Connection Complete event.

Fix by keeping a list of pending Create Connection commands, and
returning command errors if there is none pending at the moment.

5 months agomonitor/analyze: Inline data to gnuplot
Luiz Augusto von Dentz [Tue, 1 Aug 2023 23:18:10 +0000 (16:18 -0700)]
monitor/analyze: Inline data to gnuplot

Instead of creating a separate file just to write the x:y axis inline
the data via gnuplot $data variable then use it to plot.

5 months agomonitor: Add connection tracking for SCO/ISO with -a/--analyze
Luiz Augusto von Dentz [Tue, 1 Aug 2023 21:32:48 +0000 (14:32 -0700)]
monitor: Add connection tracking for SCO/ISO with -a/--analyze

This adds proper connection tracking to SCO/ISO connection by handling
the events that establishes them.

5 months agomonitor: Print channel latency information with -a/--analyze
Luiz Augusto von Dentz [Mon, 31 Jul 2023 22:13:38 +0000 (15:13 -0700)]
monitor: Print channel latency information with -a/--analyze

This prints channel latency information and use gnuplot when using
-a/--analyze to plot a graph of channels:

  Found TX L2CAP channel with CID 68
        PSM 25
        22490 packets
        7-50 msec (~11 msec) TX Latency
        850-850 octets TX packet size
        ~569 Kb/s TX transfer speed

  10000 +-+----------------------------------------------------------------+
         +|     ++                                                         |
         +|     || +                                       Packets +-----+ |
         +|   + || |                                                       |
   1000 +-|   | || |+ ++                                                   |
         +|   | || || ||   +                                               |
         +|   | || || ||+ +|                                               |
         +|   | || || ||| || ++ ++                                         |
    100 +-|   | || || ||| || || ||   +                                     |
         +|   | || || ||| || || || ++| +   +                               |
         +|   | || || ||| || || || ||| |   |                               |
         +|   | || || ||| || || || ||| |+ +| +                             |
          |   | || || ||| || || || ||| || || |+ +                          |
     10 +-|   | || || ||| || || || ||| || || || |+                         |
         +|   | || || ||| || || || ||| || || || ||     +                   |
         +|  +| || || ||| || || || ||| || || || ||+ ++ |+ ++ +             |
          |  || || || ||| || || || ||| || || || ||| || || || |             |
      1 +-|  || || || ||| || || || ||| || || || ||| || || || |   +     +   |
         ++----------------------------------------------------------------+
          +      +      +       +      +      +      +       +      +      +
          5      10     15      20     25     30     35      40     45     50
                                    Latency (ms)

5 months agomonitor/analyze: Use conn_pkt_tx on acl_pkt
Luiz Augusto von Dentz [Mon, 31 Jul 2023 21:01:09 +0000 (14:01 -0700)]
monitor/analyze: Use conn_pkt_tx on acl_pkt

This makes use of conn_pkt_tx also on acl_pkt like other connections.

5 months agomonitor: Add TX frame number and speed estimation
Luiz Augusto von Dentz [Mon, 31 Jul 2023 18:26:19 +0000 (11:26 -0700)]
monitor: Add TX frame number and speed estimation

This adds the frame information while decoding:

> HCI Event: Number of Completed Packets (0x13) plen 5
        Num handles: 1
        Handle: 256 Address: XX:XX:XX:XX:XX:XX
        Count: 1
        #188: len 850 (755 Kb/s)
        Latency: 9 msec (3-21 msec ~6 msec)
        Channel: 68 [PSM 25 mode Basic (0x00)] {chan 4}
        Channel Latency: 9 msec (7-21 msec ~9 msec)

Or the speed estimation while analyzing:

  Found BR-ACL connection with handle 256
        Address: XX:XX:XX:XX:XX:XX
        60 RX packets
        22548 TX packets
        22547 TX completed packets
        3-73 msec (~11 msec) TX Latency
        6-850 octets (~847 octets) TX packet size
        ~568 Kb/s TX transfer speed

5 months agogatt: Fix not establishing a socket for each device
Luiz Augusto von Dentz [Mon, 24 Jul 2023 20:57:34 +0000 (13:57 -0700)]
gatt: Fix not establishing a socket for each device

AcquireWrite and AcquireNotify shall establish a socket pair for each
device connected otherwise the application cannot distinct the
operations of each client.

Fixes: https://github.com/bluez/bluez/issues/460

5 months agomonitor: Add parsing Service Data of UUID 128
Łukasz Rymanowski [Sat, 29 Jul 2023 00:45:52 +0000 (02:45 +0200)]
monitor: Add parsing Service Data of UUID 128

In the advertising report, instead of deciding EIR 0x21 into this:

Unknown EIR field 0x21: 3a048f2ba97ea6ae1b49c619e973a4a701480d130d

We can do bit better

        Service Data UUID 128: Vendor specific
          Data: 01480d130d
Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de>
5 months agomonitor: Add support to decode le read ISO link quality
Łukasz Rymanowski [Sat, 29 Jul 2023 00:45:51 +0000 (02:45 +0200)]
monitor: Add support to decode le read ISO link quality

btmon: Add parsing LE Read ISO link quality

    > HCI Event: Command Complete (0x0e) plen 34
          LE Read ISO link quality (0x08|0x0075) ncmd 1
            Status: Success (0x00)
            Handle: 98
            TX unacked packets 0
            TX flushed packets 257602
            TX last subevent packets 0
            TX retrnansmitted packets 0
            TX crc error packets 2594
            RX unreceived packets 0
            Duplicated packets 0

5 months agomonitor/ll: Add support for connection parameter command.
Szymon Czapracki [Sat, 29 Jul 2023 00:45:50 +0000 (02:45 +0200)]
monitor/ll: Add support for connection parameter command.

LL_CONNECTION_PARAM_REQ (0x0f)
  Interval min: 7.50 msec (0x0006)
  Interval max: 7.50 msec (0x0006)
  Latency: 0 (0x0000)
  Timeout: 5000 msec (0x01f4)
  Preffered periodicity: 0.00 (0x00)
  Reference connection event count: 4 (0x04)
  Offset 0: 0.00 msec (0x00)
  Offset 1: 0.00 msec (0x00)
  Offset 2: 1.25 msec (0x01)
  Offset 3: 0.00 msec (0x00)
  Offset 4: 2.50 msec (0x02)
  Offset 5: 0.00 msec (0x00)

LL_CONNECTION_PARAM_RSP (0x10)
  Interval min: 7.50 msec (0x0006)
  Interval max: 7.50 msec (0x0006)
  Latency: 0 (0x0000)
  Timeout: 5000 msec (0x01f4)
  Preffered periodicity: 0.00 (0x00)
  Reference connection event count: 4 (0x04)
  Offset 0: 318.75 msec (0xff)
  Offset 1: 318.75 msec (0xff)
  Offset 2: 318.75 msec (0xff)
  Offset 3: 318.75 msec (0xff)
  Offset 4: 318.75 msec (0xff)
  Offset 5: 318.75 msec (0xff)

5 months agomonitor: Update le event mask with bits 20-23
Łukasz Rymanowski [Sat, 29 Jul 2023 00:45:49 +0000 (02:45 +0200)]
monitor: Update le event mask with bits 20-23

5 months agomonitor: Fix decoding Command Complete for Remove ISO Data path
Łukasz Rymanowski [Sat, 29 Jul 2023 00:45:48 +0000 (02:45 +0200)]
monitor: Fix decoding Command Complete for Remove ISO Data path

Before

< HCI Command: LE Remove Isochronous Data Path (0x08|0x006f) plen 3
        Connection Handle: 96
        Data Path Direction: Output (Controller to Host) (0x01)
> HCI Event: Command Complete (0x0e) plen 6
      LE Remove Isochronous Data Path (0x08|0x006f) ncmd 1
        invalid packet size
        00 60 00

After patch

< HCI Command: LE Remove Isochronous Data Path (0x08|0x006f) plen 3
        Connection Handle: 96
        Data Path Direction: 0x01
          Input (Host to Controller)
> HCI Event: Command Complete (0x0e) plen 6
      LE Remove Isochronous Data Path (0x08|0x006f) ncmd 1
        Status: Success (0x00)
        Connection handle: 96

5 months agoRename BAA_SERVICE to BCAA_SERVICE add BAA_SERVICE(0x1851)
Silviu Florian Barbulescu [Mon, 31 Jul 2023 09:16:42 +0000 (12:16 +0300)]
Rename BAA_SERVICE to BCAA_SERVICE add BAA_SERVICE(0x1851)

Rename BAA_SERVICE to BCAA_SERVICE and added BAA_SERVICE(0x1851)
as UUID for the broadcast sink.

5 months agomain: Fix integer configuration option parse failures
Zijun Hu [Mon, 31 Jul 2023 09:28:42 +0000 (17:28 +0800)]
main: Fix integer configuration option parse failures

parse_config_int() has a obvious logical error, so causes many
parse failures of integer configuration options, fixed by this
change.

5 months agoadapter: Update ConnectDevice documentation
Simon Mikuda [Mon, 31 Jul 2023 04:12:29 +0000 (06:12 +0200)]
adapter: Update ConnectDevice documentation

5 months agoadapter: Be able to use ConnectDevice for discovered devices
Simon Mikuda [Mon, 31 Jul 2023 04:12:28 +0000 (06:12 +0200)]
adapter: Be able to use ConnectDevice for discovered devices

This can be useful when you want to specify trasport type for already
paired device (e.g. use LE transport for dual mode device).

5 months agomonitor/analyze: Fix not calculating latency for ISO/SCO packets
Luiz Augusto von Dentz [Fri, 28 Jul 2023 21:53:13 +0000 (14:53 -0700)]
monitor/analyze: Fix not calculating latency for ISO/SCO packets

ISO/SCO packets latency was not being calculated because no connection was
being assigned to them.

5 months agomonitor/analyze: Fix not dequeing TX packet properly
Luiz Augusto von Dentz [Fri, 28 Jul 2023 21:48:43 +0000 (14:48 -0700)]
monitor/analyze: Fix not dequeing TX packet properly

num_completed_packets_evt contain a count for how many packets have been
completed per handle.

5 months agomonitor: Fix not calculating latency for ISO/SCO packets
Luiz Augusto von Dentz [Fri, 28 Jul 2023 21:26:13 +0000 (14:26 -0700)]
monitor: Fix not calculating latency for ISO/SCO packets

ISO/SCO packets latency was not being calculated because no connection
was assigned to them.

5 months agomonitor: Fix not dequeing TX packet properly
Luiz Augusto von Dentz [Fri, 28 Jul 2023 21:24:41 +0000 (14:24 -0700)]
monitor: Fix not dequeing TX packet properly

num_completed_packets_evt contain a count for how many packets have been
completed per handle.

5 months agomonitor: Consolidate code around latency calculation
Luiz Augusto von Dentz [Thu, 27 Jul 2023 23:55:25 +0000 (16:55 -0700)]
monitor: Consolidate code around latency calculation

This move latency calculations to a helper function called
packet_latency_add so it can get reused by the likes of l2cap.c and
analyze.c

5 months agomonitor: Update documentation
Luiz Augusto von Dentz [Fri, 28 Jul 2023 00:16:58 +0000 (17:16 -0700)]
monitor: Update documentation

This updates the documentation to mention gnuplot usage.

5 months agomonitor: Use gnuplot to plot graph of Latency-Packets
Luiz Augusto von Dentz [Wed, 26 Jul 2023 22:14:26 +0000 (15:14 -0700)]
monitor: Use gnuplot to plot graph of Latency-Packets

This make use of gnuplot when using -a/--analyze to plot a graph of
Latency-Packets:

  Found BR-ACL connection with handle 256
        Address: XX:XX:XX:XX:XX:XX (Sony Home Entertainment&Sound Products Inc)
        60 RX packets
        22548 TX packets
        22547 TX completed packets
        3 msec min latency
        73 msec max latency
        11 msec median latency
        6 octets TX min packet size
        850 octets TX max packet size
        847 octets TX median packet size

  10000 +-+----------------------------------------------------------------+
         +|      ++                                                        |
         +|      ||+                                       Packets +-----+ |
         +|      |||                                                       |
   1000 +-|      |||++                                                     |
         +|      |||||  +                                                  |
         +|      |||||++|                                                  |
         +|      ||||||||+++                                               |
    100 +-|      |||||||||||  +                                            |
         +|      |||||||||||+++  +                                         |
         +|      ||||||||||||||  |                                         |
         +| ++   ||||||||||||||++|+                                        |
          | ||   |||||||||||||||||++                                       |
     10 +-| ||   |||||||||||||||||||+                                      |
         +| ||   ||||||||||||||||||||  +                                   |
         +| || ++||||||||||||||||||||++|++++       +                       |
          | || |||||||||||||||||||||||||||||       |                       |
      1 +-| ||+||||||||||||||||||||||||||||| +  +  |                 +     |
         ++----------------------------------------------------------------+
          +       +       +       +        +       +       +       +       +
          0       10      20      30       40      50      60      70      80
                                    Latency (ms)

5 months agogatt-client: Add read-only handles to dbus
Simon Mikuda [Fri, 28 Jul 2023 04:49:44 +0000 (06:49 +0200)]
gatt-client: Add read-only handles to dbus

This can be usefull when mapping names for services and characteristics
to their handle numbers.

5 months agoadvertising: Fix peripheral adverts when Discoverable = false
Simon Mikuda [Fri, 28 Jul 2023 10:56:04 +0000 (12:56 +0200)]
advertising: Fix peripheral adverts when Discoverable = false

There is a problem with this configuration: Type = peripheral,
Discoverable = false and Adapter is discoverable

In this state device will start advertise discoverable advertisements
even when user wanted non-discoverable advertisements.

This change will add empty Flags when "Discoverable" parameter is set.

5 months agoadapter: Fix generating IRK for adapter with privacy enabled
Simon Mikuda [Fri, 28 Jul 2023 04:45:56 +0000 (06:45 +0200)]
adapter: Fix generating IRK for adapter with privacy enabled

When root folder for adapter doesn't exist we will get this runtime error:
src/adapter.c:generate_and_write_irk() Unable set contents for
 /var/lib/bluetooth/00:00:00:00:00:00/identity:
 (Failed to create file “/var/lib/bluetooth/00:00:00:00:00:00/identity.EKQ581”:
 No such file or directory)

5 months agobap: Fix memory leaks
Luiz Augusto von Dentz [Wed, 26 Jul 2023 19:36:21 +0000 (12:36 -0700)]
bap: Fix memory leaks

This fixes the following memory leaks on exit:

g32 bytes in 1 blocks are definitely lost in loss record 170 of 800
g   at 0x484182F: malloc (vg_replace_malloc.c:431)
g   by 0x47C942: util_malloc (util.c:46)
g   by 0x47AD6A: queue_new (queue.c:47)
g   by 0x379CB6: bap_data_new (bap.c:1565)
g   by 0x379E24: bap_probe (bap.c:1757)
g   by 0x4048F3: service_probe (service.c:153)
g   by 0x4190D5: probe_service (device.c:4817)
g   by 0x41927D: dev_probe (device.c:4836)
g   by 0x403918: btd_profile_foreach (profile.c:740)
g   by 0x421861: device_probe_profiles (device.c:4896)
g   by 0x3E5023: probe_devices (adapter.c:4590)
g   by 0x498022F: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.7600.4)
g
g64 bytes in 2 blocks are definitely lost in loss record 556 of 800
g   at 0x484182F: malloc (vg_replace_malloc.c:431)
g   by 0x47C942: util_malloc (util.c:46)
g   by 0x47AD6A: queue_new (queue.c:47)
g   by 0x379CB6: bap_data_new (bap.c:1565)
g   by 0x37DEA7: bap_adapter_probe (bap.c:1843)
g   by 0x3CDB51: probe_profile (adapter.c:5066)
g   by 0x403918: btd_profile_foreach (profile.c:740)
g   by 0x3F557E: adapter_register (adapter.c:9288)
g   by 0x3F557E: read_info_complete (adapter.c:10186)
g   by 0x480D91: request_complete (mgmt.c:306)
g   by 0x484466: can_read_data (mgmt.c:394)
g   by 0x4ED93F: watch_callback (io-glib.c:157)
g   by 0x496348B: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.7600.4)

5 months agoshared/vcp: Reserve one more handle in VCS for VOCS
Nitin Jadhav [Tue, 25 Jul 2023 13:47:42 +0000 (16:47 +0300)]
shared/vcp: Reserve one more handle in VCS for VOCS

Fix: As per specs, VOCS is a secondary service;
hence it should be included under a primary service VCS.
The current number of handles is increased to accommodate the
included service

5 months agoshared/vcp: Fix issues of audio location and descriptor
Nitin Jadhav [Tue, 25 Jul 2023 13:47:41 +0000 (16:47 +0300)]
shared/vcp: Fix issues of audio location and descriptor

Issues
- Audio output descriptor & location read functions requires code
correction.
- During reading audio location descriptor value was checked
instead of the pointer. DBG statement wrongly accessed value
to print the log that caused the crash.

Fix
- Corrected audio output descriptor read variable
- Corrected the audio location debug printing function
- Allocated the memory as a char pointer to the audio descriptor variable.
- Corrected the audio descriptor pointer checking condition

5 months agoshared/vcp: Fix the crash observed with VOCS
Nitin Jadhav [Tue, 25 Jul 2023 13:47:40 +0000 (16:47 +0300)]
shared/vcp: Fix the crash observed with VOCS

Root cause
- There are two types of database- Remote and Local (rdb and ldb).
- In client mode currently the code was written to access ldb.

Fix
- Correcting it, to access rdb has resolved the problem in VOCS.
- Same correction is done for VCS.

Reported-by: Pauli Virtanen <pav@iki.fi>
5 months agobtmon: Make BIG identifier consistent
Łukasz Rymanowski [Fri, 21 Jul 2023 12:03:20 +0000 (14:03 +0200)]
btmon: Make BIG identifier consistent

Bluetooth spec uses BIG Handle as a BIG identifier.
Btmon sometimes use this and sometimes BIG ID.
This patch makes code consistent

5 months agobtmon: Fix obvious typo
Łukasz Rymanowski [Fri, 21 Jul 2023 12:03:19 +0000 (14:03 +0200)]
btmon: Fix obvious typo

5 months agomonitor: Fix invalid Create BIG Test command
Grzegorz Kolodziejczyk [Fri, 21 Jul 2023 12:03:18 +0000 (14:03 +0200)]
monitor: Fix invalid Create BIG Test command

As per Bluetooth Core 5.4 Vol 4 Part E, 7.8.104,
max pdu is 2 octect long and there is no adv_handle before encyption
flag

5 months agomonitor: Fix adv_handle size in the set info transfer packet
Jakub Tyszkowski [Fri, 21 Jul 2023 12:03:17 +0000 (14:03 +0200)]
monitor: Fix adv_handle size in the set info transfer packet

As per Bluetooth Core 5.4 Vol 4. Part E, 7.8.90,
adv_handle is 1 octet size and not 2.

5 months agoclient: Add bluetoothctl-monitor.1 man page
Luiz Augusto von Dentz [Wed, 19 Jul 2023 20:30:37 +0000 (13:30 -0700)]
client: Add bluetoothctl-monitor.1 man page

This adds bluetoothctl-monitor.rst which is then converted to
bluetoothctl-mgmt.1 using rst2man.

5 months agoclient: Add bluetoothctl-mgmt.1 man page
Luiz Augusto von Dentz [Wed, 19 Jul 2023 20:11:07 +0000 (13:11 -0700)]
client: Add bluetoothctl-mgmt.1 man page

This adds bluetoothctl-mgmt.rst which is then converted to
bluetooth-mgmt.1 using rst2man.

5 months agobtmgmt: Add man page
Luiz Augusto von Dentz [Mon, 17 Jul 2023 23:01:45 +0000 (16:01 -0700)]
btmgmt: Add man page

This adds btmgmt.rst which is then converted to btmgmt.1 using rst2man.

5 months agomidi: Fix build errors
Luiz Augusto von Dentz [Mon, 17 Jul 2023 19:36:15 +0000 (12:36 -0700)]
midi: Fix build errors

This fixes the following build errors:

unit/test-midi.c:541:82: error: function definition is not allowed here
void compare_events_cb(const struct midi_write_parser *parser,
void *user_data) {
 ^
unit/test-midi.c:587:17: error: use of undeclared identifier
'compare_events_cb'; did you mean 'compare_events'?
                                     compare_events_cb, &midi_data);
                                     ^~~~~~~~~~~~~~~~~
                                     compare_events

profiles/midi/midi.c:61:75: error: function definition is not allowed
here
void foreach_cb(const struct midi_write_parser *parser, void *user_data) {
                                                                         ^
profiles/midi/midi.c:78:40: error: use of undeclared identifier 'foreach_cb'
                midi_read_ev(&midi->midi_out, event, foreach_cb, midi);
                                                     ^

5 months agoclient: Add support for mgmt submenu
Luiz Augusto von Dentz [Fri, 14 Jul 2023 22:14:02 +0000 (15:14 -0700)]
client: Add support for mgmt submenu

This moves the functionality of btmgmt into client/mgmt.c so its
commands become available on bluetoothctl via mgmt submenu.

5 months agoiso-tester: Add test for BT_PKT_STATUS sockopt
Luiz Augusto von Dentz [Thu, 13 Jul 2023 22:40:20 +0000 (15:40 -0700)]
iso-tester: Add test for BT_PKT_STATUS sockopt

This adds a test for setting BT_PKT_STATUS sockopt and checks if
BT_SCM_PKT_STATUS is properly received.

5 months agobthost: Add support to set ISO Packet Status
Luiz Augusto von Dentz [Thu, 13 Jul 2023 22:38:28 +0000 (15:38 -0700)]
bthost: Add support to set ISO Packet Status

This adds support to set ISO Packet Status to bthost_send_iso.

5 months agotest-runner: fix behavior when no audio server
Pauli Virtanen [Wed, 12 Jul 2023 21:22:49 +0000 (00:22 +0300)]
test-runner: fix behavior when no audio server

If no audio server, don't pass NULL to printf and parse TESTAUDIO
correctly.

5 months agotest-runner: set non-quiet printk before running tests
Pauli Virtanen [Wed, 12 Jul 2023 21:22:48 +0000 (00:22 +0300)]
test-runner: set non-quiet printk before running tests

It is useful to see WARN_ON etc. messages when running the tests.

The 'quiet' in cmdline suppresses levels >= WARN, so re-enable them
explicitly after boot, so that it is on by default and doesn't need to
be handled in local test scripts.

5 months agoconfigure: Fix check ell path for cross compiling
Rudi Heitbaum [Sat, 1 Jul 2023 04:12:52 +0000 (04:12 +0000)]
configure: Fix check ell path for cross compiling

Use of AC_CHECK_FILE prevents cross compilation.
Instead use test to support cross compiling.

5 months agotest-eir: Run tests using bt_ad
Luiz Augusto von Dentz [Wed, 12 Jul 2023 19:36:37 +0000 (12:36 -0700)]
test-eir: Run tests using bt_ad

This enables the same tests done with eir_data using bt_ad.

5 months agoshared/ad: Make use of util_iov_pull_* to parse data
Luiz Augusto von Dentz [Wed, 12 Jul 2023 19:34:20 +0000 (12:34 -0700)]
shared/ad: Make use of util_iov_pull_* to parse data

This makes use of util_iov_pull_* helpers to parse data.

5 months agoshared/util: Introduce strisutf8
Luiz Augusto von Dentz [Tue, 11 Jul 2023 23:45:07 +0000 (16:45 -0700)]
shared/util: Introduce strisutf8

This introduces strisutf8 which can be used to verify if a string is
encoded using UTF-8 format.

5 months agomain: Remove DEFAULT_SIRK
Luiz Augusto von Dentz [Mon, 10 Jul 2023 22:19:24 +0000 (15:19 -0700)]
main: Remove DEFAULT_SIRK

DEFAULT_SIRK is currently not used.

5 months agoshared/ad: Use util_iov_push_* helpers to generate data
Luiz Augusto von Dentz [Mon, 10 Jul 2023 20:27:34 +0000 (13:27 -0700)]
shared/ad: Use util_iov_push_* helpers to generate data

This makes use of util_iov_push_* helpers to generate the data.

5 months agoadvertising: Fix build warning
Luiz Augusto von Dentz [Mon, 10 Jul 2023 19:28:42 +0000 (12:28 -0700)]
advertising: Fix build warning

This fixes the following warning:

src/advertising.c:942:2: warning: Null pointer passed to 2nd parameter
expecting 'nonnull' [core.NonNullParamChecker]
        memcpy(cp->data + adv_data_len, scan_rsp, scan_rsp_len);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

5 months agoclient/advetising: Allow use of EA data length
Luiz Augusto von Dentz [Fri, 7 Jul 2023 21:59:24 +0000 (14:59 -0700)]
client/advetising: Allow use of EA data length

The code was supporting a maximum of 25 bytes (31 - 6) to be entered as
advertising data, but in case of EA is used that allows up to 245 bytes
(251 - 6) to be entered.

5 months agoadvertising: Use bt_ad_set_max_len
Luiz Augusto von Dentz [Fri, 7 Jul 2023 21:57:46 +0000 (14:57 -0700)]
advertising: Use bt_ad_set_max_len

This uses bt_ad_set_max_len to properly set the maximum data length of
the bt_ad instances based on what the kernel returns.

5 months agoshared/ad: Fix hardcoding maximum data length
Luiz Augusto von Dentz [Fri, 7 Jul 2023 21:54:56 +0000 (14:54 -0700)]
shared/ad: Fix hardcoding maximum data length

Instances shall not assume BT_AD_MAX_DATA_LEN is always the maximum
length as they could be used with EA which supports bigger length.

5 months agomgmt-tester: Fix tests that consider 31 bytes the max adv lenght
Luiz Augusto von Dentz [Thu, 6 Jul 2023 19:45:17 +0000 (12:45 -0700)]
mgmt-tester: Fix tests that consider 31 bytes the max adv lenght

This fixes a couple of tests that consider 31 bytes the max advertising
length since in case of extended advertising that number is actually
251.

5 months agotest-runner: Add documentation
Luiz Augusto von Dentz [Thu, 6 Jul 2023 23:04:55 +0000 (16:04 -0700)]
test-runner: Add documentation

This adds test-runner.rst documentation with a few examples of how it
can be used to run kernel testers like mgmt-tester and also bluetoothd,
audio and Bluetooth controller plugged in the host system which is quite
useful when trying experimental features such LE Audio, etc.

5 months agoshared/bass: Introduce Add Source opcode handler
Iulia Tanasescu [Thu, 29 Jun 2023 08:07:35 +0000 (11:07 +0300)]
shared/bass: Introduce Add Source opcode handler

This implements the Control Point handler for the Add Source operation.

5 months agobtio: Add options for binding iso broadcast address
Iulia Tanasescu [Thu, 29 Jun 2023 08:07:34 +0000 (11:07 +0300)]
btio: Add options for binding iso broadcast address

This adds additional btio options, to allow binding a socket
to a broadcaster address.