From d646a68b49974e287ac0e0d9414fcb6fbd6de1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Tue, 30 May 2023 09:29:18 +0200 Subject: [PATCH] btp: Gap: verify UUIDs in complete list in advertisement check_discov_results handled only UUIDs listed as AD Type: Incomplete List of 16-bit Service UUIDs. UUID may be listed also in Complete List of 16-bit Service UUIDs. Add option to verify service data that can contain UUIDs --- autopts/pybtp/btp/gap.py | 17 +++++++++++++---- autopts/pybtp/types.py | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/autopts/pybtp/btp/gap.py b/autopts/pybtp/btp/gap.py index 8116a0bf11..7be59c5b84 100644 --- a/autopts/pybtp/btp/gap.py +++ b/autopts/pybtp/btp/gap.py @@ -1182,7 +1182,7 @@ def parse_eir_data(eir): return data -def check_discov_results(addr_type=None, addr=None, discovered=True, eir=None, uuids=None): +def check_discov_results(addr_type=None, addr=None, discovered=True, eir=None, uuids=None, svc_data=None): addr = pts_addr_get(addr).encode('utf-8') addr_type = pts_addr_type_get(addr_type) @@ -1205,15 +1205,24 @@ def check_discov_results(addr_type=None, addr=None, discovered=True, eir=None, u if device.eir: data = parse_eir_data(device.eir) - if uuids and AdType.uuid16_some in data: - eir_uuids = [data[AdType.uuid16_some][i:i + 2] - for i in range(0, len(data[AdType.uuid16_some]), 2)] + if uuids and ((AdType.uuid16_some in data) or + (AdType.uuid16_all in data)): + uuid_list_type = AdType.uuid16_some if \ + (AdType.uuid16_some in data) else \ + AdType.uuid16_all + eir_uuids = [data[uuid_list_type][i:i + 2] + for i in range(0, len(data[uuid_list_type]), 2)] for uuid in uuids: uuid_ba = bytes.fromhex(uuid.replace("-", ""))[::-1] if uuid_ba not in eir_uuids: continue + if svc_data and AdType.uuid16_svc_data in data: + eir_svc_data = data[AdType.uuid16_svc_data] + if svc_data not in eir_svc_data: + continue + found = True break diff --git a/autopts/pybtp/types.py b/autopts/pybtp/types.py index 820e02a137..6ae4fc447d 100644 --- a/autopts/pybtp/types.py +++ b/autopts/pybtp/types.py @@ -64,6 +64,7 @@ class SynchError(Exception): class AdType: flags = 1 uuid16_some = 2 + uuid16_all = 3 name_short = 8 name_full = 9 tx_power = 10