Skip to content

usbdevice: hid_prepare() writes text instead of binary HID report descriptor #6

@frankurcrazy

Description

@frankurcrazy

Bug Description

The hid_prepare() function in /usr/bin/usbdevice uses echo -ne to write the HID report descriptor:

echo -ne "\\x05\\x01\\x09\\x06..." > report_desc

On systems where /bin/sh is dash (not bash), echo does not support the -ne flags. It outputs -ne and the \x escape sequences as literal text instead of binary bytes.

The report descriptor file ends up containing:

00000000: 2d6e 6520 5c78 3035 5c78 3031  -ne \x05\x01

Instead of the correct binary:

00000000: 0501 0906 a101 0507              ........

Impact

  • The USB host cannot parse the HID descriptor during enumeration
  • The host sends infinite bus resets, UDC state stuck at default
  • Writes to /dev/hidg0 block indefinitely
  • HID keyboard emulation is completely non-functional

Fix

Replace echo -ne with printf using octal escapes (hex escapes also don't work in dash's printf):

hid_prepare()
{
	printf '\005\001\011\006\241\001\005\007\031\340\051\347\025\000\045\001\165\001\225\010\201\002\225\001\165\010\201\003\225\005\165\001\005\010\031\001\051\005\221\002\225\001\165\003\221\003\225\006\165\010\025\000\045\145\005\007\031\000\051\145\201\000\300' > report_desc
	echo 1 > protocol
	echo 1 > subclass
	echo 8 > report_length
}

Environment

  • Board: RK3588 (LubanCat)
  • Kernel: 5.10.160
  • /bin/sh → dash

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