rpikvm/gadget_enable.sh

63 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/bash
gname=rpikvm
gserial=$(awk '/Serial/ { print $3 }' /proc/cpuinfo)
gmanufacturer="Petrkr.NET"
gproduct="rPi KVM"
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-05-24 14:20:06 +02:00
echo "Config: HID KBD" > 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-05-24 20:02:59 +02:00
echo " HID Mouse"
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-05-25 01:28:26 +02:00
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x08\\x15\\x00\\x25\\x01\\x95\\x08\\x75\\x01\\x81\\x02\\x05\\x01\\x09\\x30\\x09\\x31\\x09\\x38\\x15\\x81\\x25\\x7f\\x75\\x08\\x95\\x03\\x81\\x06\\xc0\\xc0 > 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