greatscottgadgets / python-usb-protocol

python library providing utilities, data structures, constants, parsers, and tools for working with USB data
BSD 3-Clause "New" or "Revised" License
55 stars 32 forks source link

Fix EndpointDescriptor #26

Open twam opened 2 years ago

twam commented 2 years ago

Fix creation of EndpointDescriptor and add unit tests for both possible lengths.

antoinevg commented 7 months ago

Your PR is failing the test_descriptor_collection unit test:

got:      [9, 2, 32, 0, 1, 1, 0, 128, 250, 9, 4, 1, 0, 2, 255, 255, 255, 0, 9, 5, 129, 2, 64, 0, 255, 9, 5, 1, 2, 64, 0, 255] 
expected: [9, 2, 32, 0, 1, 1, 0, 128, 250, 9, 4, 1, 0, 2, 255, 255, 255, 0, 7, 5, 129, 2, 64, 0, 255, 7, 5, 1, 2, 64, 0, 255] 

https://github.com/greatscottgadgets/python-usb-protocol/blob/f7b287f87688b626eadc157c9568edbd7044081e/usb_protocol/emitters/descriptors/standard.py#L569

Your approach works when creating the descriptor using EndpointDescriptor.build() but using the context manager syntax with i.EndpointDescriptor() as e: the descriptor's bLength field will be set to 9 even when the optional fields aren't specified.