Replies: 1 comment
-
You have done your research! 😄 I think the minimum enum is better (to avoid having to It could also be useful to add a I don't consider the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm looking to add support for getting the address type for a
BLEDevice
. This is a (I think) a fairly small change for backends that support it. Mostly it's just getting an API that works for the bleak maintainers, so I thought I should start a discussion first.For context, as per https://novelbits.io/bluetooth-address-privacy-ble/, there are 4 address types. A device can be public or random. Public addresses are static, and you can use the OUI data to get a vendor. With random you cannot, and the address may or may not change over time.
If you know an address is random, differentiating between the 3 types of random address can be done by masking one octet of the mac address. For example:
However, a device can be public and pass these tests - that would be incorrect. So I need to surface the address type from the bluetooth stack in order to be able to reliably use these tests.
Backend support
There is some support for this in bleaks backend, though it is not universal:
AddressType
and can bepublic
orrandom
.winrt
has an enum (see https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothaddresstype?view=winrt-22621). It is available in Windows 1511 or later on BluetoothLEDevice (https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.bluetoothledevice?view=winrt-22621). It's available on BluetoothLEAdvertisementReceivedEventArgs too: https://learn.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementreceivedeventargs?view=winrt-22621Implementation
At the bare minimum I would like to have an enum like this:
Then extend
BLEDevice
to haveaddress_type
alongsideaddress
.Given
UNKNOWN
is a valid value on some backends, I think its fair to just returnUNKNOWN
on any backend where this isn't supported.For backwards compatibility, the constructor of BLEDevice could use a kwarg and default to unknown. Either use a
kwargs.get('address_type', AddressType.UNKNOWN)
or maybe:Finally, the enum could be extended to cover the 3 random subtypes - and the masking could happen in bleak when the BLEDevice is constructed.
This would probably be my preference, but as long as I know whether an address is public or random, I can if needed handle the rest downstream.
Beta Was this translation helpful? Give feedback.
All reactions