BLESession: Support more adtypes

It was reported that Lego WeDo2 advertises its service class UUIDs with
adtype 0x6 "incomplete 128 bit service class UUIDs". Add this adtype as
well as some more adtypes 0x5, 0x4 and 0x2 defined in Bluetooth spec [1].
Also introduce _get_dev_uuid() helper function to simplify the code.

[1] https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/

Signed-off-by: Shin'ichiro Kawasaki <kawasaki@juno.dti.ne.jp>
This commit is contained in:
Shin'ichiro Kawasaki
2020-07-11 14:06:47 +09:00
parent 0af23d4280
commit 20e65e9f03

View File

@@ -326,8 +326,14 @@ class BLESession(Session):
CONNECTED = 3
DONE = 4
ADTYPE_COMP_16B = 0x3
ADTYPE_COMP_128B = 0x7
SERVICE_CLASS_UUID_ADTYPES = {
0x7: "adtype complete 128b",
0x3: "adtype complete 16b",
0x6: "adtype incomplete 128b",
0x5: "adtype complete 32b",
0x4: "adtype incomplete 32b",
0x2: "adtype incomplete 16b",
}
class BLEThread(threading.Thread):
"""
@@ -418,6 +424,14 @@ class BLESession(Session):
def __del__(self):
self.close()
def _get_dev_uuid(self, dev):
for adtype in self.SERVICE_CLASS_UUID_ADTYPES:
service_class_uuid = dev.getValueText(adtype)
if service_class_uuid:
logger.debug(self.SERVICE_CLASS_UUID_ADTYPES[adtype])
return UUID(service_class_uuid)
return None
def matches(self, dev, filters):
"""
Check if the found BLE device mathces the filters Scracth specifies.
@@ -429,14 +443,9 @@ class BLESession(Session):
logger.debug(f"sevice to check: {s}")
given_uuid = s
logger.debug(f"given: {given_uuid}")
service_class_uuid = dev.getValueText(self.ADTYPE_COMP_128B)
logger.debug(f"adtype 128b: {service_class_uuid}")
if not service_class_uuid:
service_class_uuid = dev.getValueText(self.ADTYPE_COMP_16B)
logger.debug(f"adtype 16b: {service_class_uuid}")
if not service_class_uuid:
continue
dev_uuid = UUID(service_class_uuid)
dev_uuid = self._get_dev_uuid(dev)
if not dev_uuid:
continue
logger.debug(f"dev: {dev_uuid}")
logger.debug(given_uuid == dev_uuid)
if given_uuid == dev_uuid: