Re: USB gadget: configfs hid mouse device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 12/01/2016 02:35 PM, Sven Geggus wrote:
> Hello,
> 
> 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:
> 
> --cut--
> #!/bin/bash
> 
> CONFIGFS_HOME=/sys/kernel/config
> C=1
> N="usb0"
> 
> 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 \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x08\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x05\\x01\\x16\\x01\\xf8\\x26\\xff\\x07\\x75\\x0c\\x95\\x02\\x09\\x30\\x09\\x31\\x81\\x06\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x01\\x09\\x38\\x81\\x06\\x05\\x0c\\x0a\\x38\\x02\\x95\\x01\\x81\\x06\\xc0\\xc0 > 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
> --cut--
> 
> 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.......|
> 00000008
> 
> 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:
> 
> https://github.com/raspberrypi/linux/blob/rpi-4.4.y/drivers/usb/gadget/function/f_hid.c
> 
> Any hint?

Try to setup everything as described in [1].

You may also try to use your own C program instead of echo to check if
hex value is correctly written.

Footnotes:
1 - http://marc.info/?l=linux-usb&m=141526874831676&w=2

Best regards,
-- 
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux