Skip to content

Commit

Permalink
btp: Gap: verify UUIDs in complete list in advertisement
Browse files Browse the repository at this point in the history
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
  • Loading branch information
KKopyscinski authored and mkasenberg committed Jun 27, 2023
1 parent e32a789 commit d646a68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions autopts/pybtp/btp/gap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions autopts/pybtp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d646a68

Please sign in to comment.