platform/upstream/bluez.git
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.

5 months agoplugins/admin: Fix heap-use-after-free when using 2 controllers
Vlad Pruteanu [Tue, 4 Jul 2023 05:56:43 +0000 (08:56 +0300)]
plugins/admin: Fix heap-use-after-free when using 2 controllers

This commit fixes the heap-use-after-free error when connecting 2
controllers. When a controller is connected
admin_policy_adapter_probe is called. If policy_data was already
allocated it gets freed, if not, it only gets allocated. Eventually
add_interface is called. Here policy_data is put in the "data" variable
(specific for each controller) and the process_changes task is called
with idle priority. This function ultimately accesses policy_data from
the "data" variable.

When Bluez crashes the flow is:
1)first controller is attached
2)admin_policy_adapter_probe is called and policy_data is allocated
4)second controller is attached
5)admin_policy_adapter_probe is called and policy_data is freed, then
allocated again
6)process_changes runs and the policy_data for the first controller is
read, but it was already freed, thus the crash

5 months agomonitor: Add decoding support for Sync Receiver events
Claudia Draghicescu [Tue, 4 Jul 2023 07:41:44 +0000 (10:41 +0300)]
monitor: Add decoding support for Sync Receiver events

This commit adds decoding support for PA Sync Established,
BIG Sync Established and BIG Sync Lost events.

5 months agobap: wait for CIG to become configurable before recreating CIS
Pauli Virtanen [Sun, 2 Jul 2023 18:43:05 +0000 (21:43 +0300)]
bap: wait for CIG to become configurable before recreating CIS

ISO sockets cannot be reconnected before all sockets in the same CIG
have been closed, if the CIG was previously active.

Keep track which endpoints have active CIG, and postpone connecting CIS
until their CIG is no longer active.

This addresses getting EBUSY from connect() when multiple CIS in the
same CIG move streaming -> qos at the same time, which disconnects CIS
and recreates them.  The EBUSY originates from COMMAND_DISALLOWED
response to Set CIG Parameters.

This requires the kernel side do the Disconnect CIS / Remove CIG / Set
CIG Parameters HCI command steps in the right order, when all old
sockets are closed first before connecting new ones.

5 months agoshared/bap: detach io for source ASEs only after Stop Ready
Pauli Virtanen [Sun, 2 Jul 2023 18:43:04 +0000 (21:43 +0300)]
shared/bap: detach io for source ASEs only after Stop Ready

The Client may terminate a CIS when sink is in QOS and source in
Disabling states (BAP v1.0.1 Sec 5.6.5).  It may also terminate it when
Receiver Stop Ready has completed successfully (BAP v1.0.1 Sec 5.6.5.1).

It appears Samsung Galaxy Buds2 Pro (R510XXUOAWA5) ignores the Receiver
Stop Ready command if CIS is already disconnected, and then gets stuck
in disabling state. It works if CIS is disconnected after Receiver Stop
Ready.

For better compatibility as client for this device, and since it
shouldn't matter for us in which order we do it, disconnect CIS after
completion of Receiver Stop Ready, instead of immediately in Disabling.

We disconnect also if Receiver Stop Ready fails, given that
disconnecting in Disabled state should be OK.

Link: https://github.com/bluez/bluez/issues/516
5 months agomgmt-tester: Add a regression test hitting hci_sync bug
Pauli Virtanen [Thu, 15 Jun 2023 20:02:51 +0000 (23:02 +0300)]
mgmt-tester: Add a regression test hitting hci_sync bug

Add a test "Add + Remove Device Nowait - Success" that hits a race
condition in kernel hci_sync.c.  On current kernels this causes

BUG: KASAN: slab-use-after-free in hci_update_passive_scan_sync+0x857/0x1230

due to unsafe iteration of hdev->pend_le_conns (in Linux <= 6.4-rc4).

This seems to hit the race condition also without the added emulator
delay (since the emulator runs in the same thread), but it's better to
add the delay since otherwise it'll depend on timings on kernel side.

5 months agodoc/tester-config: enable DEBUG_KERNEL, PROVE_RCU, DEBUG_ATOMIC_SLEEP
Pauli Virtanen [Tue, 4 Jul 2023 17:06:51 +0000 (20:06 +0300)]
doc/tester-config: enable DEBUG_KERNEL, PROVE_RCU, DEBUG_ATOMIC_SLEEP

Add more lock/sleep debugging to the default tester config.

Enable DEBUG_KERNEL since olddefconfig won't enable PROVE_LOCKING
without it. Enable PROVE_RCU to also check RCU usage. Enable
DEBUG_ATOMIC_SLEEP to catch those as well.

5 months agoshared/bap: use only nonzero req->id
Pauli Virtanen [Sun, 2 Jul 2023 19:34:19 +0000 (22:34 +0300)]
shared/bap: use only nonzero req->id

In bap_req_new, use same pattern as elsewhere to not use zero as
a valid id.

5 months agotransport: handle BAP Enabling state correctly when resuming
Pauli Virtanen [Sun, 2 Jul 2023 19:34:18 +0000 (22:34 +0300)]
transport: handle BAP Enabling state correctly when resuming

If BAP stream is in Enabling state when transport acquire is attempted,
we should wait for bap_state_changed to emit the completion event.

transport->resume() is only called with new owner with no
owner->pending, and shall return nonzero completion id on success.
Currently if BAP stream is Enabling, it returns zero which fails the
acquire operation.

To fix this, return valid completion id in this case instead.  Also keep
track of the g_idle_add resume id, so that we don't try to give it to
bt_bap_stream_cancel.

Fixes sound server getting spurious Not Authorized errors when trying to
acquire a pending transport.  This can happen on BAP server: linked
transports become pending when the first of the two enters Streaming. If
sound server tries to acquire the other linked transport whose stream is
still Enabling, the acquire fails (media_owner_free +
btd_error_not_authorized).

Log:
===============================================================
profiles/audio/transport.c:bap_state_changed() stream 0x25c2880: qos(2) -> enabling(3)
...
profiles/audio/transport.c:bap_state_changed() stream 0x25cc590: qos(2) -> enabling(3)
...
src/shared/bap.c:bap_stream_state_changed() stream 0x25cc590 dir 0x01: enabling -> streaming
profiles/audio/bap.c:bap_state() stream 0x25cc590: enabling(3) -> streaming(4)
profiles/audio/transport.c:bap_state_changed() stream 0x25cc590: enabling(3) -> streaming(4)
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/fd1: fd(36) ready
profiles/audio/transport.c:transport_update_playing() /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/fd1 State=TRANSPORT_STATE_IDLE Playing=1
profiles/audio/transport.c:transport_set_state() State changed /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/fd1: TRANSPORT_STATE_IDLE -> TRANSPORT_STATE_PENDING
profiles/audio/transport.c:transport_set_state() State changed /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/fd0: TRANSPORT_STATE_IDLE -> TRANSPORT_STATE_PENDING
profiles/audio/transport.c:media_owner_create() Owner created: sender=:1.1242
profiles/audio/transport.c:media_owner_free() Owner :1.1242
===============================================================

5 months agoRelease 5.68
Marcel Holtmann [Fri, 30 Jun 2023 19:39:03 +0000 (21:39 +0200)]
Release 5.68

5 months agotransport: Fix crash on Transport.Acquire
Luiz Augusto von Dentz [Fri, 30 Jun 2023 19:24:54 +0000 (12:24 -0700)]
transport: Fix crash on Transport.Acquire

This fixes crash introduced by 3030883 which caused requests not be
initialized properly for A2DP.

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

5 months agoRelease 5.67
Marcel Holtmann [Fri, 30 Jun 2023 08:09:06 +0000 (10:09 +0200)]
Release 5.67

5 months agobuild: Use LT_INIT instead of AC_PROG_LIBTOOL
Marcel Holtmann [Fri, 30 Jun 2023 07:35:21 +0000 (09:35 +0200)]
build: Use LT_INIT instead of AC_PROG_LIBTOOL

5 months agobuild: Update library version
Marcel Holtmann [Fri, 30 Jun 2023 07:30:40 +0000 (09:30 +0200)]
build: Update library version

5 months agoshared/bap: Fix handling of codec fields
Luiz Augusto von Dentz [Tue, 27 Jun 2023 23:47:09 +0000 (16:47 -0700)]
shared/bap: Fix handling of codec fields

Codec fields needs to be converted when codec.id is 0xff as the host
endian may not always be little endian.

5 months agoshared/bap: Fix parsing of vendor specific codecs
Luiz Augusto von Dentz [Tue, 27 Jun 2023 16:45:55 +0000 (09:45 -0700)]
shared/bap: Fix parsing of vendor specific codecs

While parsing vendor specific codecs cid and vid fields need to be
converted using le16_to_cpu.

5 months agoandroid: Fix compiler warning from GCC
Marcel Holtmann [Tue, 27 Jun 2023 16:08:19 +0000 (18:08 +0200)]
android: Fix compiler warning from GCC

This ignores the following two warnings from the compiler.

  CC       android/gatt.o
android/gatt.c: In function ‘handle_client_register_for_notification’:
android/gatt.c:3733:9: error: ‘memcpy’ offset [0, 16] is out of the bounds [0, 0] [-Werror=array-bounds=]
 3733 |         memcpy(&notification->ch, &cmd->char_id, sizeof(notification->ch));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  CC       android/gatt.o
android/gatt.c: In function ‘handle_client_register_for_notification’:
android/gatt.c:3735:9: error: ‘memcpy’ writing 17 bytes into a region of size 0 overflows the destination [-Werror=stringop-overflow=]
 3735 |         memcpy(&notification->ch, &cmd->char_id, sizeof(notification->ch));
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It could be possible that these warnings are valid or they might be a
false positive. However since this is Android based code based on
Android HAL headers, just set pragma to ignore them.

5 months agoisotest: Add check after accepting connection
Iulia Tanasescu [Fri, 23 Jun 2023 07:44:06 +0000 (10:44 +0300)]
isotest: Add check after accepting connection

This checks for the POLLERR event on a newly accepted connection,
to determine if the connection was successful or not.

5 months agoiso-tester: Fix checks of latency and interval
Luiz Augusto von Dentz [Fri, 23 Jun 2023 21:17:46 +0000 (14:17 -0700)]
iso-tester: Fix checks of latency and interval

Due to rounding of latency, BAP uses msec while HCI uses slots of
1.25 ms, values may not return an exact match which is fine since the
BAP QoS suggests they are the maximum latency/interval so values bellow
that shall be considered a match.

5 months agobtdev: Fix CIS Established Event parameters
Luiz Augusto von Dentz [Fri, 23 Jun 2023 21:16:02 +0000 (14:16 -0700)]
btdev: Fix CIS Established Event parameters

ISO Interval and Transport Latency were inverted.

5 months agobtdev: Fix LE CIS Established Event
Luiz Augusto von Dentz [Thu, 22 Jun 2023 19:06:17 +0000 (12:06 -0700)]
btdev: Fix LE CIS Established Event

LE CIS Established Event Transport Latency shall follow the formula from
the spec:

 BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G
 page 3050:

 Transport_Latency_C_To_P = CIG_Sync_Delay + FT_C_To_P ×
 ISO_Interval - SDU_Interval_C_To_P
 Transport_Latency_P_To_C = CIG_Sync_Delay + FT_P_To_C ×
 ISO_Interval - SDU_Interval_P_To_C

5 months agomonitor: Use get_le24 to convert 24 bits values
Luiz Augusto von Dentz [Wed, 21 Jun 2023 22:05:31 +0000 (15:05 -0700)]
monitor: Use get_le24 to convert 24 bits values

This uses get_le24 to convert 24 bits microseconds values.

5 months agobtdev: Fix CIS Establish ISO Interval
Luiz Augusto von Dentz [Tue, 20 Jun 2023 22:37:35 +0000 (15:37 -0700)]
btdev: Fix CIS Establish ISO Interval

ISO Interval is actually using 1.25 ms slots so it needs to be properly
converted.

5 months agomonitor: Fix decoding of HCI CIS Established Event
Luiz Augusto von Dentz [Tue, 20 Jun 2023 22:35:37 +0000 (15:35 -0700)]
monitor: Fix decoding of HCI CIS Established Event

The ISO Interval is actually using set using 1.25ms slots:

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E
page 2304:

  Time = N * 1.25 ms

5 months agoadapter: Handle Device Found Event with Scan Response flag
Luiz Augusto von Dentz [Tue, 20 Jun 2023 20:37:53 +0000 (13:37 -0700)]
adapter: Handle Device Found Event with Scan Response flag

This handles recently introduced Scan Response flag since that
shouldn't affect connectable flag the device would be considered
connectable but it shall not create a new device by itself.

5 months agomonitor: Add missing flags to MGMT Device Found Event
Luiz Augusto von Dentz [Tue, 20 Jun 2023 20:36:35 +0000 (13:36 -0700)]
monitor: Add missing flags to MGMT Device Found Event

This adds the missing flags to MGMT Device Found Event so they can be
decoded properly.

5 months agomgmt-api: Update Device Found Event documentation
Luiz Augusto von Dentz [Tue, 20 Jun 2023 20:33:50 +0000 (13:33 -0700)]
mgmt-api: Update Device Found Event documentation

This updates Device Found Event documentation to mention the new flag
introduced to track when the event is generated due a interleaved Scan
Response that couldn't be merged.

5 months agoshared/bap: Pass bcode as a reference instead of value
Luiz Augusto von Dentz [Mon, 19 Jun 2023 20:30:32 +0000 (13:30 -0700)]
shared/bap: Pass bcode as a reference instead of value

This makes bcode field a pointer which makes it simpler to detect when
it is set and also fixes the usage of util_iov_free which expects it to
be allocated.

5 months agoclient/player: Fix transport.acquire for linked transports
Luiz Augusto von Dentz [Mon, 19 Jun 2023 20:30:31 +0000 (13:30 -0700)]
client/player: Fix transport.acquire for linked transports

Linked (bi-directional) transports can be acquired on single D-Bus
method call which was not being handled properly by the current code
causing unexpected errors.

5 months agoclient/player: Fix auto registration of broadcast endpoint
Luiz Augusto von Dentz [Mon, 19 Jun 2023 20:30:30 +0000 (13:30 -0700)]
client/player: Fix auto registration of broadcast endpoint

For broadcast endpoint broadcast must be set properly.

5 months agoclient: Print integers decimal value
Luiz Augusto von Dentz [Mon, 19 Jun 2023 20:30:29 +0000 (13:30 -0700)]
client: Print integers decimal value

This make the code print D-Bus integer iterators also in decimal format
in addition to hexadecimal.

5 months agoshared/bap: Add unespecified bit in audio context to PAC records
Luiz Augusto von Dentz [Mon, 19 Jun 2023 20:30:28 +0000 (13:30 -0700)]
shared/bap: Add unespecified bit in audio context to PAC records

This makes sure unespecified bit is properly marked in both audio
contexts since that required by many platforms in order to work properly
and while doing that add proper defines to the defaults values used in
PACS.

5 months agoshared/bass: Implement CP opcode handlers
Iulia Tanasescu [Tue, 13 Jun 2023 14:16:25 +0000 (17:16 +0300)]
shared/bass: Implement CP opcode handlers

This adds handlers for the following BASS Broadcast Audio Scan
Control Point opcodes:
   Remote Scan Stopped
   Remote Scan Started
   Remove Source

5 months agogatt-server: Check pointer before memcpy
Iulia Tanasescu [Tue, 13 Jun 2023 14:16:24 +0000 (17:16 +0300)]
gatt-server: Check pointer before memcpy

This adds a check before calling memcpy inside
bt_gatt_server_send_notification, to avoid getting
the following error in case the user wants to send
an empty notification for an attribute:

src/shared/gatt-server.c:1789:3: runtime error:
null pointer passed as argument 2, which is declared to never be null

5 months agoshared/vcp.c: Make VOCS as an included service of VCS
Nitin Jadhav [Mon, 12 Jun 2023 13:32:51 +0000 (19:02 +0530)]
shared/vcp.c: Make VOCS as an included service of VCS

Fixed the following issue observed during PTS testing
- Specified Upper and Lower Limit for Volume offset
- Corrected the number of handles for VOCS
- VOCS is made as included service of VCS
  (VOCS is secondary service and VSC is primary service)

5 months agoshared/vcp: Add initial code for handling VOCS
Nitin Jadhav [Mon, 12 Jun 2023 13:32:50 +0000 (19:02 +0530)]
shared/vcp: Add initial code for handling VOCS

Summary:
- This adds implementation for VOCS service and characteristics
- Implementation based on VOCS_v1.0.pdf specification
- Tested using PTS with reference to VOCS.TS.p1.pdf

5 months agolib/uuid.h: Add VOCS characteristic uuid(s)
Nitin Jadhav [Mon, 12 Jun 2023 13:32:49 +0000 (19:02 +0530)]
lib/uuid.h: Add VOCS characteristic uuid(s)

5 months agomesh: Fix build error
Luiz Augusto von Dentz [Tue, 13 Jun 2023 20:28:47 +0000 (13:28 -0700)]
mesh: Fix build error

This fixes the following error:

In function ‘get_composition’,
    inlined from ‘cfg_srv_pkt’ at mesh/cfgmod-server.c:801:8:
mesh/cfgmod-server.c:758:9: error: ‘comp’ may be used
uninitialized [-Werror=maybe-uninitialized]
  758 |         memcpy(buf, comp, len);
      |         ^~~~~~~~~~~~~~~~~~~~~~
mesh/cfgmod-server.c: In function ‘cfg_srv_pkt’:
mesh/cfgmod-server.c:739:24: note: ‘comp’ was declared here
  739 |         const uint8_t *comp;
      |                        ^~~~

5 months agobtdev: Fix build error
Luiz Augusto von Dentz [Tue, 13 Jun 2023 20:25:34 +0000 (13:25 -0700)]
btdev: Fix build error

This fixes the following build error:

emulator/btdev.c: In function ‘le_cis_estabilished’:
emulator/btdev.c:5947:22: error: ‘cis_idx’ may be used
uninitialized [-Werror=maybe-uninitialized]
 5947 |         int cig_idx, cis_idx;
      |                      ^~~~~~~

5 months agobap: Add broadcast source support
Silviu Florian Barbulescu [Wed, 7 Jun 2023 08:23:00 +0000 (11:23 +0300)]
bap: Add broadcast source support

This updates BAP plugin with broadcast source support.

5 months agoshared/bap: Add initial code for BAP broadcast source
Silviu Florian Barbulescu [Wed, 7 Jun 2023 08:22:59 +0000 (11:22 +0300)]
shared/bap: Add initial code for BAP broadcast source

This adds initial support for BAP broadcast source.

5 months agoclient/player: Add support for broadcast source
Silviu Florian Barbulescu [Wed, 7 Jun 2023 08:22:58 +0000 (11:22 +0300)]
client/player: Add support for broadcast source

This adds bluetoothctl support for broadcast source.
To test the current implementation use bluetoothctl with the commands:
endpoint.register 00001852-0000-1000-8000-00805f9b34fb 0x06
endpoint.config <created endpoint> <local endpoint> 16_2_1
transport.acquire <created transport>
transport.send <created transport> <file.wav>

5 months agoshared/bap: Split unicast and broadcast structures
Silviu Florian Barbulescu [Wed, 7 Jun 2023 08:22:57 +0000 (11:22 +0300)]
shared/bap: Split unicast and broadcast structures

This splits bt_bap_qos structure into unicast and broadcast structures.

5 months agomedia: Register app objects in proxy_added_cb()
Arkadiusz Bokowy [Sat, 27 May 2023 23:14:58 +0000 (01:14 +0200)]
media: Register app objects in proxy_added_cb()

The proxy_added_cb() function is called every time a new client is added
to the application object manager. Registering media endpoint and player
in that proxy_added_cb() callback function will allow to register new
endpoints and players not only during the initial RegisterApplication
call, but also during the application lifetime. For instance, this might
allow to dynamically enable/disable support for additional codecs.

5 months agobattery: Check interface before getting property
Arkadiusz Bokowy [Sun, 28 May 2023 07:44:45 +0000 (09:44 +0200)]
battery: Check interface before getting property

Client can export other interfaces than the BatteryProvide1 on the
registered object manager. So, before getting battery provider specific
property, validate that we are operating on the right interface.

This change will allow client to implement only one object manger for
media applications, players and battery providers without triggering
error message.

5 months agoshared/bap: Don't overwrite attribute declaration
Luiz Augusto von Dentz [Thu, 1 Jun 2023 23:28:09 +0000 (16:28 -0700)]
shared/bap: Don't overwrite attribute declaration

The attribute declaration (e.g. characteristic properties) shall not be
overwritten as they are part of the information that is part of the
cache beside the same information is already stored as part of the
bt_bap instance.

5 months agomonitor: Only print credentials if PID is set
Luiz Augusto von Dentz [Thu, 1 Jun 2023 23:26:15 +0000 (16:26 -0700)]
monitor: Only print credentials if PID is set

If PID is not set don't print anything since this is likely a packet
originated by the kernel itself.

5 months agounit: Introduce test-bass
Iulia Tanasescu [Mon, 29 May 2023 08:46:50 +0000 (11:46 +0300)]
unit: Introduce test-bass

This adds 3 unit tests for BASS server, to simulate the
Generic GATT Integrated Test suite for BASS.

Test Summary
------------
BASS/SR/SGGIT/SER/BV-01-C                            Passed
BASS/SR/SGGIT/CHA/BV-01-C                            Passed
BASS/SR/SGGIT/CHA/BV-02-C                            Passed
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0