python-usb-protocol icon indicating copy to clipboard operation
python-usb-protocol copied to clipboard

Fix EndpointDescriptor

Open twam opened this issue 3 years ago • 1 comments

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

twam avatar Feb 19 '22 15:02 twam

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.

antoinevg avatar Apr 15 '24 12:04 antoinevg