Commit Graph

26380 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
3a53b27e4d attrib: Remove gatt-service.{c,h} and attrib-server.{c,h}
These files are not longer needed since this functionality has been
moved to gatt-db.{c,h}.
2022-01-06 12:55:12 -08:00
Luiz Augusto von Dentz
710220f861 shared/util: Rename btd_malloc to util_malloc
util functions are not limited to daemon only which is normally the case
when using btd prefix.
2022-01-05 15:53:35 -08:00
Luiz Augusto von Dentz
4a00535fa3 emulator: Add support for vendor commands
This adds support for vendor commands reserving a single opcode (0xfc10)
so it can be extended using subcommands, similar to how MSFT works.

The first subcommand (0x00) enables the emulator to generate arbitrary
events using the commands parameters:

> tools/hcitool cmd 3f 10 00 22 24 d0 d0 d0 d0 d0 d0 ff ff
< HCI Command: Vendor (0x3f|0x0010) plen 11
        00 22 24 d0 d0 d0 d0 d0 d0 ff ff
	."$........
Bluetooth: hci0: Malformed HCI Event: 0x22
> HCI Event: Inquiry Result with R.. (0x22) plen 9
        Num responses: 36
        Page scan repetition mode: Reserved (0xff)
        Page period mode: Reserved (0xff)
        Class: 0xffffd0
          Major class: Uncategorized, specific device code not specified
          Minor class: 0x34
          Limited Discoverable Mode
          invalid service class
        Clock offset: 0x6368
        RSSI: 105 dBm (0x69)
> HCI Event: Command Complete (0x0e) plen 4
      Vendor (0x3f|0x0010) ncmd 1
        Status: Success (0x00)
2022-01-05 15:06:40 -08:00
Luiz Augusto von Dentz
ac33d95d29 configure: Fix use of obsolete macros
This fixes the following warnings when using autoconf >= 2.70:

  configure.ac:19: warning: The macro `AC_LANG_C' is obsolete.
  configure.ac:45: warning: The macro `AC_HELP_STRING' is obsolete.
  configure.ac:440: warning: AC_OUTPUT should be used without arguments.

The macros are replacing following the autoconf documentation:

https://www.gnu.org/software/autoconf/manual/autoconf-2.70/html_node/Obsolete-Macros.html

Fixes: https://github.com/bluez/bluez/issues/246
2022-01-05 15:06:40 -08:00
Marcel Holtmann
da07239606 Release 5.63 2022-01-05 22:49:00 +01:00
Luiz Augusto von Dentz
401643e5c5 gattrib: Fix passing NULL to memcpy
This fixes the following runtime error:

  attrib/gattrib.c:198:2: runtime error: null pointer passed as
  argument 2, which is declared to never be null
2021-12-23 11:47:03 -08:00
Luiz Augusto von Dentz
2be0c6aa3a bootstrap-configure: Enable sanitizer options
This makes bootstrap-configure enables all sanitizers.
2021-12-23 11:46:12 -08:00
Luiz Augusto von Dentz
2be2b945e2 build: Fix build when sanitizer are enabled
This fixes various issues found when sanitizers are enabled.
2021-12-23 11:45:31 -08:00
Luiz Augusto von Dentz
4839b1135d build: Add sanitizer options
Build using Address Sanitizer (asan), Leak Sanitizer (lsan), or
Undefined Behavior Sanitizer (ubsan) by using one of these options for
the configure script:

  --enable-asan
  --enable-lsan
  --enable-ubsan

For each of these to work, the compiler must support the requested
sanitizer and the requisite libraries must be installed (libasan,
liblsan, libubsan).
2021-12-22 15:16:30 -08:00
Luiz Augusto von Dentz
32a006f92a test-hog: Add monitor support
This adds monitor support so data can properly be decoded by the likes
of btmon:

= test-hog: /TP/HGRF/RH/BV-01-I - init
= test-hog: /TP/HGRF/RH/BV-01-I - setup
= test-hog: /TP/HGRF/RH/BV-01-I - setup complete
= test-hog: /TP/HGRF/RH/BV-01-I - run
> test-hog: User Data RX
      ATT: Read By Group Type Request (0x10) len 6
        Handle range: 0x0001-0xffff
        Attribute group type: Primary Service (0x2800)
2021-12-21 12:49:57 -08:00
Luiz Augusto von Dentz
b6061ea5b8 device: Fix bogus errors on load_att_info
load_att_info would attempt to load attributes file from the storage but
in case it doesn't exists it would print an error instead of just
bailing out as attributes file is created on demand when there are
something to be stored.
2021-12-15 14:48:07 -08:00
Claudio Takahasi
d36c45c55a advertising: Fix reporting advertising properties
InterfacesAdded signal for LEAdvertisingManager1 might be emitted
containing initial/default properties values and property changed is
not emitted after reading advertising features. This patch registers
the interface (LEAdvertisingManager1) after reading advertising features
from kernel.
2021-12-15 14:26:48 -08:00
Luiz Augusto von Dentz
860af44b9d shared/gatt-client: Skip included service if it cannot be resolved
Instead of failing if the included service cannot be resolved just
skip it so doesn't fail and the discovery is stop due to a possible
application error.
2021-12-13 14:46:48 -08:00
Luiz Augusto von Dentz
58d1f5ae0f btdev: Add support for BT_HCI_CMD_LE_CREATE_CONN_CANCEL
This adds support for BT_HCI_CMD_LE_CREATE_CONN_CANCEL so it is able to
generate proper command complete.
2021-12-10 15:19:07 -08:00
Tedd Ho-Jeong An
9320da5b10 profiles/health: Replace random number generation function
This patch replaces the rand() function to the getrandom() syscall.

It was reported by the Coverity scan
  rand() should not be used for security-related applications, because
  linear congruential algorithms are too easy to break
2021-12-08 16:56:18 -08:00
Tedd Ho-Jeong An
6efadbcd07 plugins: Replace random number generation function
This patch replaces the rand() function to the getrandom() syscall.

It was reported by the Coverity scan
  rand() should not be used for security-related applications, because
  linear congruential algorithms are too easy to break
2021-12-08 16:56:18 -08:00
Tedd Ho-Jeong An
9968b0b66a tools/btgatt-server: Replace random number generation function
This patch replaces the rand() function to the getrandom() syscall.

It was reported by the Coverity scan
  rand() should not be used for security-related applications, because
  linear congruential algorithms are too easy to break
2021-12-08 16:56:18 -08:00
Tedd Ho-Jeong An
a11eea9259 peripheral: Replace random number generation function
This patch replaces the rand() function to the getrandom() syscall.

It was reported by the Coverity scan
  rand() should not be used for security-related applications, because
  linear congruential algorithms are too easy to break
2021-12-08 16:56:18 -08:00
Tedd Ho-Jeong An
df64c87022 emulator: Replace random number generation function
This patch replaces the rand() function to the getrandom() syscall.

It was reported by the Coverity scan
  rand() should not be used for security-related applications, because
  linear congruential algorithms are too easy to break
2021-12-08 16:56:17 -08:00
Ulisses Costa
433f7cce3b client/gatt: Fix property_change in WriteValue for desc
g_dbus_emit_property_changed was not working properly in the WriteValue
for the descriptor because the Characteristic interface was being used.
2021-12-07 18:48:46 -08:00
Inga Stotland
1f380468ce mesh: Don't log error for false positive mkdir failure
When invoking mkdir() for mesh configuration storage, do not
report an error if a target directory already exists.
2021-12-06 10:19:07 -08:00
Luiz Augusto von Dentz
aa361e2216 gatt: Omit MTU if not connected
If not connected there is no reason to expose the MTU as that only
valid while connected.
2021-11-29 09:59:42 -08:00
Javier de San Pedro
ebf2d79356 gatt-client: Fix disconnecting due to GattCharacteristic1.MTU
After the MTU dbus property patches in 5.62 we are seeing bluetoothd
terminate frequently with "Disconnected from D-Bus. Exiting." msgs.
Apparently this is because bluetoothd sent an invalid reply to a D-Bus
Property Get (for GattCharacteristic1's MTU).
Multiple issues in bluez Github.com project reported similar behavior;
at least #235 (see Fixes:), #219, and likely #238.

When the Characteristic1 object is still cached/alive, but the
underlying att connection is not (e.g. someone just called Disconnect),
the property getter (characteristic_get_mtu) right now returns false.
However, gdbus seems to ignore the return value and sends the empty reply
message anyway (rather than a dbus error?), and this seems to cause
the dbus connection to be terminated (due to the ill-formed reply?).
bluetoothd then aborts.

This patch makes the property value BT_ATT_DEFAULT_LE_MTU if the
underlying att object does not exist, rather than returning an invalid
message. This is consistent with the existing PropertyChanged signal
behavior (we will emit a PropertyChange only if a larger MTU is
exchanged), and fixes the issue on my machines.
An alternative could be to change gdbus behavior, but I'm not sure if we
are allowed to return an error here anyway without causing problems in
other dbus libraries/wrappers.

Fixes: aaa0c4996a ("gatt: Add implementation of GattCharacteristic1.MTU")
Fixes: https://github.com/bluez/bluez/issues/235
2021-11-29 09:54:49 -08:00
Archie Pusaka
bdf36141b0 doc: Add Name Request Fail flag in device found event
Userspace should use this new flag to decide whether to do the remote
name resolving or not.
2021-11-29 09:43:42 -08:00
Archie Pusaka
68e1c426cb main: add configurable RemoteNameRequestRetryDelay parameter
This specifies how long will the userspace ignore a peer with an
unknown name after a failed remote name resolving procedure.

The peer device can still be connected, this only prevents the remote
name resolving procedure retry.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-11-29 09:43:42 -08:00
Archie Pusaka
ee004ee7bd device: Save remote name request attempts into cache file
Since a peer device is potentially removed if not discovered for more
than 30 seconds, we would lost the remote name request activity when
the device is rediscovered. This could end up with a remote name
request much sooner than we intend it to be.

Therefore, put the RNR record into a cache file, so we can recover it
when the peer device is rediscovered.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-11-29 09:43:42 -08:00
Archie Pusaka
69c7d34744 Listen and process remote name resolving failure
When Remote Name Resolve ends with failure, record this occurrence and
prevent remote name resolving for the same device for some time.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-11-29 09:43:41 -08:00
Archie Pusaka
db31aecae0 mgmt: Add NAME_REQUEST_FAILED flag for device_found event
Report failure when resolving remote name to userspace. This is useful
so the userspace can make an informed decision when to retry name
resolving procedure.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
2021-11-29 09:43:41 -08:00
Luiz Augusto von Dentz
aa699cb762 build: Check for linux/uinput.h and linux/uhid.h
This makes configure to check the presence of linux/uinput.h and
linux/uhid.h kernel uapi headers since the code no longer contain copies
of them and otherwise the code cannot be build without them:

checking linux/uinput.h usability... yes
checking linux/uinput.h presence... yes
checking for linux/uinput.h... yes
checking linux/uhid.h usability... yes
checking linux/uhid.h presence... yes
checking for linux/uhid.h... yes
2021-11-23 13:32:12 -08:00
Tedd Ho-Jeong An
270c8d07a0 emulator: fix potential resource leak
This patch releases the allocated fd to prevent the potential resource
leak. This was reported by the Coverity scan.
2021-11-22 14:26:35 -08:00
Manish Mandlik
f59a6d4a4e core: Update default advmon Sampling_Period to 0xFF
Update default Advertisemet Monitor Sampling_Period to 0xFF. It
indicates that controller will report only one advertisement per
monitoring period for a device. This will help reduce the power
consumption drastically.

Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:05 -08:00
Manish Mandlik
85397c4acb adv_monitor: Change sampling period to uint16_t
In the Advertisement Monitor API, RSSISamplingPeriod is an unsigned
value. Change sampling_period variable to uint16_t in the code.

More info: doc/advertisement-monitor-api.txt

Reviewed-by: Archie Pusaka <apusaka@google.com>
Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:05 -08:00
Manish Mandlik
f618084077 adv_monitor: Invoke DeviceFound/Lost on tracked monitors
This patch delivers DeviceFound/DeviceLost events to apps over D-Bus
whenever controller starts/stops tracking a device.

Tests performed:
- Add a monitor and verify that DeviceFound/DeviceLost events are
  received whenever controller starts/stops monitoring.
- Verify from logs that only one Adv Report is received from the
  controller when Sampling_Period is set to 0xFF and the
  DeviceFound/DeviceLost functionality still works as intended.
- Verify that DeviceFound/DeviceLost is reported appropriately even
  when the Active Scanning is in progress.
- Verify that the reconnection also works properly with and without
  any active Advertisement Monitor.

Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:04 -08:00
Manish Mandlik
da253c54d1 adv_monitor: Receive the Device Found/Lost events
This patch registers callback functions to receive the Advertisement
Monitor Device Found and Device Lost events. It also disables software
based filtering whenever controller offloading support is available.

Test performed:
- Verified by logs that the MSFT Monitor Device is received from the
  controller and the bluetoothd is notified whenever the controller
  starts/stops monitoring a device.

Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:04 -08:00
Manish Mandlik
37caf622b8 lib: Add definitions of the Adv Monitor Device Found/Lost events
This patch adds definitions of the new Advertisement Monitor Device
Found and Device Lost events to indicate that the controller has
started/stopped tracking a particular device.

Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:04 -08:00
Manish Mandlik
415ae7733a doc: Introduce the Adv Monitor Device Found/Lost events
This patch introduces two new MGMT events
MGMT_EV_ADV_MONITOR_DEVICE_FOUND and MGMT_EV_ADV_MONITOR_DEVICE_LOST to
indicate that the controller has started/stopped tracking a particular
device matching one of the already added Advertisement Monitor.

If the controller offloading support is not available,
MGMT_EV_ADV_MONITOR_DEVICE_FOUND event is also used to report all
advertisements to perform software based filtering whenever we are not
active scanning.

Reviewed-by: Miao-chen Chou <mcchou@google.com>
2021-11-22 14:25:04 -08:00
Luiz Augusto von Dentz
b312fa0c9f uhid: Remove local copy of uhid header
uhid.h is part of kernel uapi nowadays so it can be included
directly from linux/uhid.h so this removes the local copy to use it
instead.
2021-11-22 13:49:18 -08:00
Luiz Augusto von Dentz
873109595a uinput: Remove local copy of uinput.h
uinput.h is part of kernel uapi nowadays so it can be included directly
from linux/uinput.h which has a compatible definition with 32 bits
systems:

https://github.com/bluez/bluez/issues/84#issuecomment-942155841

Fixes: https://github.com/bluez/bluez/issues/84
2021-11-22 13:49:15 -08:00
Tedd Ho-Jeong An
6ea642f6ef client: Fix uninitiailzed scalar variable
This patch fixes the uninitiailzed varialble(CWE-457) reported by
the Coverity scan.
2021-11-15 13:07:08 -08:00
Tedd Ho-Jeong An
9a79c9b74a monitor: Fix uninitiailzed scalar variable
This patch fixes the uninitiailzed varialble(CWE-457) reported by
the Coverity scan.
2021-11-15 13:07:07 -08:00
Tedd Ho-Jeong An
1722bf1258 emulator: Fix uninitiailzed scalar variable
This patch fixes the uninitiailzed varialble(CWE-457) reported by
the Coverity scan.
2021-11-15 13:07:07 -08:00
Yun-Hao Chung
927059ba60 admin: fix devices not reset
When |admin_policy_remove| is called, we set |devices| to NULL but never
set it back until |admin_init|. This makes admin lost track of current
registered device interface, so the next |admin_policy_removed| will not
be able to unregister those interfaces.

Reviewed-by: Archie Pusaka <apusaka@chromium.org>
2021-11-15 13:06:57 -08:00
Luiz Augusto von Dentz
591c546c53 shared/gatt-server: Fix heap overflow when appending prepare writes
The code shall check if the prepare writes would append more the
allowed maximum attribute length.

Fixes https://github.com/bluez/bluez/security/advisories/GHSA-479m-xcq5-9g2q
2021-11-12 14:00:31 -08:00
Luiz Augusto von Dentz
e79417ed71 sdpd: Fix leaking buffers stored in cstates cache
These buffer shall only be keep in cache for as long as they are
needed so this would cleanup any client cstates in the following
conditions:

 - There is no cstate on the response
 - No continuation can be found for cstate
 - Different request opcode
 - Respond with an error
 - Client disconnect

Fixes: https://github.com/bluez/bluez/security/advisories/GHSA-3fqg-r8j5-f5xq
2021-11-12 14:00:31 -08:00
Jefferson Zhai
44789fb8d9 tools/mesh: Add <Vendor ID> option to sub-add cmd
If the Subscription being added is a Vendor Model, there needs to be a
4th parameter. Fixes oversight of not supporting vendor model in Meshctl.
2021-11-10 16:48:08 -08:00
Luiz Augusto von Dentz
0d5013510a mgmt-tester: Add test for Device Privacy Mode flag
This tests the use of Set Device Flags to set Device Privacy Mode which
results in the following sequence:

@ MGMT Event: Command Compl.. (0x0001) plen 10  {0x0001}
      Set Device Flags (0x0050) plen 7
        Status: Success (0x00)
        LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
< HCI Command: LE Set Exten.. (0x08|0x0042) plen 6
        Extended scan: Disabled (0x00)
        Filter duplicates: Disabled (0x00)
        Duration: 0 msec (0x0000)
        Period: 0.00 sec (0x0000)
= mgmt-tester: Set Device Flags (0x0050): Success (0x00)
= mgmt-tester: Test condition complete, 4 left
= mgmt-tester: New Device Flags Changed event received
= mgmt-tester: Test condition complete, 3 left
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Extended Scan Enable (0x08|0x0042) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Addre.. (0x08|0x002d) plen 1
        Address resolution: Disabled (0x00)
= mgmt-tester: HCI Command 0x2042 length 6
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Address Resolution Enable (0x08|0x002d) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Priva.. (0x08|0x004e) plen 8
        Peer Identity address type: Public (0x00)
        Peer Identity address: BC:9A:78:56:34:12 (OUI BC-9A-78)
        Privacy Mode: Use Device Privacy (0x01)
= mgmt-tester: HCI Command 0x202d length 1
= mgmt-tester: Test condition complete, 2 left
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Privacy Mode (0x08|0x004e) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Addre.. (0x08|0x002d) plen 1
        Address resolution: Enabled (0x01)
= mgmt-tester: HCI Command 0x204e length 8
= mgmt-tester: Test condition complete, 1 left
> HCI Event: Command Complete (0x0e) plen 4
      LE Set Address Resolution Enable (0x08|0x002d) ncmd 1
        Status: Success (0x00)
< HCI Command: LE Set Exten.. (0x08|0x0041) plen 8
        Own address type: Random (0x03)
        Filter policy: Ignore not in accept list (0x01)
        PHYs: 0x01
        Entry 0: LE 1M
          Type: Passive (0x00)
          Interval: 60.000 msec (0x0060)
          Window: 30.000 msec (0x0030)
= mgmt-tester: HCI Command 0x202d length 1
= mgmt-tester: Test condition complete, 0 left
2021-11-09 14:45:51 -08:00
Luiz Augusto von Dentz
72c562e4e4 monitor: Add support for Device Privacy Mode flag
This adds proper decoding for Device Privacy Mode flag:

@ MGMT Command: Set Device... (0x0050) plen 11  {0x0001}
        LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
        Current Flags: 0x00000002
          Device Privacy Mode
@ MGMT Event: Device Flags... (0x002a) plen 15  {0x0002}
        LE Address: BC:9A:78:56:34:12 (OUI BC-9A-78)
        Supported Flags: 0x00000003
          Remote Wakeup
          Device Privacy Mode
        Current Flags: 0x00000002
          Device Privacy Mode
2021-11-09 14:45:51 -08:00
Luiz Augusto von Dentz
37be50d679 adapter: Set Device Privacy Mode
This adds support for setting Device Privacy flag when enabled in
main.conf via Privacy = device,limited-device.
2021-11-09 14:45:51 -08:00
Luiz Augusto von Dentz
20adf23209 main.conf: Rework privacy options
This reworks privacy options so the limited discoverable is only
available when controller mode is set to dual.
2021-11-09 14:45:51 -08:00
Luiz Augusto von Dentz
12cf7617ad mgmt-api: Add new Device Flag to use Device Privacy Mode
This adds a new flag to Get/Set Device Flag commands so it is possible
to set the Device Privacy Mode which allows to connect when the
remote device uses either identity or random address.
2021-11-09 14:45:51 -08:00