platform/upstream/bluez.git
3 years agoavrcp: include all player settings in notif event
Howard Chung [Wed, 5 Aug 2020 02:05:36 +0000 (10:05 +0800)]
avrcp: include all player settings in notif event

According to AVRCP 1.6.2 spec section 6.7.2 table 6.39, all player
application settings should be returned to the CT and let CT to
determine which settings have changed. Currently bluez only returns
the changed attribute instead. This patch also addresses a potential
issue on which the number of application settings mismatches with
the actual number returned.

Change-Id: I3fbedd0d73f72c9de5d24af173aded4adf0b9a19
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput/device: Send UHID_DESTROY upon disconnection
Archie Pusaka [Mon, 3 Aug 2020 06:52:24 +0000 (14:52 +0800)]
input/device: Send UHID_DESTROY upon disconnection

According to the uhid documentation: "If your device disconnects,
you should send an UHID_DESTROY event"

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput/device: Implement handle for UHID_SET_REPORT
Archie Pusaka [Mon, 3 Aug 2020 06:52:23 +0000 (14:52 +0800)]
input/device: Implement handle for UHID_SET_REPORT

This patch listens to UHID_SET_REPORT event and forwards this
message to the hid device. Upon reply, we also send a report back
to the kernel as UHID_SET_REPORT_REPLY.

hidp_send_set_report no longer listen UHID_OUTPUT events, that is
handled by hidp_send_output instead.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput/device: Replace UHID_FEATURE with UHID_GET_REPORT
Archie Pusaka [Mon, 3 Aug 2020 06:52:22 +0000 (14:52 +0800)]
input/device: Replace UHID_FEATURE with UHID_GET_REPORT

According to kernel's uhid.h, UHID_FEATURE is obsolete and is
replaced with UHID_GET_REPORT.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput: Remove bonding info when receiving virtual cable unplug
Archie Pusaka [Thu, 16 Jul 2020 18:04:33 +0000 (02:04 +0800)]
input: Remove bonding info when receiving virtual cable unplug

From Bluetooth HID Profile 1.1 Spec: If a Virtual Cable is
unplugged via a HID control Virtual Unplug command, then both the
Bluetooth HID device and Bluetooth HID Host shall destroy or
invalidate all Bluetooth bonding and Virtual Cable information
that was previously stored in persistent memory for the respective
Virtually Cabled devices and hosts.

This patch removes the bonding information upon receiving and/or
sending a "virtual cable unplug".

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodevice: add device_remove_bonding function
Archie Pusaka [Thu, 16 Jul 2020 18:04:32 +0000 (02:04 +0800)]
device: add device_remove_bonding function

This patch splits the "bonding removal" function in device.c,
because we need to remove bonding information when receiving
"virtual cable unplug" in HID profile.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput: encrypt on receive conn req if classic_bonded_only
Archie Pusaka [Wed, 22 Jul 2020 16:20:33 +0000 (00:20 +0800)]
input: encrypt on receive conn req if classic_bonded_only

According to bluetooth HID1.1 spec, section 5.4.3.5.3:
If the Bluetooth HID Host is bonded to a Bluetooth HID device:
If encryption is not already enabled, the Bluetooth HID Host shall
enable encryption with the Bluetooth HID device before sending an
L2CAP Connect Response with a result code of “Connection Successful”
(0x0000) after an L2CAP Connect Request is received.

This patch raises the security level to medium when listening for
incoming connection if the flag classic_bonded_only is set,
effectively starting encryption.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput: authenticate when connecting to a bonded device
Archie Pusaka [Wed, 22 Jul 2020 16:20:32 +0000 (00:20 +0800)]
input: authenticate when connecting to a bonded device

According to bluetooth HID1.1 spec, part 5.4.3.4.3:
If the Bluetooth HID Host is bonded to a Bluetooth HID device:
If encryption is not already enabled, the Bluetooth HID Host shall
enable encryption with the Bluetooth HID device before sending an
L2CAP Connect Request to open the HID L2CAP Control channel.

When creating connection, this patch checks whether the target
device is bonded, if yes then we use the medium security level
instead of the low one to enable encryption.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoaudio/transport: supply volume on transport init
Archie Pusaka [Thu, 23 Jul 2020 07:23:40 +0000 (15:23 +0800)]
audio/transport: supply volume on transport init

Sometimes the response of RegisterNotification for volume change
event came before we create the transport for the corresponding
device. If that happens, the volume will be stuck to an
uninitialized invalid value. The property Volume of
MediaTransport1 will also be left unaccessible.

This patch supplies the initial volume when creating a new
transport. The value is obtained from the media_player object.
However, since the avrcp session might not be created by the time
the transport is created, we also try to initialize the volume
when creating avrcp session.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoaudio/transport: change volume to 8bit
Archie Pusaka [Thu, 23 Jul 2020 07:23:39 +0000 (15:23 +0800)]
audio/transport: change volume to 8bit

The valid range of volume is 0 - 127, yet it is stored in 16bit
data type. This patch modifies it so we use 8bit data type to
store volume instead. Furthermore we also use signed type, so
negative values can be used to indicate invalid volume.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Don't remove temporary devices on disconnect
Luiz Augusto von Dentz [Sat, 18 Jul 2020 00:34:38 +0000 (17:34 -0700)]
adapter: Don't remove temporary devices on disconnect

This makes the disconnect logic just update last seen field of the
device so in case it is temporary it would trigger its timer and be
removed after the timeout which is consistent with the discovery
session givin a grace time for application to react to such events.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodevice: Fix not removing temporary timer when connected
Luiz Augusto von Dentz [Sat, 18 Jul 2020 00:25:52 +0000 (17:25 -0700)]
device: Fix not removing temporary timer when connected

Devices with random addresses will not have its temporary flag (as they
cannot be persisted in storage) reset even in case they are connected
which could cause and unintended disconnection.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Consolidate code parsing services
Luiz Augusto von Dentz [Sat, 18 Jul 2020 00:22:08 +0000 (17:22 -0700)]
shared/gatt-client: Consolidate code parsing services

This makes code parsing primary/secondary services which was mostly
duplicated into a function so it can be reused.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Fix possible crash
Luiz Augusto von Dentz [Fri, 17 Jul 2020 21:09:42 +0000 (14:09 -0700)]
shared/gatt-client: Fix possible crash

This fixes the following crash which was the cause of CI failing with
the latest changes:

Invalid read of size 8
   at 0x15A5ED: queue_remove_if (queue.c:289)
   by 0x15181E: chrc_removed (gatt-client.c:278)
   by 0x15A4BC: queue_foreach (queue.c:220)
   by 0x157870: notify_attribute_changed (gatt-db.c:396)
   by 0x157870: notify_service_changed (gatt-db.c:407)
   by 0x15793C: gatt_db_service_destroy (gatt-db.c:433)
   by 0x15A741: queue_remove_all (queue.c:354)
   by 0x15A774: queue_destroy (queue.c:73)
   by 0x15776F: gatt_db_destroy (gatt-db.c:459)
   by 0x15776F: gatt_db_unref (gatt-db.c:471)
   by 0x15776F: gatt_db_unref (gatt-db.c:463)
   by 0x15211A: bt_gatt_client_free (gatt-client.c:2250)
   by 0x152565: notify_cb (gatt-client.c:2228)
   by 0x14D0F8: handle_notify (att.c:972)
   by 0x14D0F8: can_read_data (att.c:1063)
   by 0x1597F4: watch_callback (io-glib.c:170)
   by 0x48B67AE: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.3)
   by 0x48B6B37: ??? (in /usr/lib64/libglib-2.0.so.0.6400.3)
   by 0x48B6E52: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.3)
   by 0x159DE4: mainloop_run (mainloop-glib.c:79)
   by 0x15A1C1: mainloop_run_with_signal (mainloop-notify.c:201)
   by 0x14B27B: tester_run (tester.c:870)
   by 0x147C8E: main (test-gatt.c:4488)
 Address 0x4f51498 is 8 bytes inside a block of size 32 free'd
   at 0x483B9F5: free (vg_replace_malloc.c:538)
   by 0x1520A8: bt_gatt_client_free (gatt-client.c:2235)
   by 0x152565: notify_cb (gatt-client.c:2228)
   by 0x14D0F8: handle_notify (att.c:972)
   by 0x14D0F8: can_read_data (att.c:1063)
   by 0x1597F4: watch_callback (io-glib.c:170)
   by 0x48B67AE: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.3)
   by 0x48B6B37: ??? (in /usr/lib64/libglib-2.0.so.0.6400.3)
   by 0x48B6E52: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6400.3)
   by 0x159DE4: mainloop_run (mainloop-glib.c:79)
   by 0x15A1C1: mainloop_run_with_signal (mainloop-notify.c:201)
   by 0x14B27B: tester_run (tester.c:870)
   by 0x147C8E: main (test-gatt.c:4488)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoprofile: Add exception to battery profile for external access
Sonny Sasaka [Wed, 15 Jul 2020 22:47:40 +0000 (15:47 -0700)]
profile: Add exception to battery profile for external access

This gives exception to battery profile to be shared both internally and
externally.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agogatt: Support DeviceInfo Service when vid/pid is specified
Alain Michaud [Fri, 17 Jul 2020 14:40:07 +0000 (14:40 +0000)]
gatt: Support DeviceInfo Service when vid/pid is specified

This patch adds support for the PNPID characteristic when configured in
main.conf.

This was validated as read correclty both by manually reading the valud
and confirming in the Ellisys Analyzer.

ATT Read (PnP ID: Source=Bluetooth ID, Vendor=224, Product=50181,
ATT Read Response Packet (Source=Bluetooth ID, Vendor=224,
Product=50181, Version=86)     | OK     | 7 bytes (01 E0 00 05 C4 56 00)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Fix handling of service changed
Luiz Augusto von Dentz [Fri, 17 Jul 2020 19:08:14 +0000 (12:08 -0700)]
shared/gatt-client: Fix handling of service changed

When handling multiple service changed multiple discovery operations
would be performed but at the end of each one the hash would be read
which not only would create extra traffic but also prevents the code
to properly detection services disappering.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Don't remove active services
Luiz Augusto von Dentz [Fri, 17 Jul 2020 19:07:01 +0000 (12:07 -0700)]
shared/gatt-client: Don't remove active services

If discovery was aborted (i.e due to a disconnect) check if pending
services were active so only staled services which were not completed
fetched are removed.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Remove notification if its attribute is removed
Luiz Augusto von Dentz [Thu, 16 Jul 2020 22:07:42 +0000 (15:07 -0700)]
shared/gatt-client: Remove notification if its attribute is removed

If the attribute is being removed from the database it means the
notification shall also be dropped, that way users don't have to
cleanup its subscriptions themselves.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-db: Add support for notifying attribute changes
Luiz Augusto von Dentz [Thu, 16 Jul 2020 22:02:27 +0000 (15:02 -0700)]
shared/gatt-db: Add support for notifying attribute changes

This enables to get notified when an attribute has been changed e.g.
it is being removed so the code can detect changes changes at attribute
level.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/att: Fix possible crash on disconnect
Luiz Augusto von Dentz [Thu, 16 Jul 2020 01:25:37 +0000 (18:25 -0700)]
shared/att: Fix possible crash on disconnect

If there are pending request while disconnecting they would be notified
but clients may endup being freed in the proccess which will then be
calling bt_att_cancel to cancal its requests causing the following
trace:

Invalid read of size 4
   at 0x1D894C: enable_ccc_callback (gatt-client.c:1627)
   by 0x1D247B: disc_att_send_op (att.c:417)
   by 0x1CCC17: queue_remove_all (queue.c:354)
   by 0x1D47B7: disconnect_cb (att.c:635)
   by 0x1E0707: watch_callback (io-glib.c:170)
   by 0x48E963B: g_main_context_dispatch (in /usr/lib/libglib-2.0.so.0.6400.4)
   by 0x48E9AC7: ??? (in /usr/lib/libglib-2.0.so.0.6400.4)
   by 0x48E9ECF: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.6400.4)
   by 0x1E0E97: mainloop_run (mainloop-glib.c:79)
   by 0x1E13B3: mainloop_run_with_signal (mainloop-notify.c:201)
   by 0x12BC3B: main (main.c:770)
 Address 0x7d40a28 is 24 bytes inside a block of size 32 free'd
   at 0x484A2E0: free (vg_replace_malloc.c:540)
   by 0x1CCC17: queue_remove_all (queue.c:354)
   by 0x1CCC83: queue_destroy (queue.c:73)
   by 0x1D7DD7: bt_gatt_client_free (gatt-client.c:2209)
   by 0x16497B: batt_free (battery.c:77)
   by 0x16497B: batt_remove (battery.c:286)
   by 0x1A0013: service_remove (service.c:176)
   by 0x1A9B7B: device_remove_gatt_service (device.c:3691)
   by 0x1A9B7B: gatt_service_removed (device.c:3805)
   by 0x1CC90B: queue_foreach (queue.c:220)
   by 0x1DE27B: notify_service_changed.isra.0.part.0 (gatt-db.c:369)
   by 0x1DE387: notify_service_changed (gatt-db.c:361)
   by 0x1DE387: gatt_db_service_destroy (gatt-db.c:385)
   by 0x1DE3EF: gatt_db_remove_service (gatt-db.c:519)
   by 0x1D674F: discovery_op_complete (gatt-client.c:388)
   by 0x1D6877: discover_primary_cb (gatt-client.c:1260)
   by 0x1E220B: discovery_op_complete (gatt-helpers.c:628)
   by 0x1E249B: read_by_grp_type_cb (gatt-helpers.c:730)
   by 0x1D247B: disc_att_send_op (att.c:417)
   by 0x1CCC17: queue_remove_all (queue.c:354)
   by 0x1D47B7: disconnect_cb (att.c:635)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Remove timer for removing temporary devices
Luiz Augusto von Dentz [Wed, 15 Jul 2020 20:29:24 +0000 (13:29 -0700)]
adapter: Remove timer for removing temporary devices

Now that each temporary device object can cleanup after it has detected
that it has disappeared it is no longer necessary to keep this logic as
well in the adapter.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodevice: Add timer for removing temporary devices
Luiz Augusto von Dentz [Wed, 15 Jul 2020 20:23:23 +0000 (13:23 -0700)]
device: Add timer for removing temporary devices

This adds a timer for how long to keep temporary devices, it is updated
everytime the device is seen so devices will be removed even during an
active discovery session which means the discovering for a long period
will no longer just grow without removing devices that disappeared.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoaudio/avrcp: Always update transport volume regardless of player
Marijn Suijten [Sat, 11 Jul 2020 11:50:31 +0000 (13:50 +0200)]
audio/avrcp: Always update transport volume regardless of player

`Volume` is a special property that not only exists on players but also
on the transport (see org.bluez.MediaTransport1). A player is not
attached when the controller does not support FEATURE_CATEGORY_1, which
is common on headphones without media browsing capabilities.

On such audio devices (headphones, in-ears and the like) Absolute Volume
is not available unless an external player is registered
(org.bluez.Media1.RegisterPlayer) and the device sends a volume event
back after that to set a2dp->volume in transport.c to a valid value
(causing volume_exists to finally return true).

This [1] mail thread denoting the same issue has a solution to at least
request capabilities from the controller, but the proposed player object
is not created on category 2 devices. Any notifications received on
AVRCP_EVENT_VOLUME_CHANGED (avrcp_volume_changed) that is subsequently
registered, or handling the result of avrcp_set_volume in
avrcp_handle_set_volume will be ignored unless said player is present.

This issue is not addressed by adding a fake player but instead dealing
with the fact that volume is "special" and available on the transport
regardless of the existence of a player. This is confirmed in
avrcp_get_capabilities_resp as well which requires a player to register
any event except AVRCP_EVENT_VOLUME_CHANGED.

The applied solution moves media_transport_update_device_volume out of
the player and into avrcp_volume_changed/avrcp_handle_set_volume where
it is unconditionally called. These functions are the only users of
avrcp_player->set_volume.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Fix not cleanup temporary devices
Luiz Augusto von Dentz [Wed, 8 Jul 2020 21:14:59 +0000 (14:14 -0700)]
adapter: Fix not cleanup temporary devices

When an adapter is powered down or unplugged remove its temporary
devices immediatelly as the application will no longer be able to
connect to them.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoclient: Add support for the Roles property.
Alain Michaud [Tue, 7 Jul 2020 02:19:20 +0000 (02:19 +0000)]
client: Add support for the Roles property.

This adds support for reading the Roles property through bluetootctl's
show option.

[bluetooth]# show
...
Roles: central
Roles: peripheral
Roles: central-peripheral

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: add support for the Roles property
Alain Michaud [Tue, 7 Jul 2020 02:19:18 +0000 (02:19 +0000)]
adapter: add support for the Roles property

This patch adds support for the Roles property as defined in
adapter-api.txt.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput: Make HID devices support wake
Abhishek Pandit-Subedi [Mon, 6 Jul 2020 20:25:18 +0000 (13:25 -0700)]
input: Make HID devices support wake

HID devices can wake the host from a suspended state. Mark the profiles
to support wake when they are accepted. If the device hasn't already
been configured with a Wake Allowed configuration, it will default to
yes when the profile is accepted.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc/device-api: Add WakeAllowed
Abhishek Pandit-Subedi [Mon, 6 Jul 2020 20:25:17 +0000 (13:25 -0700)]
doc/device-api: Add WakeAllowed

Add documentation for WakeAllowed, which allows a device to wake the
system from suspend.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoclient: Display wake allowed property with info
Abhishek Pandit-Subedi [Mon, 6 Jul 2020 20:25:16 +0000 (13:25 -0700)]
client: Display wake allowed property with info

Display whether the device is configured as wake allowed when queried
with cmd_info.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodevice: Support marking a device with wake allowed
Abhishek Pandit-Subedi [Mon, 6 Jul 2020 20:25:15 +0000 (13:25 -0700)]
device: Support marking a device with wake allowed

If a device is allowed to wake the host system from suspend, it should
be marked as wake allowed. We add support for a new property that is
sent to the kernel via set device flags mgmt op. We also add the dbus
endpoint to allow the wake allowed setting to be controlled.

In order for wake allowed to be set, the profile must also support wake.
This setting isn't exposed to the user but must be set by profiles that
intend to support wake from suspend.

If a device is connecting for the first time, it will be marked
WakeAllowed if the profile supports it. On subsequent reloads of bluez,
the stored setting "WakeAllowed" will be used to override any other
setting.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomonitor: Decode device flags mgmt ops and event
Abhishek Pandit-Subedi [Mon, 6 Jul 2020 20:25:14 +0000 (13:25 -0700)]
monitor: Decode device flags mgmt ops and event

Add support for Get Device Flags and Set Device Flags mgmt operations
and Device Flags Changed mgmt event.

Sample trace:
@ MGMT Command: Set Device Flags (0x0050) plen 11     {0x0002} [hci0]
        LE Address: CD:F3:CD:13:C5:91 (Static)
        Current Flags: 0x00000000
@ MGMT Event: Device Flags Changed (0x002a) plen 15   {0x0001} [hci0]
        LE Address: CD:F3:CD:13:C5:91 (Static)
        Supported Flags: 0x00000001
          Remote Wakeup
        Current Flags: 0x00000000
@ MGMT Event: Device Flags Changed (0x002a) plen 15   {0x0004} [hci0]
        LE Address: CD:F3:CD:13:C5:91 (Static)
        Supported Flags: 0x00000001
          Remote Wakeup
        Current Flags: 0x00000000
@ MGMT Event: Device Flags Changed (0x002a) plen 15   {0x0003} [hci0]
        LE Address: CD:F3:CD:13:C5:91 (Static)
        Supported Flags: 0x00000001
          Remote Wakeup
        Current Flags: 0x00000000
@ MGMT Event: Command Complete (0x0001) plen 10       {0x0002} [hci0]
      Set Device Flags (0x0050) plen 7
        Status: Success (0x00)
        LE Address: CD:F3:CD:13:C5:91 (Static)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomgmt: Add mgmt op and events for device flags
Abhishek Pandit-Subedi [Mon, 6 Jul 2020 20:25:13 +0000 (13:25 -0700)]
mgmt: Add mgmt op and events for device flags

Add Get Device Flags, Set Device Flags and Device Flags Changed.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoclient: Add battery percentage to info command
Sonny Sasaka [Thu, 2 Jul 2020 18:01:55 +0000 (11:01 -0700)]
client: Add battery percentage to info command

This adds the Battery Percentage to the info command based on
org.bluez.Battery1 API. Example usage:

[bluetooth]# info XX:XX:XX:XX:XX:XX
Device XX:XX:XX:XX:XX:XX (random)
        Name: ...
        Alias: ...
        ...
        Modalias: ...
        Battery Percentage: 0x64 (100)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agounit/test-gatt: Fix test /TP/GAR/CL/BI-16-C/auto
Luiz Augusto von Dentz [Thu, 2 Jul 2020 17:20:35 +0000 (10:20 -0700)]
unit/test-gatt: Fix test /TP/GAR/CL/BI-16-C/auto

Test has been using Read Blob Response (0x0d) opcode instead of the
expected Read Response (0x0b) to Read Resquest (0x0a).

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Fix not return error to callback
Luiz Augusto von Dentz [Thu, 2 Jul 2020 16:01:05 +0000 (09:01 -0700)]
shared/gatt-client: Fix not return error to callback

If a CCC request has been cancelled the pdu given to the callback will
be NULL which was not translated to a proper error.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoscanparam: Use configured values when available
Alain Michaud [Wed, 1 Jul 2020 13:13:28 +0000 (13:13 +0000)]
scanparam: Use configured values when available

This patch updates the scan parameter service to use the configured scan
parameters when available rather than the hardcoded kernel defaults.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agogobex: Fix segfault caused by interrupted transfer
Denis Grigorev [Tue, 30 Jun 2020 13:47:31 +0000 (16:47 +0300)]
gobex: Fix segfault caused by interrupted transfer

When a obex transfer is interrupted by a peer in the middle, the response
G_OBEX_RSP_FORBIDDEN comes and the transfer is freed in transfer_complete.
However gobex is still ref'ed and gobex->io continues to be writable,
so write_data() and then g_obex_abort() are called. When the abort response
comes, struct obc_transfer is already freed, which leads to the crash.

Backtrace :
__GI___pthread_mutex_lock (mutex=0x65732f74) at pthread_mutex_lock.c:67
0xecc6eeda in dbus_connection_get_object_path_data () from libdbus-1.so.3
0x000457d4 in g_dbus_emit_property_changed_full () at gdbus/object.c:1794
0x00045868 in g_dbus_emit_property_changed () at gdbus/object.c:1832
0x000367f0 in transfer_set_status () at obexd/client/transfer.c:211
0x0003681e in transfer_set_status () at obexd/client/transfer.c:206
xfer_complete () at obexd/client/transfer.c:672
0x00022df6 in transfer_complete () at gobex/gobex-transfer.c:103
0x00022f44 in transfer_abort_response () at gobex/gobex-transfer.c:124
0x00020a0e in handle_response () at gobex/gobex.c:1128
0x00020dde in incoming_data () at gobex/gobex.c:1373

This commit introduces g_obex_drop_tx_queue(), which will be called if
a transfer error detected. After the tx queue is dropped, obex shuts
down gracefully.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoa2dp: Fix typo in endpoint_setconf_ind
Alain Michaud [Mon, 1 Jun 2020 15:58:58 +0000 (15:58 +0000)]
a2dp: Fix typo in endpoint_setconf_ind

This patch simply fixes a typo in endpoint_setconf_ind.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoavdtp: Fix possible unbalance ref count
Luiz Augusto von Dentz [Mon, 22 Jun 2020 16:21:27 +0000 (09:21 -0700)]
avdtp: Fix possible unbalance ref count

It has been reported that under some unknown circuntances the reference
number of AVDTP sessions can go bellow 0 (loop around) causing a crash:

bluetoothd[5633]: profiles/audio/avdtp.c:avdtp_ref() 0x56a882b8a500: ref=-2101995743
bluetoothd[5633]: profiles/audio/a2dp.c:discover_cb() err (nil)
WARNING crash_reporter[10707]: [user] Received crash notification for bluetoothd[5633]

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/gatt-client: Fix freeing instance while processing notification
Luiz Augusto von Dentz [Thu, 25 Jun 2020 20:52:55 +0000 (13:52 -0700)]
shared/gatt-client: Fix freeing instance while processing notification

If CCC fails to be programmed the callback would be run without taking
a reference which may lead to freeing the client instance while there
are still notification to be processed.

To fix this handling of both success and failure to program the CCC will
now take a reference to the client, also in case of failure instead of
attempting to program the CCC once again the code now notify all the
queued requests which is consistent with how the success case is
handled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agosrc/shared: update uuid16_table to latest
Noah Pendleton [Sun, 21 Jun 2020 18:56:18 +0000 (14:56 -0400)]
src/shared: update uuid16_table to latest

Update the table of 16-bit UUID to manufacturer name string to the
latest from this url:

https://www.bluetooth.com/specifications/assigned-numbers/16-bit-uuids-for-members/

I used this script to convert to the bluez format:

https://github.com/noahp/bt-sig-16-bit-uuids
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agocheckpatch: Add configuration for checkpatch
Tedd Ho-Jeong An [Mon, 22 Jun 2020 17:18:17 +0000 (10:18 -0700)]
checkpatch: Add configuration for checkpatch

This patch adds a configuration with basic rules for checkpatch.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomidi: Fix random empty timestamp_high value
Tedd Ho-Jeong An [Fri, 19 Jun 2020 18:34:56 +0000 (11:34 -0700)]
midi: Fix random empty timestamp_high value

The timestamp_high value is assigned from the monotonic time but there
is a chance that the value becomes zero because it reads the value
between bit8 and bit13.

This patch makes sure the timestamp_high value get a non-zero value.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomidi: Fix SysEx parser in MIDI plugin
Tedd Ho-Jeong An [Fri, 19 Jun 2020 18:34:55 +0000 (11:34 -0700)]
midi: Fix SysEx parser in MIDI plugin

The SysEx end of message parser didn't consider the fact that
timestampsLow are in the stream and it might have the EOX (F7)
byte as well.

Fix that by always assuming the first system message byte is
the timestampLow.

Future work would involve support other type of system message
bytes, such as real-time.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agobtmgmt: Add command "add" into "monitor" btmgmt submenu
Michael Sun [Fri, 19 Jun 2020 22:56:23 +0000 (15:56 -0700)]
btmgmt: Add command "add" into "monitor" btmgmt submenu

This patch introduces a new command ‘add’ within "monitor" submenu to
allow users to add advertisement monitor filters and get back monitor
handlers. An event handler is also added to handle kernel issued
MGMT_EV_ADV_MONITOR_ADDED events. The command will work with the new
MGMT opcode MGMT_OP_ADD_ADV_MONITOR. This patch only adds support for
adding pattern based filters.

Tested on Atlas Chromebook with a sample stdout below:
[mgmt]# add -p 0:1:c504 1:a:9a55beef
Advertisement monitor with handle:0x0005 added
[mgmt]# add -p 0:1:xxxx
Failed to parse monitor patterns.
Usage: add <-p|-h> [options...]
Monitor Types:
        -p <ad_type:offset:pattern>...  Pattern Monitor
e.g.:
        add -p 0:1:c504 1:a:9a55beef

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agobtmgmt: Add command "remove" into "monitor" btmgmt submenu
Michael Sun [Fri, 19 Jun 2020 22:56:22 +0000 (15:56 -0700)]
btmgmt: Add command "remove" into "monitor" btmgmt submenu

This patch introduces a new btmgmt command ‘remove’ wihtin "monitor"
submenu to allow users to remove previously added filters along with a
event handler to handle kernel issued MGMT_EV_ADV_MONITOR_REMOVED
event. The command will work with the new
MGMT opcode MGMT_OP_REMOVE_ADV_MONITOR.

Tested on Atlas Chromebook with a sample stdout below:
[mgmt]# remove 1
Advertisement monitor with handle: 0x0001 removed
[mgmt]# remove 1234
Could not remove advertisement monitor with status 0x11 (Invalid Index)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agobtmgmt: Add "monitor" btmgmt submenu and command "features"
Michael Sun [Fri, 19 Jun 2020 22:56:21 +0000 (15:56 -0700)]
btmgmt: Add "monitor" btmgmt submenu and command "features"

This patch introduces a new submenu "monitor" along with command
‘features’ to help user query for supported advertisement features. The
command will work with the new MGMT opcode
MGMT_OP_READ_ADV_MONITOR_FEATURES.

Tested on Atlas Chromebook with a sample stdout below:
[mgmt]# features
Supported features:
        None
Enabled features:
        None
Max number of handles: 32
Max number of patterns: 16
Handles list with 2 items:
        0x0001
        0x0002

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomain: adding missing connection parameter entries
Alain Michaud [Mon, 15 Jun 2020 14:52:21 +0000 (14:52 +0000)]
main: adding missing connection parameter entries

This patch adds the missing connection parameter entries for loading
connection parameters from main.conf

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agolib: Correct the string for a mgmt op
Miao-chen Chou [Tue, 16 Jun 2020 22:56:50 +0000 (15:56 -0700)]
lib: Correct the string for a mgmt op

This corrects the string of MGMT_OP_ADD_ADV_PATTERNS_MONITOR to match
mgmt-api.txt.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomain: Add configurable le autoconnect timeout value
Alain Michaud [Mon, 15 Jun 2020 14:52:52 +0000 (14:52 +0000)]
main: Add configurable le autoconnect timeout value

This patch adds support for a configurable le autoconnect timer.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomain: Fix logical error when loading controller params
Alain Michaud [Thu, 18 Jun 2020 01:48:12 +0000 (01:48 +0000)]
main: Fix logical error when loading controller params

Fix logical error when loading configuration parameters from the
config file.  Without this patch, the maximum allowable value is always
used.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agolib: Correct the name command definition
Miao-chen Chou [Tue, 16 Jun 2020 04:28:34 +0000 (21:28 -0700)]
lib: Correct the name command definition

This renames MGMT_OP_ADD_ADV_MONITOR to
MGMT_OP_ADD_ADV_PATTERNS_MONITOR as this command is only used for
patterns.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agolib: Move HOG UUID definition
Manish Mandlik [Wed, 10 Jun 2020 16:22:04 +0000 (09:22 -0700)]
lib: Move HOG UUID definition

HOG UUID is defined at multiple places in the code. Move that
definition to lib/uuid.h where all other UUIDs are defined.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Fix minor typo
Marcel Holtmann [Fri, 12 Jun 2020 19:49:12 +0000 (21:49 +0200)]
doc: Fix minor typo

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomgmt: syncing configuration commands to the documentation.
Alain Michaud [Fri, 12 Jun 2020 19:48:36 +0000 (21:48 +0200)]
mgmt: syncing configuration commands to the documentation.

This patch simply fixes the definition names (and corresponding
implemenation) to the adopted documentation.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Fix not checking status of stop discovery command
Luiz Augusto von Dentz [Fri, 12 Jun 2020 17:11:04 +0000 (10:11 -0700)]
adapter: Fix not checking status of stop discovery command

Status needs to be checked in order to properly synchronize the states
with the controller.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agolib: Add definitions for advertisement monitor features
Miao-chen Chou [Tue, 19 May 2020 03:10:00 +0000 (20:10 -0700)]
lib: Add definitions for advertisement monitor features

This adds the following command opcodes, event codes and the corresponding
structures.
- MGMT_OP_READ_ADV_MONITOR_FEATURES
- MGMT_OP_ADD_ADV_PATTERNS_MONITOR
- MGMT_OP_REMOVE_ADV_MONITOR
- MGMT_EV_ADV_MONITOR_ADDED
- MGMT_EV_ADV_MONITOR_REMOVED

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Rename watch_client to discovery_client
Luiz Augusto von Dentz [Thu, 11 Jun 2020 20:23:06 +0000 (13:23 -0700)]
adapter: Rename watch_client to discovery_client

watch term is quite vague so this replace it with discovery which is
what is used for the filter as well.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Fix leaking filter pattern
Luiz Augusto von Dentz [Thu, 11 Jun 2020 20:16:29 +0000 (13:16 -0700)]
adapter: Fix leaking filter pattern

When a discovery client has set a pattern as filter the code allocates
the string so it needs to be freed with the filter otherwise it leads to
the following leak:

10 bytes in 2 blocks are definitely lost in loss record 19 of 265
   at 0x483980B: malloc (vg_replace_malloc.c:309)
   by 0x4D9FF7E: strdup (in /usr/lib64/libc-2.30.so)
   by 0x1FC8E7: parse_pattern (adapter.c:2454)
   by 0x1FF37B: parse_discovery_filter_entry (adapter.c:2480)
   by 0x1FF37B: parse_discovery_filter_dict (adapter.c:2538)
   by 0x2020AF: set_discovery_filter (adapter.c:2589)
   by 0x24AD63: process_message.isra.0 (object.c:259)
   by 0x24B40F: generic_message (object.c:1079)
   by 0x4A670B7: ??? (in /usr/lib64/libdbus-1.so.3.19.11)
   by 0x4A57763: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.19.11)
   by 0x2459CF: message_dispatch (mainloop.c:72)
   by 0x4963E8A: ??? (in /usr/lib64/libglib-2.0.so.0.6200.6)
   by 0x496756F: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6200.6)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Track discovery client which initiate an action
Luiz Augusto von Dentz [Thu, 11 Jun 2020 20:14:07 +0000 (13:14 -0700)]
adapter: Track discovery client which initiate an action

This adds tracking for active clients so it can be properly
removed/freed on the callbacks.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Fix passing wrong pointer to stop discovery
Luiz Augusto von Dentz [Thu, 11 Jun 2020 17:26:57 +0000 (10:26 -0700)]
adapter: Fix passing wrong pointer to stop discovery

stop_discovery_complete now expects adapter to be passed instead of
client.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput: Disconnect ctrl chan only if intr chan was disconnected by us
Archie Pusaka [Wed, 10 Jun 2020 15:04:46 +0000 (23:04 +0800)]
input: Disconnect ctrl chan only if intr chan was disconnected by us

If the intr channel was disconnected by the other party, then they
are also responsible to close the ctrl channel. Such disconnection
message would have the G_IO_ERR flag set, as opposed to it being
unset if the disconnection is initiated by us.

There doesn't seem to be an explicit rule in the specification
about this behavior, but this is enforced in the PTS qualification
tool.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoinput: disconnect intr channel before ctrl channel
Archie Pusaka [Tue, 9 Jun 2020 14:58:25 +0000 (22:58 +0800)]
input: disconnect intr channel before ctrl channel

According to bluetooth HID Profile spec Ver 1.0, section 7.2.2, A
host or device shall always complete the disconnection of the
interrupt channel before disconnecting the control channel.
However, the current implementation disconnects them both
simultaneously.

This patch postpone the disconnection of control channel to the
callback of interrupt watch, which shall be called upon receiving
interrupt channel disconnection response.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Fix possible crash when stopping discovery
Luiz Augusto von Dentz [Mon, 8 Jun 2020 21:55:57 +0000 (14:55 -0700)]
adapter: Fix possible crash when stopping discovery

If the client disconnect/crash while MGMT_OP_STOP_DISCOVERY was pending
it would possibly cause a crash as the client pointer is passed to
mgmt_send and accessed in the callback after being freed.

To fix this the adapter itself is now passed to the callback so the
client is not accessed directly, instead the code now checks if
discovery_list has not been cleared in the meantime and only then
proceed to access the client pointer which is how
MGMT_OP_START_DISCOVERY is handled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Consolitate code for discovery reply
Luiz Augusto von Dentz [Mon, 8 Jun 2020 21:52:53 +0000 (14:52 -0700)]
adapter: Consolitate code for discovery reply

This consolidate code that were used to reply discovery commands in a
single function so it easier to reuse and maintain.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Do not remove client watch directly if discovery fails
Luiz Augusto von Dentz [Mon, 8 Jun 2020 21:07:25 +0000 (14:07 -0700)]
adapter: Do not remove client watch directly if discovery fails

Client watch is used for both discovery and it filters so in case the
client has set the later the watch shall be perserved.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoa2dp: Use streaming mode when MPS is enabled
Luiz Augusto von Dentz [Mon, 8 Jun 2020 20:24:40 +0000 (13:24 -0700)]
a2dp: Use streaming mode when MPS is enabled

If MPS is enabled use L2CAP streaming mode for AVDTP channels.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Describe the new Advertisement Monitor support
Miao-chen Chou [Wed, 10 Jun 2020 17:54:54 +0000 (19:54 +0200)]
doc: Describe the new Advertisement Monitor support

This describes the following commands and event.
- Read Advertisement Monitor Features command
- Add Advertisement Patterns Monitor command
- Remove Advertisement Monitor command
- Advertisement Monitor Added event
- Advertisement Monitor Removed event
Note that the content of a monitor can differ based on its type. For now we
introduce only pattern-based monitor, so you may find that unlike the
command of removing monitor(s), the Add command is tied to a specific type.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Fix typo for Set Device Class command description
Marcel Holtmann [Wed, 10 Jun 2020 17:21:57 +0000 (19:21 +0200)]
doc: Fix typo for Set Device Class command description

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Add commands and event for handling device flags
Marcel Holtmann [Wed, 10 Jun 2020 17:20:16 +0000 (19:20 +0200)]
doc: Add commands and event for handling device flags

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Add the event for default configuration changes
Marcel Holtmann [Wed, 10 Jun 2020 14:11:18 +0000 (16:11 +0200)]
doc: Add the event for default configuration changes

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Mention mgmt version 1.18 changes
Marcel Holtmann [Wed, 10 Jun 2020 09:02:02 +0000 (11:02 +0200)]
doc: Mention mgmt version 1.18 changes

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: Add commands for reading and changing runtime parameters
Marcel Holtmann [Wed, 10 Jun 2020 08:59:39 +0000 (10:59 +0200)]
doc: Add commands for reading and changing runtime parameters

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc: adding definitions for load default params mgmt op
Alain Michaud [Wed, 10 Jun 2020 08:47:58 +0000 (10:47 +0200)]
doc: adding definitions for load default params mgmt op

This change adds the definition for the read/set default parameter
commands.

In particular, these commands are used to read and set the system
default parameters.  The use of a TLV format also ensures that
parameters are expandable in the future.

This will allow bluetoothd to load parameters from a conf file that may
be customized for the specific requirements of each platforms.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agohealth: Fix use of L2CAP modes with bt_io
Luiz Augusto von Dentz [Mon, 8 Jun 2020 16:25:28 +0000 (09:25 -0700)]
health: Fix use of L2CAP modes with bt_io

bt_io modes are no longer compatible with L2CAP modes so the later
shall not used with bt_io APIs.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoavctp: Fix using L2CAP modes with bt_io
Luiz Augusto von Dentz [Mon, 8 Jun 2020 16:18:50 +0000 (09:18 -0700)]
avctp: Fix using L2CAP modes with bt_io

bt_io modes are no longer compatible with L2CAP modes so the later
shall not used with bt_io APIs.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agobtio: Fix not translation mode to L2CAP mode
Luiz Augusto von Dentz [Fri, 5 Jun 2020 17:58:01 +0000 (10:58 -0700)]
btio: Fix not translation mode to L2CAP mode

When using L2CAP_OPTIONS legacy modes need to be used since they are
not compatible with BT_MODE.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadvertising: Fix resetting NO_BREDR flag
Luiz Augusto von Dentz [Fri, 5 Jun 2020 17:45:21 +0000 (10:45 -0700)]
advertising: Fix resetting NO_BREDR flag

When setting BT_AD_FLAG_LIMITED it was actually overwriting
BT_AD_FLAG_NO_BREDR as well so this moves the logic of detecting if the
instance needs to set BT_AD_FLAG_NO_BREDR to set_flags so it is always
updated when attempting to set any flags.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/ad: Add defines for possible flags
Luiz Augusto von Dentz [Fri, 5 Jun 2020 17:37:42 +0000 (10:37 -0700)]
shared/ad: Add defines for possible flags

This adds defines for limited disverable, general discoveral and BR/EDR
not supported.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomain: Read default system configuration from the conf file
Alain Michaud [Fri, 29 May 2020 15:38:15 +0000 (15:38 +0000)]
main: Read default system configuration from the conf file

This change adds support for reading the configurations from the
main.conf file.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Set default system configuration if available
Alain Michaud [Fri, 29 May 2020 15:38:13 +0000 (15:38 +0000)]
adapter: Set default system configuration if available

This change loads any specified system configuration if provided and
supported by the kernel.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agomgmt: Add load default system configuration definitions
Alain Michaud [Fri, 29 May 2020 15:38:11 +0000 (15:38 +0000)]
mgmt: Add load default system configuration definitions

This change adds the load default system configuration definitions

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agotools/l2cap-tester: Add test for waiting disconnection response
Archie Pusaka [Tue, 5 May 2020 04:29:11 +0000 (12:29 +0800)]
tools/l2cap-tester: Add test for waiting disconnection response

This is to test the behaviour of L2CAP channel when closed with
shut_down(sock, SHUT_WR). In this case, we should wait until we
receive a disconnection response before raising G_IO_HUP.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoaudio/avrcp: Fix media player passthrough bitmask
Archie Pusaka [Fri, 29 May 2020 05:31:04 +0000 (13:31 +0800)]
audio/avrcp: Fix media player passthrough bitmask

Adjust the values of the passthrough bitmask with the declared
keys in avctp.c:key_map, according to section 6.10.2.1 of the
AVRCP specification.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/hci: Fix crash when bt_hci_unref is used from callback
Luiz Augusto von Dentz [Thu, 4 Jun 2020 21:04:39 +0000 (14:04 -0700)]
shared/hci: Fix crash when bt_hci_unref is used from callback

If application unref its reference on the command callback it can lead
to crashes like the following:

 Invalid read of size 1
    at 0x254270: wakeup_writer (hci.c:187)
    by 0x254321: process_response (hci.c:229)
    by 0x254590: process_event (hci.c:263)
    by 0x254590: io_read_callback (hci.c:305)
    by 0x269258: watch_callback (io-glib.c:170)
    by 0x496756F: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6200.6)
    by 0x49678FF: ??? (in /usr/lib64/libglib-2.0.so.0.6200.6)
    by 0x4967BF2: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6200.6)
    by 0x269C6C: mainloop_run (mainloop-glib.c:79)
    by 0x26A219: mainloop_run_with_signal (mainloop-notify.c:201)
    by 0x171A35: main (main.c:770)
  Address 0x53b7e81 is 17 bytes inside a block of size 64 free'd
    at 0x483AA0C: free (vg_replace_malloc.c:540)
    by 0x254A70: bt_hci_unref (hci.c:461)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/util: Fix undefined behavior of left shift
Sonny Sasaka [Wed, 3 Jun 2020 17:56:00 +0000 (10:56 -0700)]
shared/util: Fix undefined behavior of left shift

When left-shifting 1, we should be explicit that it is an unsigned 1.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agogatt: Fix possible crash when unable to generate hash
Luiz Augusto von Dentz [Wed, 3 Jun 2020 17:31:59 +0000 (10:31 -0700)]
gatt: Fix possible crash when unable to generate hash

gatt_db_get_hash actually depends on crypto so platforms that don't
have it enabled shall not register GATT_CHARAC_DB_HASH as otherwise it
would cause a crash due to hash being NULL.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoa2dp: Fix crash on transport_cb
Luiz Augusto von Dentz [Mon, 1 Jun 2020 21:25:30 +0000 (14:25 -0700)]
a2dp: Fix crash on transport_cb

There have been reports of crashes on transport_cb where the setup
would most likely already have been freed but transport_cb would still
be called, so instead of assuming the setup pointer would be valid try
to lookup the list of active setups and log a warning when it happens.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoa2dp: Fix double free in load_remote_sep
Alain Michaud [Mon, 1 Jun 2020 00:56:00 +0000 (00:56 +0000)]
a2dp: Fix double free in load_remote_sep

This patch fixes a double free condition in load_remote_sep. Value is
freed, then the inner loop is broken, but the rest of the outer loop
will attempt to free value again.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoa2dp: Fix ref counting bug of setup_unref
Sonny Sasaka [Sat, 30 May 2020 08:51:18 +0000 (01:51 -0700)]
a2dp: Fix ref counting bug of setup_unref

In a2dp_reconfig, setup is ref-counted by cb_data. However, in the fail
label setup is unref-ed but cb_data is not cleared. This may cause
double unref in the future if cb_data gets executed. Instead, we should
do setup_cb_free to clear cb_data and unref setup.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadapter: Fix not removing client from discovery list
Luiz Augusto von Dentz [Thu, 28 May 2020 22:07:37 +0000 (15:07 -0700)]
adapter: Fix not removing client from discovery list

If command MGMT_OP_START_DISCOVERY fails we reply with btd_error_busy
but we don't remove the client from the list which would prevent the
client to start it once again.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoavrcp: Don't attempt to load settings if on volume changed is supported
Luiz Augusto von Dentz [Thu, 28 May 2020 17:18:17 +0000 (10:18 -0700)]
avrcp: Don't attempt to load settings if on volume changed is supported

If only volume changed is supported that means the player cannot really
indicate track/metadata changes so don't attempt to read them.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoavrcp: Fix always requesting player settings for category 1
Luiz Augusto von Dentz [Wed, 27 May 2020 22:39:56 +0000 (15:39 -0700)]
avrcp: Fix always requesting player settings for category 1

Player Application settings is not mandatory for category 1 so instead
of always listing the settings the code now checks if
AVRCP_FEATURE_PLAYER_SETTINGS is enabled.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoshared/shell: don't hook io_hup on non-interactive
Stimim Chen [Wed, 27 May 2020 05:02:28 +0000 (13:02 +0800)]
shared/shell: don't hook io_hup on non-interactive

When we are in non-interactive mode (data.mode == 1), we should not
terminate the mainloop when stdin is disconnected.

For example, in bash, the following command would terminate immediately
without any output.

  : | btmgmt info

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoadvertising: Fix advertising flags
Luiz Augusto von Dentz [Tue, 26 May 2020 18:07:48 +0000 (11:07 -0700)]
advertising: Fix advertising flags

When an instance wants to force being discoverable the code shall
actually check if the adapter is in general disverable mode already and
if not set BR/EDR as not supported so that devices scanning don't
assume BR/EDR PHY is connectable when in fact it isn't.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoemulator: Use master settings for CIS params
Luiz Augusto von Dentz [Tue, 26 May 2020 16:41:00 +0000 (09:41 -0700)]
emulator: Use master settings for CIS params

The slave will be the first to respond with CIS Estabished but only the
master has the CIG params set so this switch to master so parameters are
proper.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agoemulator: Don't require ACL connection for Setup ISO Data Path
Luiz Augusto von Dentz [Thu, 21 May 2020 17:35:10 +0000 (10:35 -0700)]
emulator: Don't require ACL connection for Setup ISO Data Path

LE Setup ISO Data Path can be used even before the ACL handle exists
when master since Set CIG Parameters will respond with ISO handle it
can then be used to setup the data path in advance of ACL connection.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agotest/example-advertisement: Fix include_tx_power
Alvar Penning [Wed, 20 May 2020 20:44:44 +0000 (22:44 +0200)]
test/example-advertisement: Fix include_tx_power

Adding the Tx Power Level is no longer done via IncludeTxPower, but via
the tx-power value in the Includes array. The previous code did not
throw an error, but neither led to the insertion of the value. As a
result of this change, include_tx_power now adds the Tx Power Level
again.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
3 years agodoc/settings-storage: Update documentation of Endpoints
Luiz Augusto von Dentz [Mon, 18 May 2020 20:49:46 +0000 (13:49 -0700)]
doc/settings-storage: Update documentation of Endpoints

Add documentation of DelayReporting storage as that has been added to
the cache.

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