Commit Graph

26380 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
4fefa24097 adapter: Fix adding SDP records when operating on LE only mode
If mode is set to BT_MODE_LE SDP protocol won't be operational so it is
useless to attempt to add records.
2022-03-28 10:51:27 -07:00
Inga Stotland
2a2b027176 mesh: Fix address overrun error in rx filter
This fixes the following error for invalid read access when registering
filter for incoming messages:

140632==ERROR: AddressSanitizer: stack-buffer-overflow on address...
 #0 0x7f60c185741d in MemcmpInterceptorCommon(...
    #1 0x7f60c1857af8 in __interceptor_memcmp (/lib64/libasan.so...
    #2 0x55a10101536e in find_by_filter mesh/mesh-io-unit.c:494
    #3 0x55a1010d8c46 in l_queue_remove_if ell/queue.c:517
    #4 0x55a101014ebd in recv_register mesh/mesh-io-unit.c:506
    #5 0x55a10102946f in mesh_net_attach mesh/net.c:2885
    #6 0x55a101086f64 in send_reply mesh/dbus.c:153
    #7 0x55a101124c3d in handle_method_return ell/dbus.c:216
    #8 0x55a10112c8ef in message_read_handler ell/dbus.c:276
    #9 0x55a1010dae20 in io_callback ell/io.c:120
    #10 0x55a1010dff7e in l_main_iterate ell/main.c:478
    #11 0x55a1010e06e3 in l_main_run ell/main.c:525
    #12 0x55a1010e06e3 in l_main_run ell/main.c:507
    #13 0x55a1010e0bfc in l_main_run_with_signal ell/main.c:647
    #14 0x55a10100316e in main mesh/main.c:292
    #15 0x7f60c0c6855f in __libc_start_call_main (/lib64/libc.so.6+...
    #16 0x7f60c0c6860b in __libc_start_main_alias_1 (/lib64/libc.so.6+...
    #17 0x55a101003ce4 in _start (/home/istotlan/bluez/mesh/bluetooth-m...
2022-03-26 09:48:58 -07:00
Luiz Augusto von Dentz
71cec503c8 device: Don't use DBG in gatt_debug
gatt_debug callback is used to print debug strings from bt_att which
includes the file and function names so using DBG would add yet another
set of file and function prefixes which makes the logs confusing.
2022-03-23 15:39:45 -07:00
Luiz Augusto von Dentz
e1b808c128 att: Rename att_debug and att_verbose to DBG and VERBOSE
att_debug and att_verbose are macros which are more common to be
used as uppercase, this also change them to use DBG like other parts of
the code.
2022-03-23 15:39:41 -07:00
Luiz Augusto von Dentz
55c25d91e4 gatt-server: Add DBG macro
This adds gatt_log wrapper for util_debug and DBG so file and function
names are printed with the logs.
2022-03-23 15:39:38 -07:00
Luiz Augusto von Dentz
e0870ce5e1 gatt-client: Add DBG macro
This adds gatt_log wrapper for util_debug and DBG macro so file and
function names are printed which is more consistent with other parts of
the daemon code.
2022-03-23 15:39:36 -07:00
Luiz Augusto von Dentz
8039d42687 att: Log file and function names
This adds logging of file and function names.
2022-03-23 15:39:33 -07:00
Luiz Augusto von Dentz
62c6037ea0 adapter: Don't use DBG in mgmt_debug
mgmt_debug callback is used to print debug strings from mgmt instances
which includes the file and function names so using DBG would add yet
another set of file and function prefixes which makes the logs
confusing.
2022-03-23 15:39:29 -07:00
Luiz Augusto von Dentz
b7c807269f mgmt: Introduce mgmt_set_verbose
This introduces mgmt_set_verbose which can be used to enable printing
the the likes hexdump of packets, by default it is disabled since in
most cases the hexdump is not very useful and there are better tools
to collect the hexdumo like btmon.
2022-03-23 15:39:23 -07:00
Luiz Augusto von Dentz
f9cb7c802f mgmt: Add DBG macro
This adds mgmt_log wrapper for util_debug and DBG so file and function
names are printed with the logs.
2022-03-23 15:39:20 -07:00
Luiz Augusto von Dentz
a3c9409035 log: Don't log __FILE__ and __func__ with DBG_IDX
This removes __FILE__ and __func__ from DBG_IDX since users of it may
already contain such information embedded in the format.
2022-03-23 15:39:01 -07:00
Marcel Holtmann
41f8c466f3 Release 5.64 2022-03-16 16:04:29 +01:00
Luiz Augusto von Dentz
411d63ec33 gatt-db: Fix gatt_db_attribute_notify
gatt_db_attribute_notify was only accepting passing the Characteristic
Declaration instead of accepting its value as well,
gatt_db_service_foreach_desc also have similar limitation so both have
been updated to allow working with both value and declaration.
2022-03-14 14:47:02 -07:00
Luiz Augusto von Dentz
8fb8f9e73f gatt: Print error if gatt_db_attribut_notify fails
This prints an error if gatt_db_attribut_notify fails.
2022-03-14 14:46:21 -07:00
Luiz Augusto von Dentz
42e9937158 test-runner: Update help information
This updates usage so it list -l/--emulator properly:

test-runner - Automated test execution utility
Usage:
	test-runner [options] [--] <command> [args]
Options:
	-a, --auto             Find tests and run them
	-d, --dbus             Start D-Bus daemon
	-m, --monitor          Start btmon
	-l, --emulator         Start btvirt
	-u, --unix [path]      Provide serial device
	-q, --qemu <path>      QEMU binary
	-k, --kernel <image>   Kernel image (bzImage)
	-h, --help             Show help options
2022-03-08 18:07:06 -08:00
Luiz Augusto von Dentz
55888bfd62 test-runner: Fix -l/--emulator
This fixes -l/--emulator not able to start depending on what parameters
are given as it was not setting the directory properly.
2022-03-08 18:00:49 -08:00
Luiz Augusto von Dentz
8e1892cc92 btdev: Fix response to LE Set Extended Advertising Parameters
The response should both the status and TX Power regardless if the
command succeeds or not.
2022-03-08 17:58:40 -08:00
Yun-Hao Chung
b69b5736c8 audio: Fix crash in a2dp_discover
Sample stack trace:
0x0000567c394e4c6b (bluetoothd - a2dp.c: 270) setup_cb_free
0x0000567c394e4a94 (bluetoothd - a2dp.c: 2884) a2dp_discover
0x0000567c394e3c03 (bluetoothd - sink.c: 275) sink_setup_stream
0x0000567c394e3d4f (bluetoothd - sink.c: 299) sink_connect
0x0000567c39535183 (bluetoothd - service.c: 294) btd_service_connect
0x0000567c39539f68 (bluetoothd - device.c: 2006) connect_next
0x0000567c3954086d (bluetoothd - device.c: 2060) service_state_changed
0x0000567c39534efb (bluetoothd - service.c: 111) change_state
0x0000567c3953559c (bluetoothd - service.c: 0)
btd_service_connecting_complete
0x0000567c39534a5c (bluetoothd - profile.c: 1641) record_cb
0x0000567c395197cd (bluetoothd - sdp-client.c: 298) connect_watch
0x00007b14bc8034f6 (libglib-2.0.so.0 - gmain.c: 3337)
g_main_context_dispatch
0x00007b14bc803801 (libglib-2.0.so.0 - gmain.c: 4131)
g_main_context_iterate
0x00007b14bc803a7d (libglib-2.0.so.0 - gmain.c: 4329) g_main_loop_run
0x0000567c39566af1 (bluetoothd - mainloop-glib.c: 79) mainloop_run
0x0000567c39566ddb (bluetoothd - mainloop-notify.c: 201)
mainloop_run_with_signal
0x0000567c3954bf4c (bluetoothd - main.c: 1222) main
0x00007b14bc579797 (libc.so.6 - libc-start.c: 332) __libc_start_main
0x0000567c394df449 (bluetoothd) _start
0x00007ffd70145737

This could be triggered from a2dp_discover -> avdtp_discover ->
send_request -> send_req -> l2cap_connect (return error) ->
avdtp_set_state (to disconnect state)-> channel_remove -> channel_free
-> finalize_setup_errno (discover cb is freed) -> error handling all
the way back to a2dp_discover -> a2dp_discover (discover cb is freed
again, crashed!).

The fix is to attach cb with setup after avdtp_discover success.

Suggested-by: luiz.dentz@gmail.com
Reviewed-by: Archie Pusaka <apusaka@chromium.org>
2022-03-08 11:22:50 -08:00
Luiz Augusto von Dentz
554fcb7d89 bthost: Add support for Create BIG
This adds bthost_create_big
2022-03-07 17:21:57 -08:00
Luiz Augusto von Dentz
f040ba43d1 bthost: Add support for Periodic Advertising
This adds bthost_set_pa_params and bthost_set_pa_enable.
2022-03-07 17:21:57 -08:00
Luiz Augusto von Dentz
a473a5a47c bthost: Add support for BT_H4_ISO_PKT
This adds sending and receiving BT_H4_ISO_PKT packets.
2022-03-07 17:21:56 -08:00
Luiz Augusto von Dentz
9cbc6fc1b2 btdev: Implements BT_HCI_CMD_LE_BIG_TERM_SYNC
This sends BT_HCI_EVT_DISCONNECT_COMPLETE when handling
BT_HCI_CMD_LE_BIG_TERM_SYNC.
2022-03-07 17:18:39 -08:00
Luiz Augusto von Dentz
40bacfff0c btdev: Implements BT_HCI_CMD_LE_BIG_CREATE_SYNC
This sends BT_HCI_EVT_LE_BIG_SYNC_ESTABLISHED when handling
BT_HCI_CMD_LE_BIG_CREATE_SYNC.
2022-03-07 17:18:38 -08:00
Luiz Augusto von Dentz
9d7f4405df monitor: Rename Periodic Advertising terms to PA/pa
This renames the use of Periodic Advertising in the API to just PA.
2022-03-07 17:18:38 -08:00
Luiz Augusto von Dentz
306bc0ca76 btdev: Send BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if remote start pa
This sends BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if remote device start
to periodic advertise when BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC is
pending.
2022-03-07 17:18:37 -08:00
Luiz Augusto von Dentz
d07185ff4e btdev: Send BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED when scan is initiated
This sends BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if scan is initiated
while BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC is pending.
2022-03-07 17:18:37 -08:00
Luiz Augusto von Dentz
942a73daca btdev: Implement BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC
This adds implementation of BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC.
2022-03-07 17:18:37 -08:00
Luiz Augusto von Dentz
3250d7f938 btdev: Implement BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL
This adds implementation of
BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL generating
BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if necessary.
2022-03-07 17:18:37 -08:00
Luiz Augusto von Dentz
ea501af91c btdev: Implement BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC
This adds implementation of BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC
generating BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED and
BT_HCI_EVT_LE_PER_ADV_REPORT.
2022-03-07 17:18:36 -08:00
Luiz Augusto von Dentz
b5ab5eee3a monitor: Fix Create BIG PDU
The PDU of Create BIG is actually fixed size as the num_bis is
related to the number of indexes to be connected and not the BIS
parameters.
2022-03-07 17:18:36 -08:00
ihsinme
2f4368de81 device: Fix writing out of bounds array
%32s expect a buffer of at least 33 bytes since it is a string it needs
to be NULL terminated.
2022-03-07 16:14:23 -08:00
Andreas Kemnade
5e9342ee34 gatt: sanitize input at profile registration
Check whether type of UUIDs property of GattProfile1 object
is correct.
2022-03-07 16:12:35 -08:00
Luiz Augusto von Dentz
18af5f4faf client: Add support for scan <le/bredr>
This adds support for entering the transport directly as an scan
argument rather than having to first set it scan.transport.
2022-03-02 16:30:11 -08:00
Luiz Augusto von Dentz
b9f27b814d test-runner: Fix parsing of command line
Instead of parsing the command line, which can contain a shell script,
run using /bin/sh so it allows more complex command line to be tested:

sudo tools/test-runner -l -d -k <pathto/bzImage> --
'client/bluetoothctl power on && sleep 2 && client/bluetoothctl power
off'
2022-03-01 15:26:14 -08:00
Luiz Augusto von Dentz
ab943bf833 shared/shell: Introduce bt_shell_exec
This introduces bt_shell_exec which can be used to inject commands into
a bt_shell without using stdin/user input.
2022-02-28 15:58:29 -08:00
Luiz Augusto von Dentz
850003734a test-runner: Add option to start emulator
This adds an option (-l/--emulator) to start btvirt before processing
the command which is convenient to runs tools like bluetoothctl:

  sudo tools/test-runner -l -d -k <pathto/bzImage> --
  client/bluetoothctl power on
2022-02-28 15:26:02 -08:00
Luiz Augusto von Dentz
d91fe6994f hog-lib: Fix not waiting for UHID_START
With use of UHID_CREATE2 the code needs to wait for UHID_START in order
to know if the reports are numbered or not.

Fixes: https://github.com/bluez/bluez/issues/298
2022-02-25 15:35:04 -08:00
Luiz Augusto von Dentz
2ae3ce9e6d btproxy: Attempt to bind the next index
If no specific index is given attempt to bind the next index if the
current one is already in use.
2022-02-25 15:35:03 -08:00
Nicolas Fella
bf09e1f048 neard: Fix reading State message
dbus_message_iter_recurse only makese sense for container types, this is a string.

Fixes: https://github.com/bluez/bluez/issues/300
2022-02-24 13:57:59 -08:00
Fabrice Fontaine
58dec00edc src/shared/util.h: include sys/types.h
Include sys/types.h to avoid the following build failure on musl raised
since commit fb57ad9b9d:

In file included from src/shared/queue.c:15:
./src/shared/util.h:106:1: error: unknown type name 'ssize_t';
did you mean 'size_t'?
  106 | ssize_t util_getrandom(void *buf, size_t buflen, unsigned int flags);
      | ^~~~~~~
      | size_t

Fixes:
 - http://autobuild.buildroot.org/results/83eaeb3863040645409f5787fdbdde79385c5257
2022-02-24 13:56:30 -08:00
Fabrice Delliaux
65302d98e1 error: Fix typo
s/suuported/supported
2022-02-24 13:55:40 -08:00
Joseph Hwang
d89af9acb7 monitor: fix division by zero about conn->tx_pkt_med
In a connection without outgoing traffic, conn->tx_num will remain 0.
In this case, conn->tx_pkt_med should be simply 0 without calculating
"conn->tx_bytes / conn->tx_num".

This was likely to happen, for example, when "btmon -w btsnoop.log"
was launched in the middle of a LE mouse connection, and a number of
incoming ACL Data RX were received as the mouse movements.  When
running "btmon -a btsnoop.log", it would encounter this error.

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
Reviewed-by: Shuo-Peng Liao <deanliao@chromium.org>
2022-02-23 08:57:33 -08:00
Bastien Nocera
b086260ac6 adapter-api: Document per-client discovery sessions
The fact that each client can start its own discovery wasn't clear from
the documentation and only becomes obvious when reading the sources.
2022-02-23 08:57:23 -08:00
Luiz Augusto von Dentz
2e4627c3c9 player: Fix Track being emitted with empty metadata
This sometimes causes the Track to be schedule while some metadata are
still pending, also don't remove the Duration from track when updating
its metadata since Duration is typically updated by player status rather
than metadata.

Fixes: https://github.com/bluez/bluez/issues/291
2022-02-22 11:38:19 -08:00
Tedd Ho-Jeong An
8fe1e5e165 gobex: Fix read from pointer after free
This patch sets the pointer to null after free since the g_free(p)
doesn't set the pointer to NULL.

This is reported by the Coverity.

Fixes: 7e7d826aa1 ("gobex: Print error if data cannot be written")
2022-02-18 13:25:57 -08:00
Michael Nosthoff
51c34da9d6 Makefile.tools: remove duplicate link entry 2022-02-18 13:25:43 -08:00
Tedd Ho-Jeong An
840ca1e7f1 shared: Fix the incorrect type with bit shift
This patch fixes the following runtime error:

$ sudo ./monitor/btmon -w test.btsnoop
  Bluetooth monitor ver 5.63
  src/shared/btsnoop.c:339:18: runtime error: left shift of 65535 by 16 places cannot be represented in type 'int'
2022-02-18 13:25:31 -08:00
Luiz Augusto von Dentz
afefbb4872 main.conf: Fix parsing of mode options
This replace the use of g_key_file_get_integer, which is limited to
only decimal values, to g_key_file_get_string and then use strtol to
convert the string value to integer.

Fixes: https://github.com/bluez/bluez/issues/293
2022-02-18 13:17:00 -08:00
Luiz Augusto von Dentz
d96c2fd877 adapter: Fix allowing multiple adapters with the same address
The bdaddr of an adapter is used for its unique storage path so having
multiple adapters with the same address would likely cause problems
with its storage as they would be shared.
2022-02-16 15:16:48 -08:00
Luiz Augusto von Dentz
a1cdd683df main.conf: Introduce MaxControllers
This introduces MaxControllers which can be used to limit the number of
adapters exposed in the system.
2022-02-16 15:16:29 -08:00