tejado / android-usb-gadget

Convert your Android phone to any USB device you like! USB Gadget Tool allows you to create and activate USB device roles, like a mouse or a keyboard. 🛠🛡📱
GNU General Public License v3.0
894 stars 70 forks source link

Samsung S9 cant create keyboard gadget or add keyboard function #44

Open ElectricPulse opened 1 year ago

ElectricPulse commented 1 year ago

When trying to add the keyboard function to the default gadget I get the following:

`ROOT (stderr) - GadgetShellApi - Gadget Path is valid ROOT - Execute command: #!/bin/sh

GADGET="keyboard" GADGET_PATH="/config/usb_gadget/g1/"

cd $GADGET_PATH/configs/ CONFIG_PATH="$GADGET_PATH/configs/ls -1 | head -1/" STRINGS_PATH="$GADGET_PATH/strings/0x409/"

mkdir -p $GADGET_PATH/functions/hid.keyboard cd $GADGET_PATH/functions/hid.keyboard

HID protocol (according to USB spec: 1 for keyboard)

echo 1 > protocol

device subclass

echo 1 > subclass

number of bytes per record

echo 8 > report_length

writing report descriptor

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 > report_desc

ln -s ${GADGET_PATH}/functions/hid.keyboard $CONFIG_PATH/hid.keyboard

ROOT (stdout) - ROOT (stderr) - mkdir: '/config/usb_gadget/g1//functions/hid.keyboard': No such file or directory : [12]: cd: /config/usb_gadget/g1/functions/hid.keyboard: No such file or directory : [15]: can't create protocol: Permission denied : [17]: can't create subclass: Permission denied : [19]: can't create report_length: Permission denied : [22]: can't create report_desc: Permission denied ln: cannot create symbolic link from '/config/usb_gadget/g1//functions/hid.keyboard' to '/config/usb_gadget/g1//configs/b.1//hid.keyboard': No such file or directory ROOT - Execute command: for dir in /config/usb_gadget//; do echo GADGET_PATH=$dir; cd $dir/configs/; echo CONFIG_PATH="$dir/configs/ls -1 | head -1/"; cd $dir; if [ "$?" -ne "0" ]; then echo "Error - not able to change dir to $dir... exit"; exit 1; fi; echo UDC=$(cat UDC); find ./configs/ -type l -exec sh -c 'echo FUNCTIONSACTIVE=$(basename $(readlink "$@"))' {} \;; for f in ./functions//; do echo FUNCTIONS=$(basename $f); done; cd ./strings/0x409/; for vars in *; do echo ${vars}=$(cat $vars); done; echo "============="; done;

ROOT (stdout) - GADGET_PATH=/config/usb_gadget/g1/ CONFIG_PATH=/config/usb_gadget/g1//configs/b.1/ UDC=10c00000.dwc3 FUNCTIONS_ACTIVE=ncm.0 FUNCTIONS_ACTIVE=audio_source.0 FUNCTIONS_ACTIVE=accessory.0 FUNCTIONS_ACTIVE=midi.0 FUNCTIONS_ACTIVE=conn_gadget.0 FUNCTIONS_ACTIVE=dm.0 FUNCTIONS_ACTIVE=rndis.0 FUNCTIONS_ACTIVE=acm.0 FUNCTIONS_ACTIVE=ffs.adb FUNCTIONS_ACTIVE=ptp.0 FUNCTIONS_ACTIVE=mtp.0 FUNCTIONS=accessory.0 FUNCTIONS=acm.0 FUNCTIONS=audio_source.0 FUNCTIONS=conn_gadget.0 FUNCTIONS=dm.0 FUNCTIONS=ffs.adb FUNCTIONS=midi.0 FUNCTIONS=mtp.0 FUNCTIONS=ncm.0 FUNCTIONS=ptp.0 FUNCTIONS=rndis.0 manufacturer=samsung product=SM-G960F serialnumber=2a62ec9a06047ece =============`

I couldnt enable CONFIGFS_F_HID in my lineageos ROM (linker errors), so its disabled if that makes a difference.

tejado commented 1 year ago

Currently, CONFIG_USB_CONFIGFS_F_HID needs to be set to yes or m, otherwise it will not work. Additionally, others and I had issues with Samsung devices - the other issues in this repo.

Alternative to USB HID: Bluetooth HID - depending on your use-cae.