Commit Graph

26288 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
33d13bbc57 hog: Add input queue while uhid device has not been created
Since report map is only read after all reports it is possible to start
receiving notifications before uhid has been created, so this adds a
queue to store the events while the report map is pending and once uhid
has been created dequeue the events.
2022-01-13 13:34:53 -08:00
Luiz Augusto von Dentz
7fe38a17f6 hog: Fix read order of attributes
The Report Map must be read after all other attributes otherwise the
Kernel driver may start using UHID_SET_REPORT which requires the
report->id to be known in order to resolve the attribute to send to.

Fixes: https://github.com/bluez/bluez/issues/220
2022-01-13 13:34:53 -08:00
Luiz Augusto von Dentz
8edd9ff4e4 media: Fix crash when endpoint replies with an error to SetConfiguration
If endpoint responds to SetConfiguration the transport is being
destroyed without removing it from the list leading a crash.

Fixes: https://github.com/bluez/bluez/issues/269
2022-01-13 13:34:53 -08:00
Inga Stotland
9761d7b1e4 tools/mesh-cfgclient: Fix config menu help message
An info message suggesting to request a remote node composition
should reference the correct menu command: "composition-get".
2022-01-12 14:34:55 -08:00
Inga Stotland
f688edd8e1 tools/mesh-cfgclient: Fix typos in config storage
Fix keyword typos and comments.
2022-01-12 14:34:55 -08:00
Luiz Augusto von Dentz
050cead360 avdtp: Fix runtime errors passing NULL to memcpy
Passing NULL to memcpy is considered undefined behavior which leads to
the following runtime errors:

profiles/audio/avdtp.c:2709:2: runtime error: null pointer passed as
argument 1, which is declared to never be null
profiles/audio/avdtp.c:2709:2: runtime error: null pointer passed as
argument 2, which is declared to never be null
profiles/audio/avdtp.c:3326:2: runtime error: null pointer passed as
argument 2, which is declared to never be null
profiles/audio/avdtp.c:500:3: runtime error: null pointer passed as
argument 2, which is declared to never be null
2022-01-07 13:28:46 -08:00
Luiz Augusto von Dentz
cfab569484 build: Replace use of g_memdup with util_memdup
This replaces the uses of g_memdup with util_memdup since the former has
been deprecated:

  warning: ‘g_memdup’ is deprecated: Use 'g_memdup2' instead
  [-Wdeprecated-declarations]

g_memdup2 requires bumping glib version which would likely have its
own problems thus why util_memdup was introduced.
2022-01-06 12:58:39 -08:00
Luiz Augusto von Dentz
9f09e69ecb shared/util: Add util_memdup
This adds util_memdup which is intended to replace g_memdup since
replacing that with g_memdup2 requires bumping the glib version.
2022-01-06 12:55:20 -08:00
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