Skip to content

Commit

Permalink
Bluetooth: Add EIR URI (#4617)
Browse files Browse the repository at this point in the history
* bluetooth: Add EIR URI

* bluetooth: Rename EIR_Appearance
  • Loading branch information
antoniovazquezblanco authored Dec 25, 2024
1 parent eb279cc commit cb4a95b
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 1 deletion.
202 changes: 201 additions & 1 deletion scapy/layers/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ class EIR_AdvertisingInterval(EIR_Element):


class EIR_Appearance(EIR_Element):
name = "EIR_Appearance2"
name = "EIR_Appearance"
fields_desc = [
BitEnumField('category', 0, 10, tot_size=-2, enum={
0x000: 'Unknown',
Expand Down Expand Up @@ -1359,6 +1359,205 @@ def extract_padding(self, s):
return s[:plen], s[plen:]


class EIR_URI(EIR_Element):
name = 'EIR URI'
fields_desc = [
ByteEnumField('scheme', 0, {
0x01: '',
0x02: 'aaa:',
0x03: 'aaas:',
0x04: 'about:',
0x05: 'acap:',
0x06: 'acct:',
0x07: 'cap:',
0x08: 'cid:',
0x09: 'coap:',
0x0A: 'coaps:',
0x0B: 'crid:',
0x0C: 'data:',
0x0D: 'dav:',
0x0E: 'dict:',
0x0F: 'dns:',
0x10: 'file:',
0x11: 'ftp:',
0x12: 'geo:',
0x13: 'go:',
0x14: 'gopher:',
0x15: 'h323:',
0x16: 'http:',
0x17: 'https:',
0x18: 'iax:',
0x19: 'icap:',
0x1A: 'im:',
0x1B: 'imap:',
0x1C: 'info:',
0x1D: 'ipp:',
0x1E: 'ipps:',
0x1F: 'iris:',
0x20: 'iris.beep:',
0x21: 'iris.xpc:',
0x22: 'iris.xpcs:',
0x23: 'iris.lwz:',
0x24: 'jabber:',
0x25: 'ldap:',
0x26: 'mailto:',
0x27: 'mid:',
0x28: 'msrp:',
0x29: 'msrps:',
0x2A: 'mtqp:',
0x2B: 'mupdate:',
0x2C: 'news:',
0x2D: 'nfs:',
0x2E: 'ni:',
0x2F: 'nih:',
0x30: 'nntp:',
0x31: 'opaquelocktoken:',
0x32: 'pop:',
0x33: 'pres:',
0x34: 'reload:',
0x35: 'rtsp:',
0x36: 'rtsps:',
0x37: 'rtspu:',
0x38: 'service:',
0x39: 'session:',
0x3A: 'shttp:',
0x3B: 'sieve:',
0x3C: 'sip:',
0x3D: 'sips:',
0x3E: 'sms:',
0x3F: 'snmp:',
0x40: 'soap.beep:',
0x41: 'soap.beeps:',
0x42: 'stun:',
0x43: 'stuns:',
0x44: 'tag:',
0x45: 'tel:',
0x46: 'telnet:',
0x47: 'tftp:',
0x48: 'thismessage:',
0x49: 'tn3270:',
0x4A: 'tip:',
0x4B: 'turn:',
0x4C: 'turns:',
0x4D: 'tv:',
0x4E: 'urn:',
0x4F: 'vemmi:',
0x50: 'ws:',
0x51: 'wss:',
0x52: 'xcon:',
0x53: 'xconuserid:',
0x54: 'xmlrpc.beep:',
0x55: 'xmlrpc.beeps:',
0x56: 'xmpp:',
0x57: 'z39.50r:',
0x58: 'z39.50s:',
0x59: 'acr:',
0x5A: 'adiumxtra:',
0x5B: 'afp:',
0x5C: 'afs:',
0x5D: 'aim:',
0x5E: 'apt:',
0x5F: 'attachment:',
0x60: 'aw:',
0x61: 'barion:',
0x62: 'beshare:',
0x63: 'bitcoin:',
0x64: 'bolo:',
0x65: 'callto:',
0x66: 'chrome:',
0x67: 'chromeextension:',
0x68: 'comeventbriteattendee:',
0x69: 'content:',
0x6A: 'cvs:',
0x6B: 'dlnaplaysingle:',
0x6C: 'dlnaplaycontainer:',
0x6D: 'dtn:',
0x6E: 'dvb:',
0x6F: 'ed2k:',
0x70: 'facetime:',
0x71: 'feed:',
0x72: 'feedready:',
0x73: 'finger:',
0x74: 'fish:',
0x75: 'gg:',
0x76: 'git:',
0x77: 'gizmoproject:',
0x78: 'gtalk:',
0x79: 'ham:',
0x7A: 'hcp:',
0x7B: 'icon:',
0x7C: 'ipn:',
0x7D: 'irc:',
0x7E: 'irc6:',
0x7F: 'ircs:',
0x80: 'itms:',
0x81: 'jar:',
0x82: 'jms:',
0x83: 'keyparc:',
0x84: 'lastfm:',
0x85: 'ldaps:',
0x86: 'magnet:',
0x87: 'maps:',
0x88: 'market:',
0x89: 'message:',
0x8A: 'mms:',
0x8B: 'mshelp:',
0x8C: 'mssettingspower:',
0x8D: 'msnim:',
0x8E: 'mumble:',
0x8F: 'mvn:',
0x90: 'notes:',
0x91: 'oid:',
0x92: 'palm:',
0x93: 'paparazzi:',
0x94: 'pkcs11:',
0x95: 'platform:',
0x96: 'proxy:',
0x97: 'psyc:',
0x98: 'query:',
0x99: 'res:',
0x9A: 'resource:',
0x9B: 'rmi:',
0x9C: 'rsync:',
0x9D: 'rtmfp:',
0x9E: 'rtmp:',
0x9F: 'secondlife:',
0xA0: 'sftp:',
0xA1: 'sgn:',
0xA2: 'skype:',
0xA3: 'smb:',
0xA4: 'smtp:',
0xA5: 'soldat:',
0xA6: 'spotify:',
0xA7: 'ssh:',
0xA8: 'steam:',
0xA9: 'submit:',
0xAA: 'svn:',
0xAB: 'teamspeak:',
0xAC: 'teliaeid:',
0xAD: 'things:',
0xAE: 'udp:',
0xAF: 'unreal:',
0xB0: 'ut2004:',
0xB1: 'ventrilo:',
0xB2: 'viewsource:',
0xB3: 'webcal:',
0xB4: 'wtai:',
0xB5: 'wyciwyg:',
0xB6: 'xfire:',
0xB7: 'xri:',
0xB8: 'ymsgr:',
0xB9: 'example:',
0xBA: 'mssettingscloudstorage:'
}),
StrLenField('uri_hier_part', None, length_from=EIR_Element.length_from)
]

@property
def uri(self):
return EIR_URI.scheme.i2s[self.scheme] + self.uri_hier_part.decode('utf-8')


class HCI_Command_Hdr(Packet):
name = "HCI Command header"
fields_desc = [XBitField("ogf", 0, 6, tot_size=-2),
Expand Down Expand Up @@ -2452,6 +2651,7 @@ class HCI_LE_Meta_Long_Term_Key_Request(Packet):
bind_layers(EIR_Hdr, EIR_AdvertisingInterval, type=0x1a)
bind_layers(EIR_Hdr, EIR_ServiceData32BitUUID, type=0x20)
bind_layers(EIR_Hdr, EIR_ServiceData128BitUUID, type=0x21)
bind_layers(EIR_Hdr, EIR_URI, type=0x24)
bind_layers(EIR_Hdr, EIR_Manufacturer_Specific_Data, type=0xff)
bind_layers(EIR_Hdr, EIR_Raw)

Expand Down
8 changes: 8 additions & 0 deletions test/scapy/layers/bluetooth.uts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ p = HCI_Hdr(hex_bytes('042fff01c47c80894df801000c0128a269a30c4a125d13f30196894df
assert EIR_ServiceData32BitUUID in p
assert p[EIR_ServiceData32BitUUID].svc_uuid == 0x001a1af6

= Parse EIR_URI

p = HCI_Event_Hdr(hex_bytes('3e2902010301f3c1dad728031d1c24172f2f6669726d776172652e73696c766169722e636f6d2f6f6f62ac'))
assert EIR_URI in p
assert p[EIR_URI].scheme == 0x17
assert p[EIR_URI].uri_hier_part == b'//firmware.silvair.com/oob'
assert p[EIR_URI].uri == 'https://firmware.silvair.com/oob'

= Parse EIR_Flags, EIR_CompleteList16BitServiceUUIDs, EIR_CompleteLocalName and EIR_TX_Power_Level

ad_report_raw_data = \
Expand Down

0 comments on commit cb4a95b

Please sign in to comment.