platform/upstream/bluez.git
2 years agoplugins/admin: add uuid duplicate check
Yun-Hao Chung [Wed, 11 Aug 2021 07:17:57 +0000 (15:17 +0800)]
plugins/admin: add uuid duplicate check

SetServiceAllowlist should ignore those duplicated UUIDs.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoclient: add AffectedByPolicy property
Yun-Hao Chung [Wed, 11 Aug 2021 07:08:57 +0000 (15:08 +0800)]
client: add AffectedByPolicy property

This prints property AffectedByPolicy in device info if
org.bluez.AdminPolicyStatus1 exists.

This also rename find_battery_by_path to find_proxies_by_path to reuse
the function.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoclient: add admin submenu and allow command
Yun-Hao Chung [Wed, 11 Aug 2021 07:08:56 +0000 (15:08 +0800)]
client: add admin submenu and allow command

This creates a menu - admin and add a commands to bluetoothctl
- allow [clear/uuid1 uuid2 ...]

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoshared/shell: fix missing stdbool in shell.h
Yun-Hao Chung [Wed, 11 Aug 2021 07:08:55 +0000 (15:08 +0800)]
shared/shell: fix missing stdbool in shell.h

bt_shell_menu_exists_t returns bool, but stdbool.h is not included.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoclient/advertising: Fix not disabling local-name in Includes
Luiz Augusto von Dentz [Tue, 10 Aug 2021 21:59:12 +0000 (14:59 -0700)]
client/advertising: Fix not disabling local-name in Includes

When setting a advertising.name other than on/off it shall also disable
local-name flag from Includes as that would cause an error when parsed
by the daemon.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoadvertising: Fix failing to advertise with Includes=local-name
Luiz Augusto von Dentz [Tue, 10 Aug 2021 21:50:16 +0000 (14:50 -0700)]
advertising: Fix failing to advertise with Includes=local-name

When local-name is set MGMT_ADV_FLAG_LOCAL_NAME would be set which would
be sent with MGMT_OP_ADD_EXT_ADV_PARAMS but latter one it would be
overwrite in generate_scan_rsp.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Make --analyze print address OUI
Luiz Augusto von Dentz [Mon, 9 Aug 2021 22:47:18 +0000 (15:47 -0700)]
monitor: Make --analyze print address OUI

This makes analyze.c use packet_print_addr which does take care of
decoding OUI portion of the address.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Make --analyze output latencies in msec
Luiz Augusto von Dentz [Fri, 6 Aug 2021 21:30:16 +0000 (14:30 -0700)]
monitor: Make --analyze output latencies in msec

Milisecconds is probably the best unit to have since it is unlikely that
the controller can respond in under 1 msec as well as most time
sensitive connection e.g. A2DP, HFP, etc, also don't expect the
latencies to be over 1 sec.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Fix not accouting for multiple outstanding packets
Luiz Augusto von Dentz [Fri, 6 Aug 2021 21:22:58 +0000 (14:22 -0700)]
monitor: Fix not accouting for multiple outstanding packets

Analyze code was not accounting for the fact that multiple outstanding
packets could be pending which will cause the last_tx to be overwritten
but its latency would be calculated against the very first packet
complete.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Fix minimun packet latency
Luiz Augusto von Dentz [Fri, 6 Aug 2021 21:05:16 +0000 (14:05 -0700)]
monitor: Fix minimun packet latency

It seems timer_sub can produce negative values leading to median packet
latency to be negative e.g conn->last_tx_compl is ahead of
conn->last_tx, in which case it should be discarded.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Fix median packet size
Luiz Augusto von Dentz [Fri, 6 Aug 2021 20:33:01 +0000 (13:33 -0700)]
monitor: Fix median packet size

Calculating the median packet based on the current median + size / 2
does not account for last packet could smaller e.g. opp transfer could
end with just 1 byte which would cut the median in a half, so this
switch to more traditional means of calculating by doing total bytes
sent / num of packets so each an every packet has the same weight.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoaudio/transport: Only store volume when also emitting DBus prop change
Marijn Suijten [Sun, 8 Aug 2021 14:35:55 +0000 (16:35 +0200)]
audio/transport: Only store volume when also emitting DBus prop change

By setting a2dp->volume early in set_volume() the resulting call to
media_transport_update_volume() when an AVRCP reply is received will
likely see the same volume received (unless the peer rounded it to
another value) and bail on equality, before emitting a DBus property
change.  This results in DBus clients not being made aware of the change
unless the peer is an audio source (that receives a notification about
changed volume, instead of a command to _set_ a new volume), where
set_volume() immediately raises the DBus signal.

This issue is observed when playing back audio to headphones through an
AbsoluteVolume-enabled audio server like PulseAudio, which does not
receive the "Volume" change (while the peer does change volume) when
setting this property externally using ie. dbus-send.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoaudio/avrcp: Use host/network order as appropriate for pdu->params_len
Marijn Suijten [Sun, 8 Aug 2021 14:35:26 +0000 (16:35 +0200)]
audio/avrcp: Use host/network order as appropriate for pdu->params_len

When comparing against or writing to pdu->params_len to enforce matching
length with total packet length, take into account that pdu->params_len
is in network order (big endian) while packet size (operand_count) is in
host order (usually little endian).

This silently breaks a number of AVRCP commands that perform a quick
length check based on params_len and bail if it doesn't match exactly.

Fixes: e2b0f0d8d ("avrcp: Fix not checking if params_len match number of received bytes")
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agodoc: Add a doc for Intel hardware variants
Tedd Ho-Jeong An [Fri, 6 Aug 2021 05:49:41 +0000 (22:49 -0700)]
doc: Add a doc for Intel hardware variants

This patch adds a document for Intel hardware variants currently
supported by the kernel and its firmware list.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Add support for tlv based version format for Intel vendor
Tedd Ho-Jeong An [Fri, 6 Aug 2021 00:43:04 +0000 (17:43 -0700)]
monitor: Add support for tlv based version format for Intel vendor

Some Intel device supports two different formats of the
HCI_Intel_Read_Version command depends on the command parameter and this
patch parses the command and response parameters depends on the format.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Add proper handling for own_address_type 0x03
Luiz Augusto von Dentz [Wed, 4 Aug 2021 00:57:38 +0000 (17:57 -0700)]
btdev: Add proper handling for own_address_type 0x03

When own_address_type is set to 0x03 the host expects the controller to
generate RPAs using the stored IRK from the resolving list and in
addition to that set the generated RPA as Local RPA in LE Enhanced
Connection Complete.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Add further stats to analzye functionality
Marcel Holtmann [Fri, 6 Aug 2021 14:15:30 +0000 (16:15 +0200)]
monitor: Add further stats to analzye functionality

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agodoc: add admin policy file storage description
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:17 +0000 (19:43 +0800)]
doc: add admin policy file storage description

This adds storage description of admin policy file in
doc/settings-storage.txt

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agodoc: add description of admin policy
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:16 +0000 (19:43 +0800)]
doc: add description of admin policy

This adds admin-policy-api.txt.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins/admin: persist policy settings
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:15 +0000 (19:43 +0800)]
plugins/admin: persist policy settings

This adds code to store the ServiceAllowlist to file
/var/lib/bluetooth/{MAC_ADDR}/admin_policy
The stored settings will be loaded upon admin_policy initialized.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins/admin: add AffectedByPolicy property
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:14 +0000 (19:43 +0800)]
plugins/admin: add AffectedByPolicy property

This adds property to indicate if a device has any service that is being
blocked by admin policy.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins/admin: add device callbacks
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:13 +0000 (19:43 +0800)]
plugins/admin: add device callbacks

This adds callbacks for device resolved and device removed. It is
necessary for implementation of "AffectedByPolicy" property since it
needs to register an interface for each device object and unregister it
once the device gets removed.

Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins/admin: add ServiceAllowList property
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:12 +0000 (19:43 +0800)]
plugins/admin: add ServiceAllowList property

This adds code to register interface org.bluez.AdminPolicyStatus.
The interface will provide read-only properties to indicate the current
settings of admin policies. We separate this from AdminPolicySet so that
normal clients can check current policy settings while only a few
clients can change policies.

This patch also adds readonly property ServiceAllowlist to
AdminPolicyStatus1, which indicates the current setting of service
allowlist.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins/admin: add ServiceAllowList method
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:11 +0000 (19:43 +0800)]
plugins/admin: add ServiceAllowList method

This adds code to register interface org.bluez.AdminPolicySet1.
The interface will provide methods to limit users to operate certain
functions of bluez, such as allow/disallow user to taggle adapter power,
or only allow users to connect services in the specified list, etc.

This patch also implements ServiceAllowlist in
org.bluez.AdminPolicySet1.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins/admin: add admin_policy adapter driver
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:10 +0000 (19:43 +0800)]
plugins/admin: add admin_policy adapter driver

This adds code to register admin_policy driver to adapter when
admin plugin is enabled.

The following test steps were performed:
1. restart bluetoothd
2. check if "Admin Policy is enabled" in system log

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoplugins: new plugin
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:09 +0000 (19:43 +0800)]
plugins: new plugin

This adds an initial code for a new plugin admin.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agocore: block not allowed UUID connect in auth
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:08 +0000 (19:43 +0800)]
core: block not allowed UUID connect in auth

This ensures any incoming profile connection will be blocked if its UUID
is not allowed by the following assumption:

1. Each system profile asks adapter authorization when seeing a incoming
   connection.
2. Each external profile checks if its UUID is allowed by adapter when
   seeing a incoming connection.

Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agocore: add adapter and device allowed_uuid functions
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:07 +0000 (19:43 +0800)]
core: add adapter and device allowed_uuid functions

This implements functions in src/adapter.c and src/device.c for
plugins setting a list of allowed services.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agocore: add device callbacks to adapter driver
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:06 +0000 (19:43 +0800)]
core: add device callbacks to adapter driver

This adds the following callbacks to btd_adapter_driver.

device_added:    called when a device is added to the adapter
device_removed:  called when a device is removed from the adapter
device_resolved: called when all services of the device have been
                 resolved.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agocore: add is_allowed property in btd_service
Yun-Hao Chung [Tue, 3 Aug 2021 11:43:05 +0000 (19:43 +0800)]
core: add is_allowed property in btd_service

This adds is_allowed property in btd_service. When is_allowed is set to
false, calling btd_service_connect and service_accept will fail and the
existing service connection gets disconnected.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoa2dp: Invalidate cache if SetConfiguration fails
Luiz Augusto von Dentz [Tue, 3 Aug 2021 01:13:19 +0000 (18:13 -0700)]
a2dp: Invalidate cache if SetConfiguration fails

If SetConfiguration fails with Unsupported Configuration it might
indicate that either the capabilities stored are incorrect or the seid
may have changed, so this attempt to invalidate the remote seps loaded
from cache when that happens so the next time there is an attempt to
discover this will force Get(All)Capabilities to be called and cause
the cache to be updated.

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

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Fix truncated server socket path parameter
Mariusz Skamra [Wed, 4 Aug 2021 10:54:46 +0000 (12:54 +0200)]
monitor: Fix truncated server socket path parameter

This fixes the issue of --server <socket> parameter
last character was dropped. There is no need to use
strncpy, as the length is already checked, and it is
known that the destination buffer is big enough

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Track connections for analyze function
Marcel Holtmann [Tue, 3 Aug 2021 21:28:55 +0000 (23:28 +0200)]
monitor: Track connections for analyze function

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Remove unneeded fprintf for new devices
Marcel Holtmann [Tue, 3 Aug 2021 19:55:00 +0000 (21:55 +0200)]
monitor: Remove unneeded fprintf for new devices

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Count number of control messages
Marcel Holtmann [Tue, 3 Aug 2021 15:04:47 +0000 (17:04 +0200)]
monitor: Count number of control messages

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Add ISO packets to analyze option
Marcel Holtmann [Tue, 3 Aug 2021 14:58:41 +0000 (16:58 +0200)]
monitor: Add ISO packets to analyze option

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Remove unneeded fprintf for unknown opcodes
Marcel Holtmann [Tue, 3 Aug 2021 14:54:03 +0000 (16:54 +0200)]
monitor: Remove unneeded fprintf for unknown opcodes

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agogatt-db: remove redundant check in foreach range
Yun-Hao Chung [Thu, 29 Jul 2021 03:36:00 +0000 (11:36 +0800)]
gatt-db: remove redundant check in foreach range

svc_start < foreach_data->end has already been checked in a few lines
before.

Reviewed-by: Archie Pusaka <apusaka@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomain.conf: Revert default for Privacy and Experimental
Luiz Augusto von Dentz [Thu, 29 Jul 2021 21:09:17 +0000 (14:09 -0700)]
main.conf: Revert default for Privacy and Experimental

Privacy shall be off by default until kernel is stable to support it,
also Experimental shall only be enabled for testing purpose.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Print EIR of Extended Advertisement Report
Sonny Sasaka [Thu, 15 Jul 2021 00:35:21 +0000 (17:35 -0700)]
monitor: Print EIR of Extended Advertisement Report

It's useful to be able to see Extended Adv's EIR flags just like the
legacy Adv.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agogatt: Add support for Central Address Resolution characteristic
Luiz Augusto von Dentz [Wed, 28 Jul 2021 20:44:44 +0000 (13:44 -0700)]
gatt: Add support for Central Address Resolution characteristic

This adds Central Address Resolution characteristic so peripherals can
use directed advertising using RPA as initiator address.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoadapter: Fix storing discoverable setting
Luiz Augusto von Dentz [Thu, 24 Jun 2021 23:32:04 +0000 (16:32 -0700)]
adapter: Fix storing discoverable setting

discoverable setting shall only be store when changed via Discoverable
property and not when discovery client set it as that be considered
temporary just for the lifetime of the discovery.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoobexd: phonebook: Set default apparams for PTS clients
Hannu Mallat [Fri, 23 Jul 2021 13:58:24 +0000 (15:58 +0200)]
obexd: phonebook: Set default apparams for PTS clients

Some PTS clients do not send all the mandatory apparams
when retrieving the phonebook. Clients such as car multimedia systems
cannot be fixed, therefore working around this issue by inserting
default apparams which makes these clients work as well.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoobexd: phonebook-ebook: modernize
Dylan Van Assche [Fri, 23 Jul 2021 13:58:21 +0000 (15:58 +0200)]
obexd: phonebook-ebook: modernize

Modernize PBAP phonebook-ebook plugin for newer libebook version
of the Evolution Data Server.

The ebook plugin was introduced during GSoC 2011 [1] and allows
BlueZ to share contacts stored in the Evolution Data Server to
connected clients such as car multimedia systems.
With the rise of Mobile Linux thanks to the PinePhone and Librem 5,
this plugin was modernized to compile with newer libebook versions
because the API was changed [2].

[1] http://www.bluez.org/gsoc-eds-backend-of-phonebook-access-profilepbap/
[2] https://wiki.gnome.org/Apps/Evolution/ESourceMigrationGuide

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools: btmgmt: support quality experiment feature command
Joseph Hwang [Thu, 15 Jul 2021 09:50:18 +0000 (17:50 +0800)]
tools: btmgmt: support quality experiment feature command

This patch adds the "exp-quality" command to btmgmt to enable/disable
the Bluetooth quality report.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoadapter: read quality report feature
Joseph Hwang [Thu, 15 Jul 2021 09:50:17 +0000 (17:50 +0800)]
adapter: read quality report feature

This patch adds a new UUID for the quality report experimental
feature. When reading the experimental features, it checks if
the new feature is supported by the controller and stores the
value in the quality_report_supported flag of the adapter.

The quality_report_supported flag could be used by the bluetoothd
to determine if the quality report feature can be enabled.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: add new Intel extended telemetry events
Joseph Hwang [Thu, 15 Jul 2021 09:50:16 +0000 (17:50 +0800)]
monitor: add new Intel extended telemetry events

This patch adds new Intel extended telemetry events for both ACL and
SCO/eSCO audio link quality reports.

For SCO/eSCO audio link quality report, it shows something like
> HCI Event: Vendor (0xff) plen 190  #120 [hci0] 2021-05-31 20:27:50.257
        Vendor Prefix (0x8780)
      Intel Extended Telemetry (0x87)
        Extended Telemetry (0x80): SubOpcode (0x03)
        Extended event type (0x01): Audio Link Quality Report Type(0x05)
        SCO/eSCO connection handle (0x6a): 0x0101
        Packets from host (0x6b): 399
        Tx packets (0x6c): 403
        Rx payload lost (0x6d): 3
        Tx payload lost (0x6e): 0
        Rx No SYNC errors (0x6f): 3 2 3 3 0
        Rx HEC errors (0x70): 0 0 0 0 0
        Rx CRC errors (0x71): 2 0 0 0 0
        Rx NAK errors (0x72): 6 0 0 0 0
        Failed Tx due to Wifi coex (0x73): 6 0 0 0 0
        Failed Rx due to Wifi coex (0x74): 0 0 0 0 0
        Late samples inserted based on CDC (0x75): 0
        Samples dropped (0x76): 0
        Mute samples sent at initial connection (0x77): 0
        PLC injection data (0x78): 0

For ACL audio link quality report, it shows something like
> HCI Event: Vendor (0xff) plen 142  #120 [hci0] 2021-05-31 20:27:50.261
        Vendor Prefix (0x8780)
      Intel Extended Telemetry (0x87)
        Extended Telemetry (0x80): SubOpcode (0x03)
        Extended event type (0x01): Audio Link Quality Report Type(0x05)
        ACL connection handle (0x4a): 0x0100
        Rx HEC errors (0x4b): 0
        Rx CRC errors (0x4c): 0
        Packets from host (0x4d): 100
        Tx packets (0x4e): 101
        Tx packets 0 retries (0x4f): 89
        Tx packets 1 retries (0x50): 11
        Tx packets 2 retries (0x51): 1
        Tx packets 3 retries (0x52): 0
        Tx packets 4 retries and more (0x53): 0
        Tx DH1 packets (0x54): 0
        Tx DH3 packets (0x55): 0
        Tx DH5 packets (0x56): 0
        Tx 2DH1 packets (0x57): 0
        Tx 2DH3 packets (0x58): 0
        Tx 2DH5 packets (0x59): 0
        Tx 3DH1 packets (0x5a): 6
        Tx 3DH3 packets (0x5b): 0
        Tx 3DH5 packets (0x5c): 94
        Rx packets (0x5d): 272
        ACL link throughput (KBps) (0x5e): 343815
        ACL max packet latency (ms) (0x5f): 20625
        ACL avg packet latency (ms) (0x60): 12

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agocore: fix a possible crash when removing devices
Yun-Hao Chung [Tue, 20 Jul 2021 11:51:37 +0000 (19:51 +0800)]
core: fix a possible crash when removing devices

In probe_service, if the service already exists in device->services, it
returns the service. This might cause dev_probe and device_probe_profile
to add a duplicate service into device->services. When removing the
device, a double-free error might occur.

This patch changes the logic of probe_service so that the same service
will not be added to a device.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Fix not checking conditions for LE Set Random Address
Luiz Augusto von Dentz [Fri, 16 Jul 2021 20:27:16 +0000 (13:27 -0700)]
btdev: Fix not checking conditions for LE Set Random Address

The spec says LE Set Random Address cannot be used when scan is enabled
or with legacy advertising:

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2480

  'If the Host issues this command when any of advertising (created
  using legacy advertising commands), scanning, or initiating are
  enabled, the Controller shall return the error code Command
  Disallowed (0x0C).'

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Add proper checks for own_addr_type for LE scan/adv
Luiz Augusto von Dentz [Wed, 14 Jul 2021 22:44:10 +0000 (15:44 -0700)]
btdev: Add proper checks for own_addr_type for LE scan/adv

own_addr_type 0x01 and 0x03 shall check that a random address has
properly been set:

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2496:

  'If LE_Scan_Enable is set to 0x01, the scanning parameters'
  Own_Address_Type parameter is set to 0x01 or 0x03, and the random
  ddress for the device has not been initialized, the Controller shall
  return the error code Invalid HCI Command Parameters (0x12).'

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2614:

  'If Enable is set to 0x01, the scanning parameters' Own_Address_Type
  parameter is set to 0x01 or 0x03, and the random address for the
  device has not been initialized, the Controller shall return the
  error code Invalid HCI Command Parameters (0x12).'

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotool/mgmt-tester: Add fail_tolerant exception
Brian Gix [Wed, 14 Jul 2021 22:03:56 +0000 (15:03 -0700)]
tool/mgmt-tester: Add fail_tolerant exception

Race conditions with the cmd-sync changes can cause fail status codes to
be different than originally expected. New test parameter fail_tolerant
allows a trivial fail-code mismatches to "Pass" while also warning that
the status wasn't exactly as expected.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotool/mgmt-tester: Add test cases for Read Clock Information API
Brian Gix [Sat, 10 Jul 2021 00:38:01 +0000 (17:38 -0700)]
tool/mgmt-tester: Add test cases for Read Clock Information API

This patch adds test cases for Read Clock Information management API.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoemulator/btdev: Add support HCI_READ_CLOCK command
Tedd Ho-Jeong An [Sat, 10 Jul 2021 00:38:00 +0000 (17:38 -0700)]
emulator/btdev: Add support HCI_READ_CLOCK command

This patch adds support HCI_READ_CLOCK command in btdev.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoa2dp: Fix crash in channel_free while waiting cmd resp
Yun-Hao Chung [Wed, 14 Jul 2021 09:02:03 +0000 (17:02 +0800)]
a2dp: Fix crash in channel_free while waiting cmd resp

When channel_free is called and we are waiting for a command response
from the peer, bluez NULL the setup->session but would not free its
setup_cb. Since setup_cb holds a ref of setup, the setup wouldn't be
freed and if service_removed is called after channel_free, a2dp_cancel
tries to abort the ongoing avdtp commands, which accesses the
setup->session and triggers a crash.

This change finalizes all avdtp commands before assigning setup->session
to NULL in channel_free.

Crash stack trace:
0x000059f01943e688 (bluetoothd -avdtp.c:3690)
avdtp_abort
0x000059f01943928a (bluetoothd -a2dp.c:3069)
a2dp_cancel
0x000059f0194377fa (bluetoothd -sink.c:324)
sink_unregister
0x000059f01948715a (bluetoothd -service.c:177)
service_remove
0x000059f01948d77c (bluetoothd -device.c:5346)
device_remove
0x000059f019476d14 (bluetoothd -adapter.c:7202)
adapter_remove
0x000059f019476c3e (bluetoothd -adapter.c:10827)
adapter_cleanup
0x000059f01949d8d7 (bluetoothd -main.c:1114) main
0x0000787b36185d74 (libc.so.6 -libc-start.c:308)
__libc_start_main
0x000059f019433e39 (bluetoothd + 0x00026e39) _start
0x00007fff2d2c0127

Reviewed-by: Archie Pusaka <apusaka@chromium.org>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Add proper checks for own_addr_type for extended advertising
Luiz Augusto von Dentz [Fri, 9 Jul 2021 23:34:47 +0000 (16:34 -0700)]
btdev: Add proper checks for own_addr_type for extended advertising

own_addr_type 0x01 and 0x03 shall check that a random address has
properly been set and in case of 0x03 the resolving list actually
contains the irk of the identity address:

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2596

  'If the advertising set's Own_Address_Type parameter is set to 0x01
  and the random address for the advertising set has not been
  initialized, the Controller shall return the error code Invalid HCI
  Command Parameters (0x12).'

BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E
page 2597

  'If the advertising set's Own_Address_Type parameter is set to 0x03,
  the controller's resolving list did not contain a matching entry, and
  the random address for the advertising set has not been initialized,
  the Controller shall return the error code Invalid HCI Command
  Parameters (0x12).'

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agosrc/adv_monitor: Remove checking in device lost timeout
Yun-Hao Chung [Mon, 28 Jun 2021 03:35:42 +0000 (11:35 +0800)]
src/adv_monitor: Remove checking in device lost timeout

The time check in device lost timeout could cause DeviceLost never being
reported because of the following reasons:

1. Timer created in timeout_add_seconds, which calls
   g_timeout_add_seconds_full internally, can be fired one second
   earlier than |timeout| seconds.
2. When handle_device_lost_timeout is invoked early, time diff between
   |curr_time| and |last_seen| could be less than |low_rssi_timeout|. In
   this case, since handle_device_lost always returns FALSE, the
   timer will be removed, but DeviceLost has not been reported yet.
3. If we never receives any advertisement from that peer since then,
   DeviceLost will never be reported.

We can remove the checking in handle_device_lost_time because we restart
or remove the timer whenever an advertisement is received.

Reviewed-by: apusaka@chromium.org
Reviewed-by: mcchou@chromium.org
Reviewed-by: mmandlik@chromium.org
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoRelease 5.60
Marcel Holtmann [Wed, 7 Jul 2021 13:42:45 +0000 (15:42 +0200)]
Release 5.60

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoprofile: Fail RegisterProfile if UUID already exists
João Paulo Rechi Vita [Fri, 11 Jun 2021 02:06:49 +0000 (19:06 -0700)]
profile: Fail RegisterProfile if UUID already exists

If a process tries to register a profile implementation that is already
registered, RegisterProfile should fail.

This should help address issues when two instances of PulseAudio are
running at the same time, and the second instance tries to register an
audio profile implementation that has already been registered by the
first instance. Two situations where this may happen is when more than
one user is logged in, or during the transition between the GDM session
and the user session, when PulseAudio gets started on the new session
before the old session has been fully terminated.

https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/303
https://gitlab.gnome.org/GNOME/gdm/-/issues/486
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoemulator/btdev: clean up the queue before closing the test
Tedd Ho-Jeong An [Sat, 26 Jun 2021 06:30:09 +0000 (23:30 -0700)]
emulator/btdev: clean up the queue before closing the test

This patch clean up the queue for connection before closing the test to
prevent the potential memory leak.

==50== 32 bytes in 1 blocks are definitely lost in loss record 18 of 32
==50==    at 0x483A809: malloc (vg_replace_malloc.c:307)
==50==    by 0x14A37E: btd_malloc (util.c:33)
==50==    by 0x149D9D: queue_new (queue.c:47)
==50==    by 0x13B3C0: btdev_create (btdev.c:6042)
==50==    by 0x13178E: create_vhci (hciemu.c:229)
==50==    by 0x13178E: hciemu_new_num (hciemu.c:403)
==50==    by 0x130E2C: read_index_list_callback (mgmt-tester.c:357)
==50==    by 0x14AD91: request_complete (mgmt.c:264)
==50==    by 0x14BD34: can_read_data (mgmt.c:356)
==50==    by 0x14E794: watch_callback (io-glib.c:157)
==50==    by 0x48B578E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5B17: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5E32: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==
==50== 32 bytes in 1 blocks are definitely lost in loss record 19 of 32
==50==    at 0x483A809: malloc (vg_replace_malloc.c:307)
==50==    by 0x14A37E: btd_malloc (util.c:33)
==50==    by 0x149D9D: queue_new (queue.c:47)
==50==    by 0x13B3C0: btdev_create (btdev.c:6042)
==50==    by 0x1318F7: hciemu_client_new (hciemu.c:332)
==50==    by 0x1318F7: hciemu_new_num (hciemu.c:412)
==50==    by 0x130E2C: read_index_list_callback (mgmt-tester.c:357)
==50==    by 0x14AD91: request_complete (mgmt.c:264)
==50==    by 0x14BD34: can_read_data (mgmt.c:356)
==50==    by 0x14E794: watch_callback (io-glib.c:157)
==50==    by 0x48B578E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5B17: ??? (in /usr/lib64/libglib-2.0.so.0.6400.6)
==50==    by 0x48B5E32: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.6)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotest-runner: Use src/main.conf if available
Luiz Augusto von Dentz [Mon, 28 Jun 2021 20:43:03 +0000 (13:43 -0700)]
test-runner: Use src/main.conf if available

This makes use of src/main.conf as configuration file that way custom
options can be applied while running the daemon.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoshared/gatt-client: Fix GATT client attribute read with offset
Howard Chung [Mon, 28 Dec 2020 06:22:36 +0000 (14:22 +0800)]
shared/gatt-client: Fix GATT client attribute read with offset

bluez always replies the whole value despite a user specify the offset.
This patch fixes the issue.

Reviewed-by: sonnysasaka@chromium.org
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoadapter: Fix toggling of experimental features
Luiz Augusto von Dentz [Thu, 24 Jun 2021 22:01:50 +0000 (15:01 -0700)]
adapter: Fix toggling of experimental features

When toggling experimental features it may cause the old value to still
be in effect since it was read after read info which upon completion
would attempt to call adapter_register without first updating the
experimental features which could affect the likes of advertising
instances when LL Privacy is enabled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agodoc/advmon-api: Clarify Patterns property
David Lechner [Thu, 24 Jun 2021 17:44:01 +0000 (12:44 -0500)]
doc/advmon-api: Clarify Patterns property

The Patterns property description was not as clear as it could be. This
expands the text a bit, replaces the C enum value 0x01 with the D-Bus
property string value "or_patterns" and improves the grammar in a few
places.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoadv_monitor: Avoid skipping non-discoverable dev on Monitor match
Manish Mandlik [Fri, 18 Jun 2021 04:58:06 +0000 (21:58 -0700)]
adv_monitor: Avoid skipping non-discoverable dev on Monitor match

Do no skip a non-discoverable device if it matches any Advertisement
Monitor.

Reviewed-by: mcchou@google.com
Reviewed-by: alainmichaud@google.com
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomedia: Fix UnregisterApplication
Luiz Augusto von Dentz [Wed, 23 Jun 2021 22:42:39 +0000 (15:42 -0700)]
media: Fix UnregisterApplication

UnregisterApplication is not doing anything since the apps queue is
never initialized which results in not finding any application when
unregistering.

Fixes: https://github.com/bluez/bluez/issues/126
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agorfkill: Fix reading from rfkill socket
Benjamin Berg [Mon, 3 May 2021 13:12:10 +0000 (15:12 +0200)]
rfkill: Fix reading from rfkill socket

The kernel will always send exactly one event, but the size of the
passed struct will depend on the length of the submitted read() and the
kernel version. i.e. the interface can be extended and we need to expect
for a read to be longer than expected if we ask for it.

Fix this by only requesting the needed length and explicitly check the
length against the V1 version of the structure to make the code a bit
more future proof in case the internal copy of the struct is updated to
contain new fields.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Update to support multiple extended adv instances
Tedd Ho-Jeong An [Wed, 23 Jun 2021 04:49:44 +0000 (21:49 -0700)]
tools/mgmt-tester: Update to support multiple extended adv instances

This patch updates to align with the multiple extended advertising
support.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoemulator/bthost: Create ext adv params before setting adv data
Tedd Ho-Jeong An [Wed, 23 Jun 2021 04:49:43 +0000 (21:49 -0700)]
emulator/bthost: Create ext adv params before setting adv data

Based on the SPEC 5.2 Vol 4, Part E, Section 7.8.54, the
LE_Set_Extended_Advertising_Data_Command may be issued after an
advertising set identifed by the Advertising_Handle has been created
using the HCI_LE_Set_Extended_Advertising_Parameters command.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoemulator/btdev: Add support HCI LE Adv Set Terminated event
Luiz Augusto von Dentz [Wed, 23 Jun 2021 04:49:42 +0000 (21:49 -0700)]
emulator/btdev: Add support HCI LE Adv Set Terminated event

This patch adds support the HCI_LE_Advertising_Set_Terminated event in
btdev.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoemulator/btdev: Add support multiple instance of extended advertising
Tedd Ho-Jeong An [Wed, 23 Jun 2021 04:49:41 +0000 (21:49 -0700)]
emulator/btdev: Add support multiple instance of extended advertising

This patch adds support multiple instance of extended advertising.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Enable High-Speed(HS) test cases
Tedd Ho-Jeong An [Wed, 23 Jun 2021 04:49:40 +0000 (21:49 -0700)]
tools/mgmt-tester: Enable High-Speed(HS) test cases

This patch enables the BT High-Speed(HS) test cases by enabling the HS
in the kernel config.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agodevice: Fix enabling temporary timer when TemporaryTimeout=0
Luiz Augusto von Dentz [Fri, 18 Jun 2021 17:09:14 +0000 (10:09 -0700)]
device: Fix enabling temporary timer when TemporaryTimeout=0

When TemporaryTimeout is set to 0 it is supposed to disable the
temporary timeout so devices never desappear.

Fixes: https://github.com/bluez/bluez/issues/146
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoavdtp: Fix parsing capabilities
Archie Pusaka [Thu, 17 Jun 2021 00:53:34 +0000 (08:53 +0800)]
avdtp: Fix parsing capabilities

This patch fixes size comparison and variable misassignment.

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Michael Sun <michaelfsun@google.com>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Adding missing device found flag in the parser
Alain Michaud [Wed, 16 Jun 2021 12:42:29 +0000 (12:42 +0000)]
monitor: Adding missing device found flag in the parser

A new flag was added to the kernel implementation of the Device Found
event, but had not been added to the parser leading to an "Unknown device
flag" error in btmon.

Reviewed-by: Yu Liu <yudiliu@google.com>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agogatt-client: Check length of notify multiple op
Sebastian Urban [Fri, 11 Jun 2021 12:30:21 +0000 (14:30 +0200)]
gatt-client: Check length of notify multiple op

Check that specfied length of value in received data does not exceed
length of PDU. Otherwise data may be read from beyond the end of the
buffer.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomgmt-tester: Fix typo
Luiz Augusto von Dentz [Wed, 16 Jun 2021 15:18:40 +0000 (08:18 -0700)]
mgmt-tester: Fix typo

This fixes debup typo.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomonitor: Fix typos
Luiz Augusto von Dentz [Tue, 15 Jun 2021 22:30:15 +0000 (15:30 -0700)]
monitor: Fix typos

This fixes interval typos.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agodoc: Add initial draft of security bugs handling document
Marcel Holtmann [Tue, 15 Jun 2021 20:12:16 +0000 (22:12 +0200)]
doc: Add initial draft of security bugs handling document

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agogatt-database: No multiple calls to AcquireWrite
Sebastian Urban [Sat, 12 Jun 2021 09:56:01 +0000 (11:56 +0200)]
gatt-database: No multiple calls to AcquireWrite

This checks if an outstanding call to AcquireWrite is already in
progress. If so, the write request is placed into the queue, but
AcquireWrite is not called again. When a response to AcquireWrite is
received, acquire_write_reply sends all queued writes over the acquired
socket.

Making multiple simultaneous calls to AcquireWrite makes no sense,
as this would open multiple socket pairs and only the last returned
socket would be used for further writes.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agogatt-server: Flush notify multiple buffer when full and fix overflow
Sebastian Urban [Sun, 13 Jun 2021 10:39:18 +0000 (12:39 +0200)]
gatt-server: Flush notify multiple buffer when full and fix overflow

This fixes the calculation of available buffer space in
bt_gatt_server_send_notification and sends pending notifications
immediately when there is no more room to add a notification.

Previously there was a buffer overflow caused by incorrect calculation
of available buffer space: data->offset can equal data->len
from a previous call to this function, leading
(data->len - data->offset) to underflow after data->offset += 2.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomgmt-tester: Enable Kernel Debug Experimental Feature
Luiz Augusto von Dentz [Mon, 14 Jun 2021 17:24:01 +0000 (10:24 -0700)]
mgmt-tester: Enable Kernel Debug Experimental Feature

This attempts to enable Kernel Debug Experimental Feature if debug is
enabled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoRelease 5.59
Marcel Holtmann [Sun, 13 Jun 2021 19:55:15 +0000 (21:55 +0200)]
Release 5.59

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoRevert "doc/mgmt-api - Add a new error code for HCI status 0x3e"
Marcel Holtmann [Sun, 13 Jun 2021 19:53:35 +0000 (21:53 +0200)]
Revert "doc/mgmt-api - Add a new error code for HCI status 0x3e"

This reverts commit 9ad67264d97b882fa58391982ecb5b003368fef0.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agomgmt-tester: Fix adding padding for Ext Adv (Scan Response) Data
Luiz Augusto von Dentz [Wed, 9 Jun 2021 21:22:42 +0000 (14:22 -0700)]
mgmt-tester: Fix adding padding for Ext Adv (Scan Response) Data

These commands are actually of variable size so they don't expect
padding like in the non-extended version.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Check advertising/scanning states when changing Resolving List
Luiz Augusto von Dentz [Mon, 7 Jun 2021 17:43:59 +0000 (10:43 -0700)]
btdev: Check advertising/scanning states when changing Resolving List

Resolving List cannot be changed when advertising/scanning:

• Advertising (other than periodic advertising) is enabled,
• Scanning is enabled, or
• an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or
HCI_LE_Periodic_Advertising_Create_Sync command is outstanding.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Check advertising/scanning states when changing White List
Luiz Augusto von Dentz [Mon, 7 Jun 2021 17:34:29 +0000 (10:34 -0700)]
btdev: Check advertising/scanning states when changing White List

White List cannot be changed when advertising/scanning:

• any advertising filter policy uses the White List and advertising is
enabled,
• the scanning filter policy uses the White List and scanning is
enabled, or
• the initiator filter policy uses the White List and an
HCI_LE_Create_Connection or HCI_LE_Extended_Create_Connection
command is outstanding.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Remove debugs
Luiz Augusto von Dentz [Fri, 4 Jun 2021 23:26:28 +0000 (16:26 -0700)]
btdev: Remove debugs

Remove left-over util_debugs.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Fix expected HCI command accounting
Inga Stotland [Fri, 4 Jun 2021 17:59:13 +0000 (10:59 -0700)]
tools/mgmt-tester: Fix expected HCI command accounting

This fixes test condition count in the expected HCI command
callback.

When the expected HCI opcode is detected, mark the condition
as done. Any subsequent HCI commands are ignored.

Without this fix, in couple of test cases where the expected HCI
command is detected more than once, the test may be erroneously
reported as a failure or prematurely declared as a success before
waiting on an expected MGMT event condition.

The test cases where this behavior is fixed:
Remove Ext Advertising - Success 1
Remove Ext Advertising - Success 2
Reviewed-by: Tedd Ho-Jeong An <tedd.an@intel.com>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoshared/mgmt: Fix not processing request queue
Luiz Augusto von Dentz [Fri, 4 Jun 2021 21:28:38 +0000 (14:28 -0700)]
shared/mgmt: Fix not processing request queue

If the kernel returns an invalid opcode like below the request won't
be processed making it unusable:

@ MGMT Command: Read Advertising Features (0x003d) plen 0
{0x0001} [hci0] 14:25:11.096370
@ MGMT Event: Command Status (0x0002) plen 3
{0x0001} [hci0] 14:25:11.096373
      Set Advertising (0x0029)
              Status: Not Supported (0x0c)

In order to fix this attempts to remove the first request pending on the
given index:

= bluetoothd: src/advertising.c:read_adv_features_callback() Failed to
read advertising features: Not Supported (0x0c)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Fix handling of white/resolving list
Luiz Augusto von Dentz [Fri, 4 Jun 2021 19:16:23 +0000 (12:16 -0700)]
btdev: Fix handling of white/resolving list

le_cig.cis entries was not properly checked which could lead to
overwriting le_wl/le_rl field.

While at it this also makes changes so have proper struct/fields for
le_wl and le_rl so they easier to manage.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agobtdev: Fix crash when generating disconnected event for BIS
Luiz Augusto von Dentz [Fri, 4 Jun 2021 00:07:26 +0000 (17:07 -0700)]
btdev: Fix crash when generating disconnected event for BIS

When generating disconnected event for a BIS it would not have any
link as the ISO is in fact we are broadcasting and don't have an ACL.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Add setup condition to resolve list
Inga Stotland [Thu, 3 Jun 2021 00:04:16 +0000 (17:04 -0700)]
tools/mgmt-tester: Add setup condition to resolve list

This adds expected setup HCI command condition to
"Start Discovery - Disable Resolve List" case.

Check that on setup HCI command Set LE Resolve Enable is complete
with "enable" parameter set to 1.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Adjust test setup complete check
Inga Stotland [Thu, 3 Jun 2021 00:04:15 +0000 (17:04 -0700)]
tools/mgmt-tester: Adjust test setup complete check

This changes check for setup complete in client_cmd_complete() callback
from tester_setup_complete() to test_setup_condition_complete(). This
allows for combining setup conditions when setup_bthost() is called.
Reviewed-by: Tedd Ho-Jeong An <tedd.an@intel.com>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Add tests for whitelist and resolving list
Tedd Ho-Jeong An [Tue, 1 Jun 2021 20:49:18 +0000 (13:49 -0700)]
tools/mgmt-tester: Add tests for whitelist and resolving list

This patch adds test cases for checking the whitelist and resolving list
HCI commands when the LL Privacy feature is enabled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Add tests for experimental feature command
Tedd Ho-Jeong An [Tue, 1 Jun 2021 20:49:17 +0000 (13:49 -0700)]
tools/mgmt-tester: Add tests for experimental feature command

This patch adds test cases for Read/Set Experimenal Feature commands.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agoemulator/btdev: Enable LE Privacy feature
Tedd Ho-Jeong An [Tue, 1 Jun 2021 20:49:16 +0000 (13:49 -0700)]
emulator/btdev: Enable LE Privacy feature

This patch enables LE Privacy to support LL Privacy feature.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Add test cases for get/set device flags
Tedd Ho-Jeong An [Wed, 26 May 2021 05:13:10 +0000 (22:13 -0700)]
tools/mgmt-tester: Add test cases for get/set device flags

This patch adds test cases for get/set device flags commands.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/mgmt-tester: Print hexdump if mgmt event parameters not match
Tedd Ho-Jeong An [Wed, 26 May 2021 05:13:09 +0000 (22:13 -0700)]
tools/mgmt-tester: Print hexdump if mgmt event parameters not match

This patch displays the hexdump of expected and received mgmt event
parameters.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agolib: Align mgmt header with document
Tedd Ho-Jeong An [Wed, 26 May 2021 05:13:08 +0000 (22:13 -0700)]
lib: Align mgmt header with document

This patch updates the mgmt header to align with the mgmt api document
(doc/mgmt-api.txt)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
2 years agotools/btmgmt: Add device flags commands
Tedd Ho-Jeong An [Wed, 26 May 2021 05:13:07 +0000 (22:13 -0700)]
tools/btmgmt: Add device flags commands

This patch adds commands for get/set device flags mgmt ops.

Usage:

get-flags [-t type] <address>
        -t type    Address Type
                      0 BR/EDR
                      1 LE Public
                      2 LE Random

set-flags [-f flags] [-t type] <address>
        -t type    Address Type
                      0 BR/EDR
                      1 LE Public
                      2 LE Random
        -f flags   Device flag.
                      1 Remote Wake Enable

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>