Skip to content

Commit

Permalink
bluetooth: Add EIR service solicitation types (#4602)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniovazquezblanco authored Dec 11, 2024
1 parent 535fc33 commit a8583a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scapy/layers/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,30 @@ class EIR_Device_ID(EIR_Element):
]


class EIR_ServiceSolicitation16BitUUID(EIR_Element):
name = "EIR Service Solicitation - 16-bit UUID"
fields_desc = [
XLEShortField("svc_uuid", None)
]

def extract_padding(self, s):
# Needed to end each EIR_Element packet and make PacketListField work.
plen = EIR_Element.length_from(self) - 2
return s[:plen], s[plen:]


class EIR_ServiceSolicitation128BitUUID(EIR_Element):
name = "EIR Service Solicitation - 128-bit UUID"
fields_desc = [
UUIDField('svc_uuid', None, uuid_fmt=UUIDField.FORMAT_REV)
]

def extract_padding(self, s):
# Needed to end each EIR_Element packet and make PacketListField work.
plen = EIR_Element.length_from(self) - 2
return s[:plen], s[plen:]


class EIR_ServiceData16BitUUID(EIR_Element):
name = "EIR Service Data - 16-bit UUID"
fields_desc = [
Expand Down Expand Up @@ -2348,6 +2372,8 @@ class HCI_LE_Meta_Long_Term_Key_Request(Packet):
bind_layers(EIR_Hdr, EIR_SecureSimplePairingRandomizerR192, type=0x0f)
bind_layers(EIR_Hdr, EIR_SecurityManagerOOBFlags, type=0x11)
bind_layers(EIR_Hdr, EIR_PeripheralConnectionIntervalRange, type=0x12)
bind_layers(EIR_Hdr, EIR_ServiceSolicitation16BitUUID, type=0x14)
bind_layers(EIR_Hdr, EIR_ServiceSolicitation128BitUUID, type=0x15)
bind_layers(EIR_Hdr, EIR_ServiceData16BitUUID, type=0x16)
bind_layers(EIR_Hdr, EIR_PublicTargetAddress, type=0x17)
bind_layers(EIR_Hdr, EIR_ServiceData32BitUUID, type=0x20)
Expand Down
7 changes: 7 additions & 0 deletions test/scapy/layers/bluetooth.uts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,13 @@ except TypeError:
else:
assert False, "expected exception"

= Parse EIR_ServiceSolicitation16BitUUID and EIR_ServiceSolicitation128BitUUID

d = hex_bytes("043e29020100013d1ef10747d81d0319000002010603140d181115d0002d121e4b0fa4994eceb531f40579aa")
p = HCI_Hdr(d)
assert p[EIR_ServiceSolicitation16BitUUID].svc_uuid == 0x180d
assert p[EIR_ServiceSolicitation128BitUUID].svc_uuid == UUID('7905f431-b5ce-4e99-a40f-4b1e122d00d0')

= Parse EIR_ServiceData16BitUUID

d = hex_bytes("043e1902010001abcdef7da97f0d020102030350fe051650fee6c2ac")
Expand Down

0 comments on commit a8583a5

Please sign in to comment.