New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempting to connect QEMU and a USB device with the command 'termux-usb -e usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' and getting "termux-usb: too many arguments". #19635
Comments
|
If I recall correctly you can simply quote the entire command that termux-usb should run, and add path as last argument to termux-usb:
It looks like your usbredirect program tries to get the fd from argv[1] though, and argv[1] will be Might be easier to pass fd as an environmental var with -E arg of termux-usb, and then parse |
See "Update-3". |
This is not correct input for usbredirect. You should use |
Termux, sockets, QEMU, and the Linux operating system
Sessions: Termux, QEMU, QEMU Linux ServerTermux session: USB flash drive
QEMU Session (Termux):
In The QEMU Monitor (Press CTRL-a c):
Leave The QEMU Monitor (Press CTRL-a c).
Termux Session:
QEMU Linux Server:
Termux Session:
QEMU Linux Server:
Termux Session:
QEMU Linux Server, "^C" (CTRL-C) Stops "socat":
Termux Session:
QEMU Linux Server, "^C" (CTRL-C) Stops "socat":
|
There is a lot of information here to parse. The first sentence is just
Could you please add what is the problem and what is your expectation? That would give perspective for what you are testing. |
@victortoso and @Grimler91 for this comment I will hold back praises and I will hold back kudos and I will hold back Multiple Standing Ovations for Termux, termux-usb, usbredirect, and QEMU (@qemu)! The modified usbredirect.c source code at The Goal: The QEMU Linux Server as a USB-Drive I/O Subsystem providing fast as possible file transfers and an easy way to access the files. On-My-Mind-1: How should the usbredirect.c source code be modified to handle the interface with "termux-usb -e 'usbredirect --device /dev/bus/usb/001/031 --as 127.0.0.1.23456'"? Use "--device termux"? Use "--device ignore"? Disable the "--device" option? Do Termux users using rooted devices need the "--device"? The answers have to come from @Grimler91 and other Termux Team members. On-My-Mind-2: Better understanding of "-device virtconsole" and "-device virtserialport". On-My-Mind-3: The experimental "socat" setup at On-My-Mind-4: Is LUKS (Linux Unified Key Setup) without using "cryptsetup" on the QEMU Linux Server console possible? https://github.com/usbarmory/interlock (@usbarmory)? On-My-Mind-5: There are Android file manager apps that can connect to a Samba server. On the QEMU Linux Server is it possible to setup a Samba server that somehow connects with a Unix domain socket on the QEMU Linux Server? In Termux is there a way to redirect an Internet domain socket to a Unix domain socket, and will it work with Samba? On-My-Mind-6: WebDAV. |
On-My-Mind-5: The Samba (SMB) server experiment with (A) the Linux "socat" command, (B) "termux.socket" (Unix domain socket) on Termux, (C) a Samba server on port 445 (Internet domain socket) on the QEMU Linux Server that's running Alpine Linux, (D) a USB flash drive formatted with the ext4 filesystem and plugged in the USB-C 2.0 port on an Android 11 smartphone (4 cores, 3 gigabytes of RAM) that is not rooted, and (E) the "usbredirect" command on Termux connecting the USB Flash drive to QEMU
Termux Session, USB flash drive in the smartphone's USB port:
QEMU Monitor:
Termux Session:
QEMU Linux Server Session:
Termux Session:
QEMU Linux Server:
|
What's the correct way to use termux-usb to solve this?
Update-1: The correct syntax is 'usbredirect --device "/dev/bus/usb/001/031" --to 127.0.0.1:23456'. Now 'termux-usb -e usbredirect --device "/dev/bus/usb/001/031" --to 127.0.0.1:23456' returns "termux-usb: illegal option --".
Update-2: Workaround-version-2 passes device bus-string by hard-coding the device bus-string in a separate shell script: echo 'FULL-PATH/usbredirect --device /dev/bus/usb/001/031 --to 127.0.0.1:23456' > u.sh; chmod a+rx u.sh ; termux-usb -e FULL-PATH/u.sh "/dev/bus/usb/001/031" and printf argv[2] in usbredirect displays the hard-coded bus-string.
Update-3: Replaced usbredirect.c source code with the latest version. Used the suggestion from @Grimler91 at
https://github.com/termux/termux-packages/issues/19635#issuecomment-2030116274
(#19635 (comment)) and the result is posted in the "Termux session: testing usbredirect" section. Major progress and very good news!Update-4: Replaced usbredirect.c with the latest version.
Update-5: It works! 'termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/003 --as 127.0.0.1:23456" /dev/bus/usb/001/003'. Thank you Termux Team!
Update-6 (using the QEMU Linux server setup in "Excerpts from the Termux session using QEMU and a USB device"): 'mkfs.ext4 /dev/sda' -- works. Create three partitions (two type 83 partitions and one type 7 parition) with 'fdisk /dev/sda' -- works. 'cryptsetup luksFormat /dev/sda1 ; cryptsetup luksOpen /dev/sda1 v1 ; mkfs.ext4 /dev/mapper/v1 ; mount /dev/mapper/v1 /root/1 ; ls -l /root/1 ; chown 1100:1100 /root/1/. ; dd if=/dev/zero of=1gb bs=1M count=1024 status=progress ; sha256sum 1gb > checksum ; ls -l /root/1 ; umount /root/1 ; cryptsetup luksClose v1' -- works. Make sure the USB flash drive's light is not blinking . . . sure there is no I/O activity? . . . 'eject /dev/sda' -- works. Unplug the USB flash drive from the phone -- QEMU and usbredirect are still running. Plug the USB drive in a Linux server (not a virtual server) and open the LUKS container -- works. The QEMU Linux server has been up for over seven hours and it needs 'apk add hdparm ntfs-3g exfatprogs' (the packages are not on the ISO images). The packages will be brought over on a USB flash drive and the USB drive has to be connected to QEMU -- usbredirect must be restarted, QEMU will not be restarted.
Update-7 Continuing From Update-6: The files have been copied to the USB flash drive. Pressing control-c (ctrl-c) will stop usbredirect.
Plug in the USB flash drive and give termux access to it:
In the QEMU monitor before starting usbredirect in termux:
Start usbredirect in termux:
Go to the QEMU monitor after starting usbredirect in termux:
The connection remains established even after 'eject /dev/sda' and removing the USB flash drive:
In the QEMU Linux server:
Update-8: Booting from the USB flash drive works:
Update-9: Give the QEMU Linux server read-write access to the "/storage/emulated/0/Download/usb1" and "/data/data/com.termux/files" directories for data transfer to and from the USB flash drive:
Termux session:
In the termux session to give termux access to the USB flash drive and start usbredirect:
QEMU Linux server session:
Update-10: SSH tunnels (port forwarding), multiple USB flash drives, and The-Remote-Linux-Server:
Connect to The-Remote-Linux-Server in the termux session:
QEMU session, start the QEMU Linux server:
In the QEMU monitor (press ctrl-a c) as the server boots:
Press 'ctrl-a c' to leave the QEMU monitor (the server is still booting).
In the termux session plug in the USB flash drive, start the termux SSH server ("sshd"), connect to the termux SSH server, start usbredirect:
QEMU session, attach the USB flash drive using the QEMU monitor:
QEMU Linux server session:
Update-11: "Termux, sockets, QEMU, and the Linux operating system" at https://github.com/termux/termux-packages/issues/19635#issuecomment-205251940
Connecting a USB device to QEMU using termux, termux-usb, usbredirect
https://web.archive.org/web/20111023113251/cgit.freedesktop.org/spice/qemu/plain/docs/ich9-ehci-uhci.cfg or https://web.archive.org/web/20111023113251if_/cgit.freedesktop.org/spice/qemu/plain/docs/ich9-ehci-uhci.cfg
https://gitlab.freedesktop.org/spice/usbredir/-/issues/1
Plug in the USB device, "termux-usb -l", "termux -r /dev/bus/usb/001/003"
Use full pathnames. Use two termux sessions, one for usbredirect and one for QEMU.
Start usbredirect and then QEMU: termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/003 --as 127.0.0.1:23456" /dev/bus/usb/001/003
qemu-system-x86_64 -nic none -m 2000M -machine q35 -smp 4 -device virtio-rng-pci -nographic -readconfig $HOME/ich9-ehci-uhci.cfg -chardev socket,host=127.0.0.1,port=23456,id=usbredirchardev1 -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,debug=3
See the "Excerpts from the Termux session using QEMU and a USB device" section below; https://old.reddit.com/r/termux/comments/190np1k/a_smartphone_with_no_root_access_alpine_linux/ (via https://old.reddit.com/r/termux/comments/19573gg/encryption_decryption_android_11_operating_system/) was used for setting up the Linux server in QEMU.
Using the QEMU monitor: https://gist.github.com/NoteAfterNote/cabd411777f2ad5ae57d3d98c576471c (NoteAfterNote-3, "Part 3 Of 5: QEMU, A Guest Operating System, LUKS Encryption, lighttpd, WebDAV", April 12, 2023). QEMU monitor commands: 'help', 'info', 'info usb', 'info chardev', 'device_del usbredirchardev1', 'chardev-add socket,host=127.0.0.1,port=23456,id=c1', 'device_add usb-redir,chardev=c1,id=u1,debug=3'
https://www.qemu.org
https://www.spice-space.org/usbredir.html , https://gitlab.freedesktop.org/spice/usbredir/-/blob/main/docs/usb-redirection-protocol.md , and https://gitlab.com/qemu-project/qemu/-/blob/master/hw/usb/redirect.c (https://github.com/qemu/qemu/tree/master/hw/usb)
qemu-system-x86_64 -device usb-redir,help
usb-redir options:
attached=
bootindex=
chardev= - ID of a chardev to use as a backend
debug= - (default: 2)
filter=
msos-desc= - on/off (default: true)
pcap=
port=
serial=
streams= - (default: true)
suppress-remote-wake= - (default: true)
qemu-system-x86_64 -chardev socket,help
chardev options:
abstract=<bool (on/off)>
append=<bool (on/off)>
backend=
chardev=
clipboard=<bool (on/off)>
cols=
debug=
delay=<bool (on/off)>
fd=
height=
host=
input-path=
ipv4=<bool (on/off)>
ipv6=<bool (on/off)>
localaddr=
localport=
logappend=<bool (on/off)>
logfile=
mouse=<bool (on/off)>
mux=<bool (on/off)>
name=
nodelay=<bool (on/off)>
path=
port=
reconnect=
rows=
server=<bool (on/off)>
signal=<bool (on/off)>
size=
telnet=<bool (on/off)>
tight=<bool (on/off)>
tls-authz=
tls-creds=
tn3270=<bool (on/off)>
to=
wait=<bool (on/off)>
websocket=<bool (on/off)>
width=
Extra information:
No root.
The latest version of the usbredirect.c source code is below. Building and compiling usbredirect.c using meson on termux works. The SPICE protocol is not used.
usbredirect.c is being modified using usbtest.c from https://wiki.termux.com/wiki/Termux-usb. Modification indicators: "#ifdef THIS_IS_A_COMMENT" and "#ifdef FOR_TERMUX".
Termux session:
~/.../usbredir-main/build $
~/.../usbredir-main/build $ ../../meson-1.4.0/meson.py compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /data/data/c
om.termux/files/usr/bin/ninja
[1/2] Compiling C object ...edirect.p/usbredirect.c.o
../tools/usbredirect.c:598:1: warning: unused function
'open_usb_device' [-Wunused-function]
598 | open_usb_device(redirect *self)
| ^~~~~~~~~~~~~~~
1 warning generated.
[2/2] Linking target tools/usbredirect
~/.../usbredir-main/build $
~/.../usbredir-main/build $ termux-usb -e ./build/tools/usbredirect device "/dev/bus/usb/001/031" --to 127.0.0.1:23456
termux-usb: too many arguments
~/.../usbredir-main/build $
termux-info:
TERMUX_API_APP__VERSION_NAME=0.50.1
TERMUX_APP_PACKAGE_MANAGER=apt
TERMUX_APP__AM_SOCKET_SERVER_ENABLED=true
TERMUX_APP__APK_PATH=/data/app/~~zMILa9TgJazQczw9C_x_Cg==/com.termux-t3s8rxYdbG9lbQ81IkrQaw==/base.apk
TERMUX_APP__APK_RELEASE=GITHUB
TERMUX_APP__FILES_DIR=/data/user/0/com.termux/files
TERMUX_APP__IS_DEBUGGABLE_BUILD=true
TERMUX_APP__IS_INSTALLED_ON_EXTERNAL_STORAGE=false
TERMUX_APP__PACKAGE_MANAGER=apt
TERMUX_APP__PACKAGE_NAME=com.termux
TERMUX_APP__PACKAGE_VARIANT=apt-android-7
TERMUX_APP__SE_FILE_CONTEXT=u:object_r:app_data_file:s0:c189,c256,c512,c768
TERMUX_APP__SE_INFO=default:targetSdkVersion=28:complete
TERMUX_APP__SE_PROCESS_CONTEXT=u:r:untrusted_app_27:s0:c189,c256,c512,c768
TERMUX_APP__TARGET_SDK=28
TERMUX_APP__VERSION_CODE=118
TERMUX_APP__VERSION_NAME=0.118.0+9b06e61
TERMUX_MAIN_PACKAGE_FORMAT=debian
TERMUX_VERSION=0.118.0+9b06e61
TERMUX__USER_ID=0
Packages CPU architecture:
arm
Updatable packages:
All packages up to date
termux-tools version:
1.40.5
Android version:
11
LD Variables:
LD_LIBRARY_PATH=
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
Installed termux plugins:
com.termux.api versionCode:51
com.termux.gui versionCode:6
Termux session: testing usbredirect
~/.../usbredir-main/build $ ../../meson-1.4.0/meson.py compile
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /data/data/com.termux/files/usr/bin/ninja
[1/2] Compiling C object ...edirect.p/usbredirect.c.o
../tools/usbredirect.c:596:1: warning: unused function
'open_usb_device' [-Wunused-function]
596 | open_usb_device(redirect *self)
| ^~~~~~~~~~~~~~~
1 warning generated.
[2/2] Linking target tools/usbredirect
~/.../usbredir-main/build $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/003 --to 127.0.0.1:23456" /dev/bus/usb/001/003
argv[0] = /data/data/com.termux/files/home/usb-test/us
bredir-main/build/tools/usbredirect
argv[1] = --device
argv[2] = /dev/bus/usb/001/003
argv[3] = --to
argv[4] = 127.0.0.1:23456
argv[5] = 7
AFTER parse_opts
BEFORE sscanf argv[0] = /data/data/com.termux/files/ho
me/usb-test/usbredir-main/build/tools/usbredirect
BEFORE sscanf argv[1] = 7
BEFORE sscanf argv[2] = (null)
BEFORE sscanf argv[3] = (null)
BEFORE sscanf argv[4] = (null)
BEFORE sscanf argv[5] = (null)
Vendor ID: 0718
Product ID: 7722
Manufacturer: Memorex
Product: USB Flash Drive
Serial No: [REMOVED-FOR-PRIVACY]
(usbredirect:8504): usbredirect-WARNING **: 13:21:02.8
78: Failed to connect to the server: Could not connect
to 127.0.0.1: Connection refused
~/.../usbredir-main/build $
Modified source code: usbredirect.c
Excerpts from the Termux session using QEMU and a USB device:
The text was updated successfully, but these errors were encountered: