2020-05-24 14:02:23 +02:00
#!/bin/bash
gname = rpikvm
gserial = $( awk '/Serial/ { print $3 }' /proc/cpuinfo)
gmanufacturer = "Petrkr.NET"
gproduct = "rPi KVM"
2020-06-05 18:12:44 +02:00
KEYBOARD = ""
KEYBOARD = " $KEYBOARD \\x05\\x01\\x09\\x06 " # Usage generic desktop, Usage keyboard
KEYBOARD = " $KEYBOARD \\xa1\\x01\\x05\\x07 " # Collection App, Use page Keyboard
KEYBOARD = " $KEYBOARD \\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08 " # Usage min (LeftControl) max (Right GUI), log min 0 log min 1, report size 1 count 8
KEYBOARD = " $KEYBOARD \\x81\\x02 " # Input data, variable, absolute
KEYBOARD = " $KEYBOARD \\x75\\x08\\x95\\x01 " # Report size 8, count 1
KEYBOARD = " $KEYBOARD \\x81\\x03 " # Input Const, variable, absolute
KEYBOARD = " $KEYBOARD \\x75\\x01\\x95\\x05 " # Report size 1 count 5
KEYBOARD = " $KEYBOARD \\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 "
KEYBOARD = " $KEYBOARD \\x81\\x00 " # Input data array absolute
KEYBOARD = " $KEYBOARD \\xc0 " # End Collection Application
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
2020-05-24 14:02:23 +02:00
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
2020-05-24 14:02:23 +02:00
echo 250 > configs/c.1/MaxPower
echo "Creating usb devices"
# Gadget HID Keyboard
echo " HID Keyboard"
2020-05-24 19:36:17 +02:00
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-06-05 18:12:44 +02:00
echo -ne $KEYBOARD > functions/hid.kbd0/report_desc
2020-05-24 19:36:17 +02:00
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"
2020-05-24 19:36:17 +02:00
mkdir -p functions/mass_storage.disk1
2020-06-07 13:37:30 +02:00
echo "RPi KVM DISK" > functions/mass_storage.disk1/lun.0/inquiry_string
2020-05-24 19:36:17 +02:00
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-06-07 13:37:30 +02:00
echo "RPi KVM CDROM" > functions/mass_storage.cdrom1/lun.0/inquiry_string
2020-05-24 14:20:06 +02:00
echo "Activating gadgeds"
2020-05-24 19:36:17 +02:00
ln -s functions/hid.kbd0 configs/c.1/
2020-05-24 20:02:59 +02:00
ln -s functions/hid.mouse0 configs/c.1/
2020-05-24 19:36:17 +02:00
ln -s functions/mass_storage.disk1 configs/c.1/
ln -s functions/mass_storage.cdrom1 configs/c.1/
2020-05-24 14:02:23 +02:00
2020-05-24 14:20:06 +02:00
echo "Turn on gadget"
2020-05-24 14:02:23 +02:00
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