Skip to content

Commit

Permalink
Correct byte order of bcdUSB and bcdDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
mossmann committed Aug 22, 2024
1 parent 38d8815 commit 7058217
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
8 changes: 4 additions & 4 deletions examples/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class TemplateDevice(USBDevice):
supported_languages : tuple = (LanguageIDs.ENGLISH_US,)

# The revision of the device hardware. This doesn't matter to the USB specification,
# but it's sometimes read by drivers.
device_revision : int = 0
# but it's sometimes read by drivers. 0x0001 represents "0.1" in BCD.
device_revision : int = 0x0001

# The revision of the USB specification that this device adheres to.
# Typically, you'll leave this at '2'.
usb_spec_version : int = 0x0002
# Typically, you'll leave this at 0x0200 which represents "2.0" in BCD.
usb_spec_version : int = 0x0200


#
Expand Down
18 changes: 6 additions & 12 deletions facedancer/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class USBBaseDevice(USBDescribable, USBRequestHandler):
supported_languages : tuple = (LanguageIDs.ENGLISH_US,)

device_revision : int = 0
usb_spec_version : int = 0x0002
usb_spec_version : int = 0x0200

device_speed : DeviceSpeed = None

Expand All @@ -100,14 +100,10 @@ def from_binary_descriptor(cls, data):
data += b"\0" * padding_necessary

# Parse the core descriptor into its components...
spec_version_msb, spec_version_lsb, device_class, device_subclass, device_protocol, \
max_packet_size_ep0, vendor_id, product_id, device_rev_msb, device_rev_lsb, \
spec_version, device_class, device_subclass, device_protocol, \
max_packet_size_ep0, vendor_id, product_id, device_rev, \
manufacturer_string_index, product_string_index, \
serial_number_string_index, num_configurations = struct.unpack_from("<xxBBBBBBHHBBBBBB", data)

# Generate our BCD arguments.
spec_version = (spec_version_msb << 8) | spec_version_lsb
device_rev = (device_rev_msb << 8) | device_rev_lsb
serial_number_string_index, num_configurations = struct.unpack_from("<xxHBBBBHHHBBBB", data)

device = cls(
device_class=device_class,
Expand Down Expand Up @@ -669,13 +665,11 @@ def set_address(self, address: int, defer: bool = False):
def get_descriptor(self) -> bytes:
""" Returns a complete descriptor for this device. """

# FIXME: use construct, here!

d = bytearray([
18, # length of descriptor in bytes
1, # descriptor type 1 == device
(self.usb_spec_version >> 8) & 0xff,
self.usb_spec_version & 0xff,
(self.usb_spec_version >> 8) & 0xff,
self.device_class,
self.device_subclass,
self.protocol_revision_number,
Expand All @@ -684,8 +678,8 @@ def get_descriptor(self) -> bytes:
(self.vendor_id >> 8) & 0xff,
self.product_id & 0xff,
(self.product_id >> 8) & 0xff,
(self.device_revision >> 8) & 0xff,
self.device_revision & 0xff,
(self.device_revision >> 8) & 0xff,
self.strings.get_index(self.manufacturer_string),
self.strings.get_index(self.product_string),
self.strings.get_index(self.serial_number_string),
Expand Down

0 comments on commit 7058217

Please sign in to comment.