Jc2k / aiohomekit

asyncio for homekit
Apache License 2.0
52 stars 19 forks source link

Some services are missing when using BlueZ #135

Open bdraco opened 2 years ago

bdraco commented 2 years ago

00000043-0000-1000-8000-0026BB765291 seen on MacOS but not Linux MACOS-homekit_controller-8629db23450ebc36b5589c3d6d653bd0-SYLVANIA Flex S-dbd7e25d780c89b5bf42b8736df88d14.json.txt LINUX-homekit_controller-8526992f05c02cbd3de691614408810f-SYLVANIA Flex S-9358632dace670c1fdbe50fe8c7dabba.json.txt

bdraco commented 2 years ago

https://github.com/WebBluetoothCG/web-bluetooth/issues/513

bdraco commented 2 years ago

the service uuid is there, but its not being enumerated by bluez

[bluetooth]# info FA:8F:A4:3F:A3:2B
Device FA:8F:A4:3F:A3:2B (random)
    Name: SYLVANIA Flex SA C-3225
    Alias: SYLVANIA Flex SA C-3225
    Paired: no
    Trusted: no
    Blocked: no
    Connected: no
    LegacyPairing: no
    UUID: Vendor specific           (0000003e-0000-1000-8000-0026bb765291)
    UUID: Vendor specific           (00000043-0000-1000-8000-0026bb765291)
    UUID: Vendor specific           (00000055-0000-1000-8000-0026bb765291)
    UUID: Vendor specific           (000000a2-0000-1000-8000-0026bb765291)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: Vendor specific           (1b7e8251-2877-41c3-b46e-cf057c562023)
    UUID: Vendor specific           (ae5d1e47-5c13-43a0-8635-82ad38a1381f)
    UUID: Vendor specific           (b0733e83-8434-4c00-a344-25d1c982a0ef)
    ManufacturerData Key: 0x004c
    ManufacturerData Value:
bdraco commented 2 years ago
[bluetooth]# list-attributes FA:8F:A4:3F:A3:2B
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff3a
    1b7e8251-2877-41c3-b46e-cf057c562023
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff3a/charff3e
    8ac32d3f-5cb9-4d44-bec2-ee689169f626
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff3a/charff3e/descff40
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff3a/charff3b
    5e9bf2a8-f93f-4481-a67e-3b2f4a07891a
    Vendor specific
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11
    b0733e83-8434-4c00-a344-25d1c982a0ef
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff1e
    b31259a5-9acc-45c2-838a-956f57825196
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff1e/descff20
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff1b
    b2fd7f2d-ead3-4f17-b16c-202ec758c697
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff1b/descff1d
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff17
    b176bd7f-4148-47bd-a6c6-9d0796e96183
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff17/descff1a
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff17/descff19
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff14
    000000a5-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff14/descff16
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff11/charff12
    e604e95d-a759-4817-87d3-aa005083a0d1
    Vendor specific
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff00
    ae5d1e47-5c13-43a0-8635-82ad38a1381f
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff00/charff06
    a47f7608-2e2d-47eb-913b-75d4edc4de4b
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff00/charff04
    a2e86c7a-d961-4091-b74f-2409e72efe26
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff00/charff01
    a3dd50bf-f7a7-4e99-838e-570a086c661b
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/serviceff00/charff01/descff03
    00002902-0000-1000-8000-00805f9b34fb
    Client Characteristic Configuration
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0
    00000055-0000-1000-8000-0026bb765291
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00fc
    00000050-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00fc/desc00fe
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f9
    0000004f-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f9/desc00fb
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f6
    0000004e-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f6/desc00f8
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f3
    0000004c-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f3/desc00f5
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service00f0/char00f1
    e604e95d-a759-4817-87d3-aa005083a0d1
    Vendor specific
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0040
    000000a2-0000-1000-8000-0026bb765291
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0040/char0046
    00000037-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0040/char0046/desc0048
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0040/char0043
    000000a5-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0040/char0043/desc0045
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0040/char0041
    e604e95d-a759-4817-87d3-aa005083a0d1
    Vendor specific
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028
    0000003e-0000-1000-8000-0026bb765291
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char003d
    00000220-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char003d/desc003f
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char003a
    00000052-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char003a/desc003c
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0037
    00000030-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0037/desc0039
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0034
    00000023-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0034/desc0036
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0031
    00000021-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0031/desc0033
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char002e
    00000020-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char002e/desc0030
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char002b
    00000014-0000-1000-8000-0026bb765291
    Vendor specific
Descriptor (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char002b/desc002d
    dc46f0fe-81d2-4616-b5d9-6abdd796939a
    Vendor specific
Characteristic (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0028/char0029
    e604e95d-a759-4817-87d3-aa005083a0d1
    Vendor specific
Primary Service (Handle 0x0000)
    /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0001
    00001801-0000-1000-8000-00805f9b34fb
    Generic Attribute Profile
bdraco commented 2 years ago

2022-08-08 14:10:35.618 DEBUG (MainThread) [bleak.backends.bluezdbus.manager] received D-Bus signal: org.freedesktop.DBus.ObjectManager.InterfacesAdded (/): ['/org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0050/char0080', {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': <dbus_next.signature.Variant ('s', 00000025-0000-1000-8000-0026bb765291)>, 'Service': <dbus_next.signature.Variant ('o', /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0050)>, 'Value': <dbus_next.signature.Variant ('ay', bytearray(b''))>, 'Notifying': <dbus_next.signature.Variant ('b', False)>, 'Flags': <dbus_next.signature.Variant ('as', ['read', 'write', 'indicate'])>, 'MTU': <dbus_next.signature.Variant ('q', 515)>}, 'org.freedesktop.DBus.Properties': {}}]

But it does like it is coming over but we never end up with it the char table

bdraco commented 2 years ago

So the char is there, but the desc is missing 2022-08-08 14:10:35.618 DEBUG (MainThread) [bleak.backends.bluezdbus.manager] received D-Bus signal: org.freedesktop.DBus.ObjectManager.InterfacesAdded (/): ['/org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0050/char0080', {'org.freedesktop.DBus.Introspectable': {}, 'org.bluez.GattCharacteristic1': {'UUID': <dbus_next.signature.Variant ('s', 00000025-0000-1000-8000-0026bb765291)>, 'Service': <dbus_next.signature.Variant ('o', /org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B/service0050)>, 'Value': <dbus_next.signature.Variant ('ay', bytearray(b''))>, 'Notifying': <dbus_next.signature.Variant ('b', False)>, 'Flags': <dbus_next.signature.Variant ('as', ['read', 'write', 'indicate'])>, 'MTU': <dbus_next.signature.Variant ('q', 515)>}, 'org.freedesktop.DBus.Properties': {}}]

bdraco commented 2 years ago
2022-08-09 10:58:51.035 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry SYLVANIA Flex S for homekit_controller
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 357, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/__init__.py", line 42, in async_setup_entry
    await conn.async_setup()
  File "/usr/src/homeassistant/homeassistant/components/homekit_controller/connection.py", line 204, in async_setup
    await self.pairing.async_populate_accessories_state(force_update=True)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 550, in async_populate_accessories_state
    await self._async_populate_accessories_state(force_update)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 100, in _async_wrap
    return await func(self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/client.py", line 62, in _async_wrap
    return await func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 560, in _async_populate_accessories_state
    await self._populate_accessories_and_characteristics(force_update)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 597, in _populate_accessories_and_characteristics
    await self._populate_char_values(config_changed)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 529, in _populate_char_values
    results = await self._get_characteristics_while_connected(chars)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 718, in _get_characteristics_while_connected
    data = await self._async_request_under_lock(OpCode.CHAR_READ, char)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/pairing.py", line 270, in _async_request_under_lock
    endpoint = self.client.get_characteristic(char.service.type, char.type)
  File "/usr/local/lib/python3.10/site-packages/aiohomekit/controller/ble/bleak.py", line 31, in get_characteristic
    char = self.services.get_service(service_type).get_characteristic(
AttributeError: 'NoneType' object has no attribute 'get_characteristic'
bdraco commented 2 years ago

We get this back from dbus 2022-08-09 11:11:02.209 DEBUG (MainThread) [bleak.backends.bluezdbus.manager] received D-Bus signal: org.freedesktop.DBus.Properties.PropertiesChanged (/org/bluez/hci0/dev_FA_8F_A4_3F_A3_2B): ['org.bluez.Device1', {'UUIDs': <dbus_next.signature.Variant ('as', ['0000003e-0000-1000-8000-0026bb765291', '00000043-0000-1000-8000-0026bb765291', '00000055-0000-1000-8000-0026bb765291', '000000a2-0000-1000-8000-0026bb765291', '00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '1b7e8251-2877-41c3-b46e-cf057c562023', 'ae5d1e47-5c13-43a0-8635-82ad38a1381f', 'b0733e83-8434-4c00-a344-25d1c982a0ef'])>, 'ServicesResolved': <dbus_next.signature.Variant ('b', True)>}, []]

But 00000043-0000-1000-8000-0026bb765291 never gets an InterfaceAdded callback

bdraco commented 2 years ago

https://github.com/bluez/bluez/issues/30

bdraco commented 2 years ago

Could be related to https://github.com/bluez/bluez/issues/316 but I don't think so

dlech commented 2 years ago

Did you log Bluetooth packets with Wireshark to see if this device isn't following the Bluetooth spec which could cause BlueZ to skip the characteristic?

bdraco commented 2 years ago

I did but its sitting on a computer 4000 miles away that I can't get to at the moment.

Let me see if I have one of them here.

bdraco commented 2 years ago

Found a device that has the issue. Any specific capture flags that would be helpful?

bdraco commented 2 years ago

syl.pcap.zip

Here it the pairing attempt with the missing chars

bdraco commented 2 years ago
[Destination: eb:4a:1b:6e:b7:83 (eb:4a:1b:6e:b7:83)]
dlech commented 2 years ago

Based on the linked BlueZ issues, I would look at the "Read By Group Type Response" packets.

bdraco commented 1 year ago
Nov 06 19:14:58 homeassistant bluetoothd[401]: src/device.c:store_chrc() Error storing characteristic - can't get data
Nov 06 19:14:58 homeassistant bluetoothd[401]: src/device.c:store_chrc() Error storing characteristic - can't get data

This appears in the log for the chars that it can't process

bdraco commented 1 year ago

I was hoping the patches in https://github.com/home-assistant/operating-system/issues/2285 would fix this issue but it looks like its a different problem with BlueZ

Dec 24 00:31:37 homeassistant bluetoothd[406]: src/device.c:store_chrc() Error storing characteristic - can't get data
Dec 24 00:31:37 homeassistant bluetoothd[406]: src/device.c:store_chrc() Error storing characteristic - can't get data
bdraco commented 1 year ago

It might be fixed in newer bluez actually since Error storing characteristic no longer appears in the bluez source

bdraco commented 4 months ago

might be solved by https://github.com/bluez/bluez/commit/7604a577c9d7bf15c9144b8154842ce277afec90