I'm trying to setup a custom mouse-like device on a pi zero.

As I have never been using the USB gadget stack before, the following
problem might likely be a configuration failure on my side as well as a
driver issue.

Using the documentation from kernel source
(Documentation/usb/gadget_hid.txt, Documentation/usb/gadget_configfs.txt and
Documentation/ABI/testing/configfs-usb-gadget-hid) it was more or less
straight forward to set up a keyboard emulating device using the provided
example code (hid_gadget_test).

Unfortunately this is not the case with the mouse emulation.

I build the following shell-script to generate a mouse device.  Due to the
lack of an example "report_desc" has been stolen from a logitech mouse:



cd $CONFIGFS_HOME/usb_gadget/
mkdir g1
cd g1
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "Sirius Cybernetics Corp." > strings/0x409/manufacturer 
echo "dummymouse" > strings/0x409/product
mkdir -p functions/hid.$N
# protocol 2 seems to be mouse
echo 2 > functions/hid.$N/protocol
echo 1 > functions/hid.$N/subclass
echo 8 > functions/hid.$N/report_length
# HID Mouse e.g. copy from logitech mouse as follows:
# for i in $(usbhid-dump -a XXX:YYY |tail -n +2); do echo -n \\\\x$i; done |tr 
'[:upper:]' '[:lower:]'
echo -ne 
 > functions/hid.$N/report_desc
hexdump -C functions/hid.$N/report_desc
mkdir -p configs/c.$C/strings/0x409
echo "Config $C: dummymouse" > configs/c.$C/strings/0x409/configuration 
echo 250 > configs/c.$C/MaxPower 
ln -s functions/hid.$N configs/c.$C/
ls /sys/class/udc > UDC

However, this does not work.  First of all, the report_desc is not written
to functions/hid.$N/report_desc as expected.

Instead I get the following truncated stuff which also shows up on the usb host
using usbhid-dump:
00000000  38 02 95 01 81 06 c0 c0                           |8.......|

Thus I enabled debugging on USB hid gadget driver and get the following:
[12381.564157] configfs-gadget gadget: high-speed config #1: c
[12381.577963] <intr> configfs-gadget gadget: hidg_set_alt intf:0 alt:0
[12381.593012] <intr> configfs-gadget gadget: non-core control req21.0a v0000 
i0000 l0
[12381.608761] <intr> configfs-gadget gadget: hidg_setup crtl_request : 
bRequestType:0x21 bRequest:0xa Value:0x0
[12381.626650] <intr> configfs-gadget gadget: Unknown request 0xa
[12381.640731] <intr> configfs-gadget gadget: non-core control req81.06 v2200 
i0000 l8
[12381.656464] <intr> configfs-gadget gadget: hidg_setup crtl_request : 
bRequestType:0x81 bRequest:0x6 Value:0x2200
[12381.674655] <intr> configfs-gadget gadget: USB_REQ_GET_DESCRIPTOR: REPORT

As a result, the device in not detected correctly on the host side as well:
usb 2-1: Product: dummymouse
usb 2-1: Manufacturer: Sirius Cybernetics Corp.
usb 2-1: SerialNumber: fedcba9876543210
hid-generic 0003:1D6B:0104.004F: unknown main item tag 0x0
hid-generic 0003:1D6B:0104.004F: collection stack underflow
hid-generic 0003:1D6B:0104.004F: item 0 0 0 12 parsing failed
hid-generic: probe of 0003:1D6B:0104.004F failed with error -22

Kernel Version is 4.4.35+ from Raspberr Pi repo, but looking at the current
version of drivers/usb/gadget/function/f_hid.c did not seem to have changes
related to thsi topic:


Any hint?



"Remember, democracy never lasts long. It soon wastes itself,
exhausts and murders itself. There never was a democracy yet
that did not commit suicide." (John Quincy Adams)
/me is giggls@ircnet, http://sven.gegg.us/ on the Web
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to