Skip to content

usb-device-hid: MouseInterface reports bInterfaceProtocol 1 (keyboard) instead of 2 #1176

Open

Description

@Duhan07

MouseInterface is enumerated as a boot keyboard, its interface descriptor has bInterfaceSubClass 1 and bInterfaceProtocol 1, but it should be protocol 2 (mouse).

Cause

HIDInterface.protocol stores both the descriptor protocol and the runtime protocol mode. desc_cfg() ends with self.protocol = 1 (report mode), and Device.config() calls desc_cfg() twice (once to measure the length, once to write). So the second call writes 1 for every boot interface.

Reproduction

  • MicroPython v1.29.0, ESP32_GENERIC_S3 (ESP32-S3, 2 MB PSRAM)
  • usb-device-hid 0.2.0, usb-device-mouse, installed with mip
from usb.device.core import Descriptor
from usb.device.mouse import MouseInterface

m = MouseInterface()
d = Descriptor(None)        # pass 1, as in Device.config()
m.desc_cfg(d, 0, 0, [])
buf = bytearray(d.o)
d = Descriptor(buf)          # pass 2
m.desc_cfg(d, 3, 1, [])
print(" ".join("%02x" % b for b in buf[:9]))

Output: 09 04 03 00 01 03 01 01 00 (last-but-one byte should be 02). macOS ioreg shows the same for interface "MicroPython Mouse".

Suggested fix

Store the descriptor value in a separate attribute (e.g. interface_protocol) and keep protocol for the runtime mode. I have tested this on the board.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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