Skip to content

"ValueError: Sub-data not available" when trying to parse vendor VariableItem #28

@haku

Description

@haku

I am trying to reverse engineer a device with a bunch of vendor specific report formats. I think I might have found an issue in VariableItem when parsing vendor messages:

Traceback (most recent call last):
  File "/home/haku/src/usbhid-experiments/./test-parse.py", line 56, in <module>
    for usage, value in desc.parse_input_report(data).items():
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/haku/.cache/pyvenv-hid/lib/python3.12/site-packages/hid_parser/__init__.py", line 690, in parse_input_report
    return self._parse_report(self._input, data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/haku/.cache/pyvenv-hid/lib/python3.12/site-packages/hid_parser/__init__.py", line 687, in _parse_report
    return self._parse_report_items(item_poll[data[0]], data[1:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/haku/.cache/pyvenv-hid/lib/python3.12/site-packages/hid_parser/__init__.py", line 669, in _parse_report_items
    parsed[item.usage] = item.parse(data)
                         ^^^^^^^^^^^^^^^^
  File "/home/haku/.cache/pyvenv-hid/lib/python3.12/site-packages/hid_parser/__init__.py", line 433, in parse
    if hid_parser.data.UsageTypes.LINEAR_CONTROL in self.usage.usage_types or any(
                                                    ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/haku/.cache/pyvenv-hid/lib/python3.12/site-packages/hid_parser/__init__.py", line 237, in usage_types
    usage_page = hid_parser.data.UsagePages.get_subdata(self.page)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/haku/.cache/pyvenv-hid/lib/python3.12/site-packages/hid_parser/data.py", line 159, in get_subdata
    raise ValueError(msg)
ValueError: Sub-data not available

I have a script that reproduces the issue here: https://github.com/haku/usbhid-experiments/blob/main/test-parse.py

The issue appears to be that hid_parser.data.UsagePages.get_subdata(page) fails with this exception for any value of page within the VENDOR_PAGE range. While this library's test cases in test_parse.py do test parsing vendor reports, all the data types defined are arrays which have a different decode code path.

I am still learning my way around this library so not entirely sure what the fix should be, but I am happy to spend some more time figuring it out if that would be helpful for you?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions