Skip to content

Commit

Permalink
Add test of reconstructing PS5 configuration descriptor.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Nov 14, 2024
1 parent 08f42bf commit 4f9d760
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/test_descriptors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from facedancer import USBDevice, USBConfiguration
import unittest

# Configuration descriptor captured from PS5 DualSense controller.
config_data = bytes([
0x09, 0x02, 0xE3, 0x00, 0x04, 0x01, 0x00, 0xC0, 0xFA,
0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
0x0A, 0x24, 0x01, 0x00, 0x01, 0x49, 0x00, 0x02, 0x01, 0x02,
0x0C, 0x24, 0x02, 0x01, 0x01, 0x01, 0x06, 0x04, 0x33, 0x00, 0x00, 0x00,
0x0C, 0x24, 0x06, 0x02, 0x01, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x04, 0x02, 0x00,
0x0C, 0x24, 0x02, 0x04, 0x02, 0x04, 0x03, 0x02, 0x03, 0x00, 0x00, 0x00,
0x09, 0x24, 0x06, 0x05, 0x04, 0x01, 0x03, 0x00, 0x00,
0x09, 0x24, 0x03, 0x06, 0x01, 0x01, 0x01, 0x05, 0x00,
0x09, 0x04, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
0x09, 0x04, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,
0x07, 0x24, 0x01, 0x01, 0x01, 0x01, 0x00,
0x0B, 0x24, 0x02, 0x01, 0x04, 0x02, 0x10, 0x01, 0x80, 0xBB, 0x00,
0x09, 0x05, 0x01, 0x09, 0x88, 0x01, 0x04, 0x00, 0x00,
0x07, 0x25, 0x01, 0x00, 0x00, 0x00, 0x00,
0x09, 0x04, 0x02, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
0x09, 0x04, 0x02, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00,
0x07, 0x24, 0x01, 0x06, 0x01, 0x01, 0x00,
0x0B, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x01, 0x80, 0xBB, 0x00,
0x09, 0x05, 0x82, 0x05, 0xC4, 0x00, 0x04, 0x00, 0x00,
0x07, 0x25, 0x01, 0x00, 0x00, 0x00, 0x00,
0x09, 0x04, 0x03, 0x00, 0x02, 0x03, 0x00, 0x00, 0x00,
0x09, 0x21, 0x11, 0x01, 0x00, 0x01, 0x22, 0x11, 0x01,
0x07, 0x05, 0x84, 0x03, 0x40, 0x00, 0x06,
0x07, 0x05, 0x03, 0x03, 0x40, 0x00, 0x06
])

class TestDescriptors(unittest.TestCase):

def test_descriptor_reconstruction(self):
configuration = USBConfiguration.from_binary_descriptor(config_data)

device = USBDevice()
device.add_configuration(configuration)

assert(configuration.get_descriptor() == config_data)

if __name__ == "__main__":
unittest.main()

0 comments on commit 4f9d760

Please sign in to comment.