I write data to host using a usb hid.
The following is the script for hid.
#!/bin/sh
usb_id=1
case "$1" in
start)
#1 mount configfs
mount -t configfs none /sys/kernel/config
#2 create hid mouse gadget
cd /sys/kernel/config/usb_gadget
mkdir g1
cd g1
#echo "0x0103" > idVendor
#echo "0xA213" > idProduct
echo "0x0483" > idVendor
echo "0xA058" > idProduct
mkdir strings/0x409
echo "0123456789ABCDEF" > strings/0x409/serialnumber
echo "TEST ENG Co.,Ltd." > strings/0x409/manufacturer
echo "HID_CAT" > strings/0x409/product
sleep 1
#3 create cfg
mkdir configs/c.1
mkdir configs/c.1/strings/0x409
echo "HID" > configs/c.1/strings/0x409/configuration
echo 0xc0 > configs/c.1/bmAttributes
echo 500 > configs/c.1/MaxPower
sleep 1
#4 create function
#hid mouse
mkdir functions/hid.usb0
echo 0 > functions/hid.usb0/subclass
echo 0 > functions/hid.usb0/protocol
echo 64 > functions/hid.usb0/report_length
# Write report descriptor
#hexdump /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/report_desc
echo -ne "\x06\x06\xFF\x09\x01\xA1\x01\x85\x4F\x09\x4F\x15\x00\x25\xFF\x75\xF8\x95\x02\xB1\x82\x85\x4F\x09\x4F\x91\x82\x85\x49\x09\x49\x15\x00\x25\xFF\x75\xF8\x95\x02\x81\x82\x85\x49\x09\x49\xB1\x82\xC0" > functions/hid.usb0/report_desc
sleep 1
#5. hid mouse
ln -s functions/hid.usb0 configs/c.1
sleep 1
#8. start gadget
my_udc=$(echo `ls /sys/class/udc/` | cut -d ' ' -f ${usb_id})
echo ${my_udc}
if [[ ${my_udc} != "" ]]; then
echo "${my_udc}" > /sys/kernel/config/usb_gadget/g1/UDC
fi
sleep 1
;;
stop)
echo "" > /sys/kernel/config/usb_gadget/g1/UDC
rm /sys/kernel/config/usb_gadget/g1/configs/c.1/hid.usb0/
rmdir /sys/kernel/config/usb_gadget/g1/configs/c.1/strings/0x409/
rmdir /sys/kernel/config/usb_gadget/g1/configs/c.1/
rmdir /sys/kernel/config/usb_gadget/g1/functions/hid.usb0/
rmdir /sys/kernel/config/usb_gadget/g1/strings/0x409/
rmdir /sys/kernel/config/usb_gadget/g1/
umount /sys/kernel/config
;;
restart|reload)
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
When I try to write data to host like the following command,
echo -ne "\x97\x77" > /dev/hidg0
the below error message displayed.
[ 555.161464] configfs-gadget gadget: usb_ep_queue error on int endpoint -11 sh: write error: Resource temporarily unavailable
But the read operation is passed.
What should I check to solve this problem?
Thanks.