Skip to content

bluetooth: Add version and company identifiers to local version commands #4716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scapy/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ def _process_data(fdesc):
return manufdb


@scapy_data_cache("bluetoothids")
def load_bluetoothids(filename=None):
# type: (Optional[str]) -> Dict[int, str]
"""Load Bluetooth IDs into the cache"""
from scapy.libs.bluetoothids import DATA
return cast(Dict[int, str], DATA)


def select_path(directories, filename):
# type: (List[str], str) -> Optional[str]
"""Find filename among several directories"""
Expand Down Expand Up @@ -613,6 +621,8 @@ def select_path(directories, filename):
)
)

BLUETOOTH_CORE_COMPANY_IDENTIFIERS = load_bluetoothids()


#####################
# knowledge bases #
Expand Down
33 changes: 28 additions & 5 deletions scapy/layers/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from scapy.data import (
DLT_BLUETOOTH_HCI_H4,
DLT_BLUETOOTH_HCI_H4_WITH_PHDR,
DLT_BLUETOOTH_LINUX_MONITOR
DLT_BLUETOOTH_LINUX_MONITOR,
BLUETOOTH_CORE_COMPANY_IDENTIFIERS
)
from scapy.packet import bind_layers, Packet
from scapy.fields import (
Expand Down Expand Up @@ -266,6 +267,24 @@ class HCI_PHDR_Hdr(Packet):
'extended_features',
]

_bluetooth_core_specification_versions = {
0x00: '1.0b',
0x01: '1.1',
0x02: '1.2',
0x03: '2.0+EDR',
0x04: '2.1+EDR',
0x05: '3.0+HS',
0x06: '4.0',
0x07: '4.1',
0x08: '4.2',
0x09: '5.0',
0x0a: '5.1',
0x0b: '5.2',
0x0c: '5.3',
0x0d: '5.4',
0x0e: '6.0',
}


class HCI_Hdr(Packet):
name = "HCI header"
Expand Down Expand Up @@ -1153,9 +1172,13 @@ class EIR_PeripheralConnectionIntervalRange(EIR_Element):

class EIR_Manufacturer_Specific_Data(EIR_Element):
name = "EIR Manufacturer Specific Data"
deprecated_fields = {
"company_id": ("company_identifier", "2.6.2"),
}
fields_desc = [
# https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers
XLEShortField("company_id", None),
LEShortEnumField("company_identifier", None,
BLUETOOTH_CORE_COMPANY_IDENTIFIERS),
]

registered_magic_payloads = {}
Expand Down Expand Up @@ -2445,10 +2468,10 @@ class HCI_Cmd_Complete_Read_Local_Version_Information(Packet):
"""
name = 'Read Local Version Information'
fields_desc = [
ByteField('hci_version', 0),
ByteEnumField('hci_version', 0, _bluetooth_core_specification_versions),
LEShortField('hci_subversion', 0),
ByteField('lmp_version', 0),
LEShortField('company_identifier', 0),
ByteEnumField('lmp_version', 0, _bluetooth_core_specification_versions),
LEShortEnumField('company_identifier', 0, BLUETOOTH_CORE_COMPANY_IDENTIFIERS),
LEShortField('lmp_subversion', 0)]


Expand Down
Loading
Loading