Commit Graph

26461 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
1ffd74a6d4 monitor/att: Fix parsing of notifications
If there are multiple notifications in the same frame the callback may
alter it when using l2cap_frame_pull helpers, so instead this passes a
cloned frame with just the expected length so callbacks cannot alter
original frame.
2022-05-25 12:52:19 -07:00
Luiz Augusto von Dentz
2894f1392f monitor/att: Attempt to reload if database is empty
If database is empty attempt to reload since the daemon may have
updated its cache in the meantime.
2022-05-25 12:47:10 -07:00
Inga Stotland
79fe529d64 client: Fix setting of advertisement interval
This fixes incorrect argument read when using "interval" command
in "advertisement" submenu
2022-05-23 13:47:15 -07:00
Luiz Augusto von Dentz
bbdd18089b monitor/att: Fix parsing of Notify Mutiple
Notify Multiple was parsing handle multiple times causing the length to
be assumed to be a handle.
2022-05-20 17:23:09 -07:00
Luiz Augusto von Dentz
8e1fd164a7 monitor/att: Fix not matching read frame direction
There could be read frames pending on both direction so this ensures
the direction is matched properly.
2022-05-20 17:23:09 -07:00
Luiz Augusto von Dentz
20e944ece7 monitor/att: Fix treating Notification/Indication as a request
Notification/Indication shall be treated as response so the correct
database is used.
2022-05-20 17:23:08 -07:00
Luiz Augusto von Dentz
eb47cb5a04 monitor/att: Fix not removing read from queue
The code was using queue_find instead of queue_remove_if so follow up
read wouldn't match the attribute properly.
2022-05-20 17:23:08 -07:00
Luiz Augusto von Dentz
f1069c4fe1 gatt-server: Fix crash while disconnecting
If there is a pending notify multiple the code was not removing before
freeing the object causing the following crash:

Invalid read of size 8
   at 0x4A3D10: notify_multiple (gatt-server.c:1703)
   by 0x4D05F0: timeout_callback (timeout-glib.c:25)
   by 0x4956900: ??? (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x49560AE: g_main_context_dispatch
   (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x49AB307: ??? (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x49557C2: g_main_loop_run
   (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x4D0A34: mainloop_run (mainloop-glib.c:66)
   by 0x4D0F2B: mainloop_run_with_signal (mainloop-notify.c:188)
   by 0x2B0CD1: main (main.c:1276)
 Address 0x6ca35c8 is 136 bytes inside a block of size 144 free'd
   at 0x48470E4: free (vg_replace_malloc.c:872)
   by 0x415E73: gatt_server_cleanup (device.c:698)
   by 0x415E73: attio_cleanup (device.c:715)
   by 0x47745B: queue_foreach (queue.c:207)
   by 0x490C54: disconnect_cb (att.c:701)
   by 0x4CF4AF: watch_callback (io-glib.c:157)
   by 0x49560AE: g_main_context_dispatch
   (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x49AB307: ??? (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x49557C2: g_main_loop_run
   (in /usr/lib64/libglib-2.0.so.0.7000.5)
   by 0x4D0A34: mainloop_run (mainloop-glib.c:66)
   by 0x4D0F2B: mainloop_run_with_signal (mainloop-notify.c:188)
   by 0x2B0CD1: main (main.c:1276)
2022-05-20 14:14:24 -07:00
Luiz Augusto von Dentz
bd6b90595e monitor/att: Add decoding support for CCC
This adds decoding support for CCC so its value can be decoded:

< ACL Data TX: Handle 3585 flags 0x00 dlen 7
      ATT: Read Request (0x0a) len 2
        Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
> ACL Data RX: Handle 3585 flags 0x02 dlen 6
      ATT: Read Response (0x0b) len 1
        Value: 01
            Notification (0x01)
< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
          Data: 0100
            Notification (0x01)
2022-05-19 17:54:16 -07:00
Luiz Augusto von Dentz
0bd5350459 monitor/att: Decode attribute type
This attempt to decode the attribute type if its gatt_db can be loaded:

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x000b Type: Client Characteristic Configuration (0x2902)
          Data: 0200
2022-05-18 15:35:49 -07:00
Luiz Augusto von Dentz
1cf5ceeef3 monitor: Cache connection information
This caches connection information including the device addres so it can
be printed alongside the handle:

> HCI Event: Disconnect Complete (0x05) plen 4
        Status: Success (0x00)
        Handle: 3585 Address: 68:79:12:XX:XX:XX (OUI 68-79-12)
        Reason: Connection Terminated By Local Host (0x16)
2022-05-18 15:35:49 -07:00
Luiz Augusto von Dentz
5efc737f49 monitor: Move ATT decoding function into its own file
This moves ATT decoding function from l2cap.c to att.c.
2022-05-18 15:35:47 -07:00
Luiz Augusto von Dentz
0247ed333e monitor: Move print_hex_field to display.h
This moves print_hex_field to display.h and removes the duplicated code
from packet.c and l2cap.c.
2022-05-18 15:35:46 -07:00
Luiz Augusto von Dentz
f66673878a gatt: Store local GATT database
This enables storing the local (adapter) GATT database which later will
be used by btmon to decode GATT handles.
2022-05-18 15:35:46 -07:00
Luiz Augusto von Dentz
02017e320b settings: Add btd_settings_gatt_db_{store,load}
This adds helper functions to store and load from/to file so they can
get reused by the likes of gatt-database.c and btmon.
2022-05-18 15:35:45 -07:00
Archie Pusaka
c159d790e8 input/device: Notify failure if ctrl disconnect when waiting intr
On some rare occasions, the peer HID device might disconnect the ctrl
channel when we are trying to connect the intr channel. If this
happens, interrupt_connect_cb() will not be called by btio, and we
will be stuck in "connecting" state. Any future connection attempt to
the peer device will fail because of "busy".

This patch prevents that by checking if we need to report connection
failure when the ctrl channel is disconnected.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
2022-05-18 15:19:43 -07:00
Luiz Augusto von Dentz
c7955b2099 hog-lib: Fix not reading report_map of instances
If there is multiple instances the gatt_db of the instances was not
initialized causing the report_map_attr to be NULL which prevents the
report_map to be read and uhid device to be created.

Fixes: https://github.com/bluez/bluez/issues/298
2022-05-12 18:04:20 -07:00
Luiz Augusto von Dentz
7a4b67f9ca device: Fix enabling wake support without RPA Resolution
If device uses RPA it shall only enable wakeup if RPA Resolution has
been enabled otherwise it cannot be programmed in the acceptlist which
can cause suspend to fail.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=215768
2022-05-12 16:58:52 -07:00
Luiz Augusto von Dentz
83497bbb30 gatt-db: Allow passing Characteristic Value to gatt_db_attribute_get_char_data
This makes gatt_db_attribute_get_char_data work with Characteristic
Value rather than only with Characteristic Declaration.
2022-05-12 16:56:25 -07:00
Luiz Augusto von Dentz
cd24715bb2 service: Add initiator argument to service_accept
This adds initiator argument to service_accept so profiles accepting
the connection can use btd_service_is_initiator to determine if the
connection was initiated locally (central) or remotely (peripheral).
2022-05-12 16:56:18 -07:00
wangyouwan
4423d63a96 device: Fix pairing has failed due to the error of Already Paired (0x13)
After connect the Bluetooth mouse, open two Bluetoothctl at the same time,
when remove the mouse, quickly go to power off,
try to paired the mouse again when I was power on,
found that the error 0x13 was always reported.
try to connect directly,can connect successfully.
but use the info command to query the information of the mouse
and find that the pairing status of the mouse is No.
so I try to delete the paired information in the kernel
through the "* cancel_pairing()" interface.
2022-05-11 14:34:53 -07:00
Ildar Kamaletdinov
42e9b8db92 device: Fix uninitialized value usage
Definitely `dbus_bool_t b;` must be initialized before comparing it
with current value.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
2022-05-09 13:05:39 -07:00
Ildar Kamaletdinov
e9ec1cf871 tools: Fix handle leak in rfcomm
Some branches of execution can make handle (socket) leakage.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
2022-05-09 13:05:38 -07:00
Ildar Kamaletdinov
a4741ef4bf tools: Fix memory leaks in btgatt-server/client
According to man buffer allocated by getline() should be freed by
the user program even if getline() failed.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
2022-05-09 13:05:38 -07:00
Ildar Kamaletdinov
efa9005093 tools: Fix memory leak in hciconfig
printf() was using function that return dynamic allocated memory as
a parameter.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
2022-05-09 13:05:38 -07:00
Luiz Augusto von Dentz
f0106d92a1 advertising: Treat empty LocalName the same as omitting it
This treats empty LocalName ("") the same as omitting it so not name is
set in the advertising data since some D-Bus binding seems to have
problems to omit properties at runtime.

Fixes: https://github.com/bluez/bluez/issues/337
2022-05-06 16:05:14 -07:00
Luiz Augusto von Dentz
7ce093041a device-api: Clarify Paired/Bonded documentation
This attempt to clarify the distinction of Paired and Bonded
properties.
2022-05-04 16:39:30 -07:00
Zhengping Jiang
bda2a9e6f9 client: Add filter to devices and show Bonded in info
Use the property name as optional filters to the command "devices" and
show the "Bonded" property for the command "info".

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
2022-05-04 14:56:05 -07:00
Zhengping Jiang
0e2e52d0c1 device: Add "Bonded" flag to dbus property
Add "Bonded" to dbus device property table. When setting the "Bonded
flag, check the status of the Bonded property first. If the Bonded
property is changed, send property changed signal.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
2022-05-04 14:56:02 -07:00
Zhengping Jiang
5c05df7c76 doc: add "Bonded" flag to dbus property
Bonded flag is used to indicate the link key or ltk of the remote
device has been stored.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
2022-05-04 14:56:01 -07:00
Luiz Augusto von Dentz
b7ca43eedf monitor: Fix parsing of LE Terminate BIG Complete event
LE Terminate BIG Complete event format Subevent_Code, BIG_Handle and
Reason but the last two were swapped.
2022-05-02 16:42:53 -07:00
Luiz Augusto von Dentz
6bf9d1775c monitor: Decode LTV fields of Basic Audio Announcements
This decodes the LTV fields of Basic Audio Announcements:

< HCI Command: LE Set Periodic Advertising Data (0x08|0x003f) plen 41
        Handle: 0
        Operation: Complete ext advertising data (0x03)
        Data length: 0x26
        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: 03
            Codec Specific Configuration #1: len 0x02 type 0x02
            Codec Specific Configuration: 01
            Codec Specific Configuration #2: len 0x05 type 0x03
            Codec Specific Configuration: 01000000
            Codec Specific Configuration #3: len 0x03 type 0x04
            Codec Specific Configuration: 2800
            Metadata #0: len 0x03 type 0x02
            Metadata: 0200
              BIS #0:
              Index: 1
              Codec Specific Configuration:
2022-05-02 16:42:46 -07:00
Luiz Augusto von Dentz
c75ff36b77 btdev: Fix not removing connection and advertising set on reset
This makes sure that all connections and advertising sets are cleanup
on reset.
2022-05-02 14:06:12 -07:00
Luiz Augusto von Dentz
fa7828bddd transport: Fix not being able to initialize volume properly
In case AVRCP is connected first and
media_transport_update_device_volume is called without any media_player
being available the volume setting would be lost and Transport.Volume
won't be available, so this introduces btd_device_{set,get}_volume
helpers which is used to store the volume temporarely so
media_player_get_device_volume is able to restore it when the transport
is created.

Fixes: https://github.com/bluez/bluez/issues/335
2022-04-28 13:05:02 -07:00
Luiz Augusto von Dentz
f65a9c9d21 btmon: Fix not decoding LC3 id
This enablind decoding LC3 codec id (0x06).
2022-04-26 16:02:54 -07:00
Luiz Augusto von Dentz
80cd36cd2a btmon: Add support for decoding Basic Audio Annoucements
This adds support for decoding Basic Audio Announcements as shown
on:

Basic Audio Profile / Profile Specification
Page 36 of 146

Table 3.15: Format of BASE used in Basic Audio Announcements

< HCI Command: LE Set Periodic Advertising Data (0x08|0x003f) plen 36
        Handle: 0
        Operation: Complete ext advertising data (0x03)
        Data length: 0x21
        Service Data: Basic Audio Announcement (0x1851)
          Presetation Delay: 40000
          Number of Subgroups: 1
            Subgroup #0:
            Number of BIS(s): 1
            Codec: Reserved (0x06)
            Codec Specific Configuration: 010101020403010000020428
            Metadata: 020202
              BIS #0:
              Index: 1
              Codec Specific Configuration:
2022-04-26 16:00:53 -07:00
Luiz Augusto von Dentz
6da642225f btmon: Add support for decoding Broadcast Audio Annoucements
This adds support for decoding Broadcast Audio Announcements as shown
on:

Basic Audio Profile / Profile Specification
Page 34 of 146

Table 3.14: Broadcast Source AD format when transmitting Broadcast
Audio Announcements

< HCI Command: LE Set Extended Advertising Data (0x08|0x0037) plen 36
        Handle: 0x00
        Operation: Complete extended advertising data (0x03)
        Fragment preference: Minimize fragmentation (0x01)
        Data length: 0x20
        Service Data: Broadcast Audio Announcement (0x1852)
        Broadcast ID: 904177 (0x0dcbf1)
        Name (complete): Broadcast Audio Source
2022-04-26 15:59:48 -07:00
Luiz Augusto von Dentz
640d6b5c66 btmon: Add proper decoding to Service Data UUID
This adds proper decoding for Service Data UUID:

        Service Data: Apple, Inc. (0xfd6f)
          Data: e6b07e19815e902100b8b2f4a55255fd18f0c6be
2022-04-26 11:39:14 -07:00
Luiz Augusto von Dentz
7a87497da4 client/player: Add transport.receive command
This adds transport.receive command:

Get/Set file to receive
Usage:
	 receive [filename]
2022-04-26 11:03:26 -07:00
Luiz Augusto von Dentz
dd5b66695c client/player: Add transport.volume command
This adds transport.volume command:

Get/Set transport volume
Usage:
	 volume <transport> [value]
2022-04-22 16:01:29 -07:00
Luiz Augusto von Dentz
3e2ad5009c btmon: Fix decoding of Enhanced Credit Connection Request
This fixes the decoding of Enhanced Credit Connection Request which was
not accounting the fields correctly causing 2 extra Source CID to be
printed.
2022-04-22 13:03:50 -07:00
Luiz Augusto von Dentz
c535623a71 hog-lib: Check if Report ID is set before prepending it
Before prepending the Report ID check if it is non-zero:

BLUETOOTH SPECIFICATION Page 16 of 26
HID Service Specification

Report ID shall be nonzero in a Report Reference characteristic
descriptor where there is more than one instance of the Report
characteristic for any given Report Type.

Fixes: https://www.spinics.net/lists/linux-bluetooth/msg97262.html
2022-04-22 13:03:34 -07:00
Diego Rondini
a1939bd51e test: changes for Python3
Remove some leftover usage of Python2 code. In particular replace
iteritems() with items() to fix the following error:

AttributeError: 'dbus.Dictionary' object has no attribute 'iteritems'
2022-04-19 15:32:16 -07:00
Luiz Augusto von Dentz
832b594a25 settings-storage: Document use of StateDirectory
This documents the use of StateDirecory environment variable which
overwrites the default storage diretory when set.
2022-04-19 11:34:25 -07:00
Luiz Augusto von Dentz
00cfb36e20 bluetooth.service: Set ConfigurationDirectoryMode
This sets ConfigurationDirectoryMode to 0555 to really enforce the
ConfigurationDirectory to be read-only [1].

[1] https://github.com/bluez/bluez/issues/329#issuecomment-1102459104
2022-04-19 11:18:59 -07:00
Luiz Augusto von Dentz
edc69d2534 bluetooth.service: Set StateDirectoryMode
This sets StateDirectoryMode to 0700 as it is the current mode used for
creating files inside the storage and it is different than the default
systemd uses which is 0755:

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html#RuntimeDirectoryMode=
2022-04-19 11:07:40 -07:00
Luiz Augusto von Dentz
b2db8f0e3a client/player: Fix use of unsupported config_qos
QoS is not yet supported by bluetoothd so remove them.
2022-04-18 16:57:49 -07:00
Luiz Augusto von Dentz
fb4997fb09 test-runner: Add dedicated option to start D-Bus
This adds a dedicated option to start D-Bus alone which can be useful
when testing the bluetoothd with the likes of valgrind.
2022-04-18 16:53:00 -07:00
Luiz Augusto von Dentz
0905a06410 build: Make use of StateDirectory and ConfigurationDirectory
This makes use of StateDirectory[1] and ConfigurationDirectory[1] to
inform systemd what those paths are used for instead of using
ReadWritePaths and ReadOnlyPaths which can lead to issues.

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

[1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html
2022-04-18 16:52:59 -07:00
Luiz Augusto von Dentz
385e8d649e main: Add support for CONFIGURATION_DIRECTORY environment variable
When running as a systemd service the CONFIGURATION_DIRECTORY
environment variable maybe set:

https://www.freedesktop.org/software/systemd/man/systemd.exec.html
2022-04-18 16:52:58 -07:00