Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect BlueTooth devices by GATT service UUID #7127

Merged
merged 5 commits into from May 16, 2024
Merged

Detect BlueTooth devices by GATT service UUID #7127

merged 5 commits into from May 16, 2024

Conversation

d4s
Copy link
Collaborator

@d4s d4s commented Apr 17, 2024

Some BT devices don't provide VID, so fwupd can't detect such devices properly. In the same time, the device might announce service with unique UUID for firmware upgrading.

This commit allows to detect BT devices by UUID of the updating service, for instance:
21608f80-6c9c-5cd1-91ed-0fbf18e31958 ← BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5

In addition, added querying of Battery service if available, and battery percentage is set according to received value

Type of pull request:

@d4s d4s requested a review from hughsie April 17, 2024 22:56
@d4s
Copy link
Collaborator Author

d4s commented Apr 17, 2024

@hughsie devices detection by service UUID.

Please pay attention to Update Error: No vendor ID set -- not sure what to do with it, since it is unable to read from the device.

├─CCC5171:
│     Device ID:          9f455188df0fd268b4b349575f714570967c3815
│     Current version:    1.2.3
│     Serial Number:      B00B5A0123456789
│     Battery:            98% (threshold 10%)
│     Update Error:       No vendor ID set
│     GUIDs:              3a2cfcac-7aa6-5442-a816-88f854a91e46 ← BLUETOOTH\GATT_0000180f-0000-1000-8000-00805f9b34fb
│                         4effb279-74b9-5c5b-a89e-7143bd28bbfa ← BLUETOOTH\GATT_0000184e-0000-1000-8000-00805f9b34fb
│                         3000539e-34f0-5d6d-8b7f-53a99a77bfae ← BLUETOOTH\GATT_00001801-0000-1000-8000-00805f9b34fb
│                         131f3fff-eb99-54a4-8b4d-7d5dc2fecefc ← BLUETOOTH\GATT_0000fd92-0000-1000-8000-00805f9b34fb
│                         5925151e-7277-5fce-b369-be4ab1973f36 ← BLUETOOTH\GATT_0000184f-0000-1000-8000-00805f9b34fb
│                         40a7497e-1ed8-5fd2-af10-7d05e52d07f0 ← BLUETOOTH\GATT_00001853-0000-1000-8000-00805f9b34fb
│                         587447f5-5e47-5bb3-b858-b40fd462001b ← BLUETOOTH\GATT_0000eb10-d102-11e1-9b23-00025b00a5a5
│                         57dfec06-7ff6-5b93-86b5-927b62c69b3c ← BLUETOOTH\GATT_00001858-0000-1000-8000-00805f9b34fb
│                         d62ab18a-55f2-50c8-8242-0d62cfae6e76 ← BLUETOOTH\GATT_00001855-0000-1000-8000-00805f9b34fb
│                         b76293b2-f6a1-5f6d-8263-1e53bfb3a3dd ← BLUETOOTH\GATT_00001850-0000-1000-8000-00805f9b34fb
│                         21608f80-6c9c-5cd1-91ed-0fbf18e31958 ← BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5
│                         7dd48931-f713-5b91-bce9-414498c3411f ← BLUETOOTH\GATT_0000184d-0000-1000-8000-00805f9b34fb
│                         b4e3f963-b131-5628-bb2f-f804eef574fd ← BLUETOOTH\GATT_00001844-0000-1000-8000-00805f9b34fb
│     Device Flags:       • Device stages updates
│                         • Device can recover flash failures
│                         • Device is usable for the duration of the update
│                         • Updatable
│                         • Signed Payload
│   
└─EarFun Air Pro 3:
      Device ID:          e8aaafb1204d42da39dfdb6314097e3b55cc75d3
      Current version:    1.2.3
      Serial Number:      ABCDEF0123456789
      Battery:            100% (threshold 10%)
      Update Error:       No vendor ID set
      GUIDs:              3000539e-34f0-5d6d-8b7f-53a99a77bfae ← BLUETOOTH\GATT_00001801-0000-1000-8000-00805f9b34fb
                          21608f80-6c9c-5cd1-91ed-0fbf18e31958 ← BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5
                          b4e3f963-b131-5628-bb2f-f804eef574fd ← BLUETOOTH\GATT_00001844-0000-1000-8000-00805f9b34fb
                          3a2cfcac-7aa6-5442-a816-88f854a91e46 ← BLUETOOTH\GATT_0000180f-0000-1000-8000-00805f9b34fb
                          4effb279-74b9-5c5b-a89e-7143bd28bbfa ← BLUETOOTH\GATT_0000184e-0000-1000-8000-00805f9b34fb
                          131f3fff-eb99-54a4-8b4d-7d5dc2fecefc ← BLUETOOTH\GATT_0000fd92-0000-1000-8000-00805f9b34fb
                          e4cbed0f-bdc6-5263-957a-cd62306cfa21 ← BLUETOOTH\GATT_0000180a-0000-1000-8000-00805f9b34fb
                          d62ab18a-55f2-50c8-8242-0d62cfae6e76 ← BLUETOOTH\GATT_00001855-0000-1000-8000-00805f9b34fb
                          5925151e-7277-5fce-b369-be4ab1973f36 ← BLUETOOTH\GATT_0000184f-0000-1000-8000-00805f9b34fb
                          40a7497e-1ed8-5fd2-af10-7d05e52d07f0 ← BLUETOOTH\GATT_00001853-0000-1000-8000-00805f9b34fb
                          b76293b2-f6a1-5f6d-8263-1e53bfb3a3dd ← BLUETOOTH\GATT_00001850-0000-1000-8000-00805f9b34fb
                          8830f587-57e8-5eee-8c6d-a1015a60b631 ← BLUETOOTH\GATT_2587db3c-ce70-4fc9-935f-777ab4188fd7
                          587447f5-5e47-5bb3-b858-b40fd462001b ← BLUETOOTH\GATT_0000eb10-d102-11e1-9b23-00025b00a5a5
      Device Flags:       • Device stages updates
                          • Device can recover flash failures
                          • Device is usable for the duration of the update
                          • Updatable
                          • Signed Payload

@d4s
Copy link
Collaborator Author

d4s commented Apr 17, 2024

Here I attached the output from busctl introspect org.bluez ... for both devices connected in BLE mode, just to keep all info here:
ble_busctl_devboard_ble1.txt
ble_busctl_earfun_ble.txt

fu_device_add_instance_str(FU_DEVICE(self), "GATT", obj_uuid);
if (!fu_device_build_instance_id_full(FU_DEVICE(self),
FU_DEVICE_INSTANCE_FLAG_VISIBLE |
FU_DEVICE_INSTANCE_FLAG_QUIRKS,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lose the FU_DEVICE_INSTANCE_FLAG_VISIBLE and then we can still match it in quirks for "interesting device" rather than showing them all to the user as potential matches for firmware.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm... I did a try and have:

11:59:10.360 FuEngine             /org/bluez/hci0/dev_00_02_5B_00_FF_01 added FuBluezDevice:
  Name:                 CCC5171
  Flags:                none
  BatteryLevel:         98
...
  Guid[quirk]:          21608f80-6c9c-5cd1-91ed-0fbf18e31958 <- BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5
...
  PhysicalId:           /org/bluez/hci0
  LogicalId:            00:02:5B:00:FF:01
  BackendId:            /org/bluez/hci0/dev_00_02_5B_00_FF_01
...
11:59:11.061 FuEngine             no GUIDs for device CCC5171 [9f455188df0fd268b4b349575f714570967c3815]

The quirk file:

[BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5]
Plugin = audio_s5gen2
ProxyGType = FuQcS5gen2BleDevice

Works well with FU_DEVICE_INSTANCE_FLAG_VISIBLE flag.
Maybe I missed something else?
I'm trying to register the device, which is working via BLE proxy implementing the Interface for communication.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no GUIDs for device CCC5171

That's actually success! We don't want to use any of the GATT UUIDs for firmware matching. I think you can fix this by adding a GUID (that is used for matching firmware) manually in the quirk file -- maybe even USB\VID_0A12&PID_4007? I think we need to work out how to get a proper VID and PID for the FuQcS5gen2BleDevice device really -- so we know what firmware to suggest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you dump what you see for FuQcS5gen2BleDevice please?

@hughsie
Copy link
Member

hughsie commented May 14, 2024

@d4s mind if i rebase and merge this? There's another vendor interested in this functionality now.

@d4s
Copy link
Collaborator Author

d4s commented May 14, 2024

@d4s mind if i rebase and merge this? There's another vendor interested in this functionality now.

@hughsie sorry for the delay.
Not at the moment, I did a quick check during weekend -- it has a segfault in my test. I'll prepare the fix today/tomorrow.

@d4s
Copy link
Collaborator Author

d4s commented May 15, 2024

@hughsie I found that segfault and additionally moved some querying from my experimental code.

Now the bluez device might look like:

FuBluezDevice:
  Name:                 EarFun Air Pro 3
  Guid:                 dfb271a8-b03d-59ff-832e-b77ed2f4286e ← BLUETOOTH\ALIAS_EarFun Air Pro 3 ⚠
  Serial:               ABCDEF0123456789
  Flags:                none
  Version:              1.0.0."(unreleased)"
  BatteryLevel:         100
  Guid[quirk]:          3000539e-34f0-5d6d-8b7f-53a99a77bfae ← BLUETOOTH\GATT_00001801-0000-1000-8000-00805f9b34fb
  Guid[quirk]:          21608f80-6c9c-5cd1-91ed-0fbf18e31958 ← BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5
  Guid[quirk]:          3a2cfcac-7aa6-5442-a816-88f854a91e46 ← BLUETOOTH\GATT_0000180f-0000-1000-8000-00805f9b34fb
  Guid[quirk]:          131f3fff-eb99-54a4-8b4d-7d5dc2fecefc ← BLUETOOTH\GATT_0000fd92-0000-1000-8000-00805f9b34fb
  Guid[quirk]:          e4cbed0f-bdc6-5263-957a-cd62306cfa21 ← BLUETOOTH\GATT_0000180a-0000-1000-8000-00805f9b34fb
  Guid[quirk]:          587447f5-5e47-5bb3-b858-b40fd462001b ← BLUETOOTH\GATT_0000eb10-d102-11e1-9b23-00025b00a5a5
  Guid[quirk]:          a746c124-07b3-5de8-bedf-ab792d21823c ← BLUETOOTH\MODEL_QCC3072
  Guid[quirk]:          9ad22715-1346-5120-964c-d5794a62b8da ← BLUETOOTH\MANUFACTURER_QCC3072&MODEL_QCC3072
  PhysicalId:           /org/bluez/hci0
  LogicalId:            70:5A:6F:63:AE:41
  BackendId:            /org/bluez/hci0/dev_70_5A_6F_63_AE_41
  AcquiesceDelay:       50
    00002b3a-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0001/char0009
    00002b2a-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0001/char0007
    00002a25-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char0015
    00001103-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0023/char0029
    0000eb14-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service002c/char0034
    00002a24-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char0013
    00002a29-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char0011
    0000eb13-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service002c/char0031
    00002a05-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0001/char0002
    0000eb22-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0036/char003c
    00002a50-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char0021
    00001102-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0023/char0026
    00002b29-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0001/char0005
    00001101-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0023/char0024
    0000eb21-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0036/char003a
    00002a19-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service003f/char0040
    00002a28-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char001b
    0000eb12-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service002c/char002f
    00002a27-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char0017
    0000eb20-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0036/char0037
    0000eb11-d102-11e1-9b23-00025b00a5a5: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service002c/char002d
    00002a2a-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char001f
    00002a23-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char001d
    00002a26-0000-1000-8000-00805f9b34fb: /org/bluez/hci0/dev_70_5A_6F_63_AE_41/service0010/char0019

@d4s d4s requested a review from hughsie May 15, 2024 18:41
@d4s d4s marked this pull request as ready for review May 15, 2024 19:10
@hughsie
Copy link
Member

hughsie commented May 15, 2024

@d4s also, the windows CI build seems to be failing with this -- maybe we need to sprinkle some ifdefs.

@d4s
Copy link
Collaborator Author

d4s commented May 15, 2024

@d4s also, the windows CI build seems to be failing with this -- maybe we need to sprinkle some ifdefs.

@hughsie in that case we need one single ifdef for the whole BlueZ?
right! in the meson.build we have:

bluez = get_option('bluez').disable_auto_if(host_machine.system() != 'linux')

@d4s d4s requested a review from hughsie May 16, 2024 06:33
d4s added 4 commits May 16, 2024 08:45
Signed-off-by: Richard Hughes <richard@hughsie.com>
Signed-off-by: Richard Hughes <richard@hughsie.com>
Added GUID constructed from the Alias. In case if the device has no
Modailas property the VID is not set, and the Alias-based name allows
to clearly match the device:
  e3dfc8e1-e923-55b1-a2b7-1c6d82e312d2 <- BLUETOOTH\ALIAS_CCC5171

Used Alias property instead of the Name, since BlueZ documentation has
the comment for the Name property:
  "This value is only present for completeness. It is better to always
  use the Alias property when displaying the devices name.
  If the Alias property is unset, it will reflect this value which makes
  it more convenient."
https://github.com/luetzel/bluez/blob/master/doc/device-api.txt#L123
Some BT devices don't provide VID, so fwupd can't detect such devices
properly. In the same time, the device might announce service with
unique UUID for firmware upgrading.

This commit allows to detect BT devices by UUID of the updating
service, for instance:
  21608f80-6c9c-5cd1-91ed-0fbf18e31958 ← BLUETOOTH\GATT_00001100-d102-11e1-9b23-00025b00a5a5

In addition, added querying of Battery service if available, and
battery percentage is set according to received value

If Device Information service is available it might also contain
useful information for device identification, see
https://www.bluetooth.com/specifications/dis-1-2/ for a full list.

Also, allow to acquire write and notify for BlueZ devices, which
allows us to interact with the device directly via file descriptor
without D-Bus usage for every data portion.
@hughsie
Copy link
Member

hughsie commented May 16, 2024

in that case we need one single ifdef for the whole BlueZ

Nah, we need to check for bits of GIO_UNIX -- I've fixed it up for you.

@d4s
Copy link
Collaborator Author

d4s commented May 16, 2024

ah! misunderstood your request.

@d4s
Copy link
Collaborator Author

d4s commented May 16, 2024

@hughsie thanks for changes!
I've tested the current variant -- works as expected.

@hughsie hughsie merged commit 8fb5560 into main May 16, 2024
18 checks passed
@hughsie hughsie deleted the wip/d4s/bt_gatt branch May 16, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants