add audio support, trying to manage MSD device
This commit is contained in:
202
hid.sh
202
hid.sh
@@ -2,30 +2,31 @@
|
||||
|
||||
set -e
|
||||
GADGET_DIR=/sys/kernel/config/usb_gadget
|
||||
GADGET_ID=g0
|
||||
MSD_ID=g1
|
||||
|
||||
if [ ! -d "$GADGET_DIR" ]; then
|
||||
echo "$DIRECTORY does not exist."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "create" ]
|
||||
then
|
||||
if [ -d "$GADGET_DIR/g0" ]; then
|
||||
create() {
|
||||
if [ -s "$GADGET_DIR/$GADGET_ID/UDC" ]; then
|
||||
echo "HID devices already exists"
|
||||
|
||||
exit 0
|
||||
fi
|
||||
cd $GADGET_DIR && mkdir g0 && cd g0
|
||||
mkdir -p $GADGET_DIR/$GADGET_ID && \
|
||||
mkdir -p $GADGET_DIR/$MSD_ID && \
|
||||
cd $GADGET_DIR/$GADGET_ID
|
||||
|
||||
echo 0x3346 > idVendor
|
||||
echo 0x1009 > idProduct
|
||||
#echo 0x3346 > idVendor
|
||||
echo 0x1b6d > idVendor
|
||||
echo 0x0104 > idProduct
|
||||
#echo 0x1009 > idProduct
|
||||
echo 0x0300 > bcdUSB
|
||||
mkdir strings/0x409
|
||||
echo '0123456789ABCDEF' > strings/0x409/serialnumber
|
||||
cat /proc/device-tree/serial-number > strings/0x409/serialnumber
|
||||
echo 'rockchip' > strings/0x409/manufacturer
|
||||
echo 'rk3588' > strings/0x409/product
|
||||
|
||||
mkdir configs/c.1
|
||||
echo 0xE0 > configs/c.1/bmAttributes
|
||||
#echo 0xE0 > configs/c.1/bmAttributes
|
||||
echo 120 > configs/c.1/MaxPower
|
||||
mkdir configs/c.1/strings/0x409
|
||||
echo "rk3588" > configs/c.1/strings/0x409/configuration
|
||||
@@ -33,35 +34,168 @@ then
|
||||
# keyboard
|
||||
mkdir functions/hid.GS0
|
||||
echo 1 > functions/hid.GS0/subclass
|
||||
#echo 1 > functions/hid.GS0/wakeup_on_write
|
||||
echo 1 > functions/hid.GS0/protocol
|
||||
echo 6 > functions/hid.GS0/report_length
|
||||
#echo 6 > functions/hid.GS0/report_length
|
||||
#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\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.GS0/report_desc
|
||||
echo 8 > functions/hid.GS0/report_length
|
||||
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\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.GS0/report_desc
|
||||
ln -s functions/hid.GS0 configs/c.1
|
||||
|
||||
# mouse
|
||||
mkdir functions/hid.GS1
|
||||
# echo 1 > functions/hid.GS1/subclass
|
||||
#echo 1 > functions/hid.GS1/wakeup_on_write
|
||||
echo 2 > functions/hid.GS1/protocol
|
||||
echo -ne \\x34 > functions/hid.GS1/report_length
|
||||
echo -ne \\x5\\x1\\x9\\x2\\xa1\\x1\\x9\\x1\\xa1\\x0\\x5\\x9\\x19\\x1\\x29\\x3\\x15\\x0\\x25\\x1\\x95\\x3\\x75\\x1\\x81\\x2\\x95\\x1\\x75\\x5\\x81\\x3\\x5\\x1\\x9\\x30\\x9\\x31\\x9\\x38\\x15\\x81\\x25\\x7f\\x75\\x8\\x95\\x3\\x81\\x6\\xc0\\xc0 > functions/hid.GS1/report_desc
|
||||
ln -s functions/hid.GS1 configs/c.1
|
||||
#mkdir functions/hid.GS1
|
||||
## echo 1 > functions/hid.GS1/subclass
|
||||
#echo 2 > functions/hid.GS1/protocol
|
||||
#echo -ne \\x34 > functions/hid.GS1/report_length
|
||||
#echo -ne \\x5\\x1\\x9\\x2\\xa1\\x1\\x9\\x1\\xa1\\x0\\x5\\x9\\x19\\x1\\x29\\x3\\x15\\x0\\x25\\x1\\x95\\x3\\x75\\x1\\x81\\x2\\x95\\x1\\x75\\x5\\x81\\x3\\x5\\x1\\x9\\x30\\x9\\x31\\x9\\x38\\x15\\x81\\x25\\x7f\\x75\\x8\\x95\\x3\\x81\\x6\\xc0\\xc0 > functions/hid.GS1/report_desc
|
||||
#ln -s functions/hid.GS1 configs/c.1
|
||||
|
||||
# touchpad
|
||||
mkdir functions/hid.GS2
|
||||
# echo 1 > functions/hid.GS2/subclass
|
||||
#echo 1 > functions/hid.GS2/wakeup_on_write
|
||||
echo 2 > functions/hid.GS2/protocol
|
||||
echo 6 > functions/hid.GS2/report_length
|
||||
echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x03\\x15\\x00\\x25\\x01\\x95\\x03\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x05\\x81\\x01\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x00\\x26\\xff\\x7f\\x35\\x00\\x46\\xff\\x7f\\x75\\x10\\x95\\x02\\x81\\x02\\x05\\x01\\x09\\x38\\x15\\x81\\x25\\x7f\\x35\\x00\\x45\\x00\\x75\\x08\\x95\\x01\\x81\\x06\\xc0\\xc0 > functions/hid.GS2/report_desc
|
||||
ln -s functions/hid.GS2 configs/c.1
|
||||
#mkdir functions/hid.GS2
|
||||
## echo 1 > functions/hid.GS2/subclass
|
||||
#echo 2 > functions/hid.GS2/protocol
|
||||
#echo 6 > functions/hid.GS2/report_length
|
||||
#echo -ne \\x05\\x01\\x09\\x02\\xa1\\x01\\x09\\x01\\xa1\\x00\\x05\\x09\\x19\\x01\\x29\\x03\\x15\\x00\\x25\\x01\\x95\\x03\\x75\\x01\\x81\\x02\\x95\\x01\\x75\\x05\\x81\\x01\\x05\\x01\\x09\\x30\\x09\\x31\\x15\\x00\\x26\\xff\\x7f\\x35\\x00\\x46\\xff\\x7f\\x75\\x10\\x95\\x02\\x81\\x02\\x05\\x01\\x09\\x38\\x15\\x81\\x25\\x7f\\x35\\x00\\x45\\x00\\x75\\x08\\x95\\x01\\x81\\x06\\xc0\\xc0 > functions/hid.GS2/report_desc
|
||||
#ln -s functions/hid.GS2 configs/c.1
|
||||
|
||||
ls /sys/class/udc/ | cat > UDC
|
||||
#cd $GADGET_DIR/$MSD_ID
|
||||
|
||||
#echo 0x3346 > idVendor
|
||||
#echo 0x1009 > idProduct
|
||||
#mkdir strings/0x409
|
||||
#echo '0123456789ABCDEF' > strings/0x409/serialnumber
|
||||
#echo 'rockchip' > strings/0x409/manufacturer
|
||||
#echo 'rk3588_msd' > strings/0x409/product
|
||||
|
||||
#mkdir configs/c.1
|
||||
#echo 0xE0 > configs/c.1/bmAttributes
|
||||
#echo 250 > configs/c.1/MaxPower
|
||||
#mkdir configs/c.1/strings/0x409
|
||||
#echo "rk3588_msd" > configs/c.1/strings/0x409/configuration
|
||||
|
||||
# attach storage
|
||||
#mkdir functions/mass_storage.disk0
|
||||
#ln -s functions/mass_storage.disk0 configs/c.1/
|
||||
#echo 1 > functions/mass_storage.disk0/lun.0/removable
|
||||
#echo 1 > functions/mass_storage.disk0/lun.0/ro
|
||||
}
|
||||
|
||||
delete() {
|
||||
if [ ! -d "$GADGET_DIR/$GADGET_ID" ]; then
|
||||
echo "No HID devices to delete."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if grep -q '[^[:space:]]' "$GADGET_DIR/$GADGET_ID/UDC"; then
|
||||
echo "HID devices are still attached. Please detach them before deleting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$GADGET_DIR" || exit 1
|
||||
|
||||
rm -f $GADGET_ID/configs/c.1/hid.GS0
|
||||
#rm -f $GADGET_ID/configs/c.1/hid.GS1
|
||||
#rm -f $GADGET_ID/configs/c.1/hid.GS2
|
||||
|
||||
rmdir $GADGET_ID/functions/hid.GS0
|
||||
#rmdir $GADGET_ID/functions/hid.GS1
|
||||
#rmdir $GADGET_ID/functions/hid.GS2
|
||||
|
||||
rmdir $GADGET_ID/configs/c.1/strings/0x409
|
||||
rmdir $GADGET_ID/configs/c.1
|
||||
rmdir $GADGET_ID/strings/0x409
|
||||
rmdir "$GADGET_ID"
|
||||
|
||||
if grep -q '[^[:space:]]' "$GADGET_DIR/$MSD_ID/UDC"; then
|
||||
echo "HID devices are still attached. Please detach them before deleting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#rm -f $MSD_ID/configs/c.1/mass_storage.disk0
|
||||
#rmdir $MSD_ID/functions/mass_storage.disk0
|
||||
#rmdir $MSD_ID/configs/c.1/strings/0x409
|
||||
#rmdir $MSD_ID/configs/c.1
|
||||
#rmdir $MSD_ID/strings/0x409
|
||||
#rmdir "$MSD_ID"
|
||||
|
||||
echo "HID devices have been deleted."
|
||||
}
|
||||
|
||||
attach() {
|
||||
if grep -q '[^[:space:]]' "$GADGET_DIR/$GADGET_ID/UDC"; then
|
||||
echo "Error: Device is already attached."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ls /sys/class/udc/ | cat > "$GADGET_DIR/$GADGET_ID/UDC"
|
||||
#ls /sys/class/udc/ | cat > "$GADGET_DIR/$MSD_ID/UDC"
|
||||
echo "Device has been attached."
|
||||
}
|
||||
|
||||
detach() {
|
||||
echo '' > "$GADGET_DIR/$GADGET_ID/UDC"
|
||||
#echo '' > "$GADGET_DIR/$MSD_ID/UDC"
|
||||
echo "Device has been detached."
|
||||
}
|
||||
|
||||
mount_iso() {
|
||||
iso_file="$1"
|
||||
|
||||
if [[ ! -f "$iso_file" ]]; then
|
||||
echo "Error: ISO file '$iso_file' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if grep -q '[^[:space:]]' "$GADGET_DIR/$MSD_ID/UDC"; then
|
||||
echo "Error: Device is still attached. Please detach it before mounting the ISO."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$iso_file" > "$GADGET_DIR/$MSD_ID/functions/mass_storage.disk0/lun.0/file"
|
||||
echo "ISO file: $iso_file inserted."
|
||||
}
|
||||
|
||||
mounted_iso() {
|
||||
cat "$GADGET_DIR/$MSD_ID/functions/mass_storage.disk0/lun.0/file"
|
||||
}
|
||||
|
||||
unmount_iso() {
|
||||
if grep -q '[^[:space:]]' "$GADGET_DIR/$MSD_ID/UDC"; then
|
||||
echo "Error: Device is still attached. Please detach it before unmounting the ISO."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo > "$GADGET_DIR/$MSD_ID/functions/mass_storage.disk0/lun.0/file"
|
||||
}
|
||||
|
||||
if [ ! -d "$GADGET_DIR" ]; then
|
||||
echo "$DIRECTORY does not exist. Load modules or recompile the kernel to support usb_gadget"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "delete" ]
|
||||
then
|
||||
echo '' > $GADGET_DIR/g0/UDC
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
create)
|
||||
create
|
||||
;;
|
||||
delete)
|
||||
delete
|
||||
;;
|
||||
attach)
|
||||
attach
|
||||
;;
|
||||
detach)
|
||||
detach
|
||||
;;
|
||||
mount_iso)
|
||||
mount_iso "$2"
|
||||
;;
|
||||
unmount_iso)
|
||||
unmount_iso
|
||||
;;
|
||||
mounted_iso)
|
||||
mounted_iso
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {create|delete|attach|detach|mount_iso|unmount_iso|mounted_iso}"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user