rpikvm/gadget_enable.sh

87 lines
3.4 KiB
Bash
Raw Normal View History

#!/bin/bash
gname=rpikvm
gserial=$(awk '/Serial/ { print $3 }' /proc/cpuinfo)
gmanufacturer="Petrkr.NET"
gproduct="rPi KVM"
2020-06-05 17:16:52 +02:00
#Mouse absolute descriptor
2020-06-05 13:20:12 +02:00
MOUSE0=""
MOUSE0="$MOUSE0\\x05\\x01\\x09\\x02" # Usage generic desktop, Usage mouse
MOUSE0="$MOUSE0\\xa1\\x01\\x09\\x01" # Collection App, Usage Pointer
MOUSE0="$MOUSE0\\xa1\\x00" # Collection Physical
MOUSE0="$MOUSE0\\x05\\x09" # Use Page buttons
MOUSE0="$MOUSE0\\x19\\x01\\x29\\x08\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08" # Usage min 1, max 8, logical min 0, max 1, report 8, size 1
MOUSE0="$MOUSE0\\x81\\x02" # Input data, variable, absolute
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
2020-06-05 17:57:19 +02:00
MOUSE0="$MOUSE0\\x09\\x30\\x35\\x00\\x46\\x80\\x07\\x15\\x00\\x26\\x80\\x07\\x75\\x10\\x95\\x01" # Usage X, Log min 0, log max 1920, size 16, report 1
2020-06-05 13:20:12 +02:00
MOUSE0="$MOUSE0\\x81\\x02" # Input data, variable, absolute
2020-06-05 17:16:52 +02:00
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
2020-06-05 17:57:19 +02:00
MOUSE0="$MOUSE0\\x09\\x31\\x35\\x00\\x46\\x38\\x04\\x15\\x00\\x26\\x38\\x04\\x75\\x10\\x95\\x01" # Usage Y, Log min 0, log max 1080, size 16, report 1
2020-06-05 17:16:52 +02:00
MOUSE0="$MOUSE0\\x81\\x02" # Input data, variable, absolute
MOUSE0="$MOUSE0\\x05\\x01" # Usage page generic desktop
2020-06-05 17:57:19 +02:00
MOUSE0="$MOUSE0\\x09\\x38\\x35\\x00\\x45\\x00\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x01" # Usage Wheel, log min -127, max 127, size 8, report 1
2020-06-05 17:16:52 +02:00
MOUSE0="$MOUSE0\\x81\\x06" # Input data, variable, relative
2020-06-05 13:20:12 +02:00
MOUSE0="$MOUSE0\\xc0" # End collection Physical
MOUSE0="$MOUSE0\\xc0" # End collection Application
cd /sys/kernel/config/usb_gadget/
mkdir -p $gname
cd $gname
echo "Creating USB Device"
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
echo "Creating strings"
mkdir -p strings/0x409
echo "$gserial" > strings/0x409/serialnumber
echo "$gmanufacturer" > strings/0x409/manufacturer
echo "$gproduct" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
2020-06-04 14:06:16 +02:00
echo "Config: KVM Composite" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
echo "Creating usb devices"
# Gadget HID Keyboard
echo " HID Keyboard"
mkdir -p functions/hid.kbd0
echo 1 > functions/hid.kbd0/protocol
echo 1 > functions/hid.kbd0/subclass
echo 8 > functions/hid.kbd0/report_length
2020-05-25 01:28:26 +02:00
echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\xff\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.kbd0/report_desc
2020-06-05 17:16:52 +02:00
echo " HID Mouse"
2020-05-24 20:02:59 +02:00
mkdir -p functions/hid.mouse0
echo 2 > functions/hid.mouse0/protocol
2020-05-25 01:28:26 +02:00
echo 1 > functions/hid.mouse0/subclass
2020-05-24 20:02:59 +02:00
echo 8 > functions/hid.mouse0/report_length
2020-06-05 13:20:12 +02:00
echo -ne $MOUSE0 > functions/hid.mouse0/report_desc
2020-05-24 20:02:59 +02:00
2020-05-24 14:20:06 +02:00
echo " Mass storage"
mkdir -p functions/mass_storage.disk1
echo " CD-ROM"
mkdir -p functions/mass_storage.cdrom1
echo 1 > functions/mass_storage.cdrom1/lun.0/cdrom
echo 1 > functions/mass_storage.cdrom1/lun.0/removable
2020-05-24 14:20:06 +02:00
echo "Activating gadgeds"
ln -s functions/hid.kbd0 configs/c.1/
2020-05-24 20:02:59 +02:00
ln -s functions/hid.mouse0 configs/c.1/
ln -s functions/mass_storage.disk1 configs/c.1/
ln -s functions/mass_storage.cdrom1 configs/c.1/
2020-05-24 14:20:06 +02:00
echo "Turn on gadget"
ls /sys/class/udc > UDC
2020-06-05 15:15:27 +02:00
echo "Change permissions"
chgrp input /dev/hidg0; chmod 660 /dev/hidg0
chgrp input /dev/hidg1; chmod 660 /dev/hidg1