Closed NoteAfterNote closed 5 months ago
-e
option accepts single argument. If command line contains spaces, it should be enclosed in quotes to prevent word splitting.
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:
termux-usb -e "usbredirect --device /dev/bus/usb/001/031 --to 127.0.0.1:23456" /dev/bus/usb/001/031
It looks like your usbredirect program tries to get the fd from argv[1] though, and argv[1] will be --device
with above command, while fd is passed in argv[5] (last arg).
Might be easier to pass fd as an environmental var with -E arg of termux-usb, and then parse TERMUX_USB_FD
in usbredirect.
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:
termux-usb -e "usbredirect --device /dev/bus/usb/001/031 --to 127.0.0.1:23456" /dev/bus/usb/001/031
It looks like your usbredirect program tries to get the fd from argv[1] though, and argv[1] will be
--device
with above command, while fd is passed in argv[5] (last arg).Might be easier to pass fd as an environmental var with -E arg of termux-usb, and then parse
TERMUX_USB_FD
in usbredirect.
See "Update-3".
usbredirect --device /dev/bus/usb/001/031
This is not correct input for usbredirect. You should use vendor:product
or bus-device_number
, not a path.
"termux.socket" is a Unix domain socket.
QEMU: The network is enabled, port 9999 is fowarded to port 80.
QEMU Linux Server: The ethernet (eth0) interface is configured. The nginx HTTP server listens on port 80 ("listen 80 default_server;").
Termux: "wget http://127.0.0.1:9999" uses the QEMU Linux Server network.
Experiment: Using "socat" for "termux.socket" communication on the QEMU Linux Server -- "socat -t 1000 /dev/vport5p1,ignoreeof TCP4-CONNECT:127.0.0.1:80" and "socat -t 1000 /dev/vport5p1,ignoreeof UNIX-CONNECT:/tmp/termux.socket".
Experiment: "termux.socket" is enabled on QEMU using "-device virtio-serial". "-chardev socket,path=$HOME/qemu/termux.socket,id=termux-socket,name=talk-to-termux,server=on,wait=off", and "-device virtserialport,id=port1,chardev=termux-socket" ("qemu-system-x86_64 -device virtserialport,help", "qemu-system-x86_64 -chardev socket,help", "qemu-system-x86_64 --help").
Experiment: On the QEMU Linux Server the nginx HTTP server listens on "termux.socket" ("listen unix:/tmp/termux.socket").
Experiment: On Termux nginx HTTP server is configured to accept a request on port 8888 ("listen 8888;") and forward it using "termux.socket" ("proxy_pass http://unix:/data/data/com.termux/files/home/qemu/termux.socket;") to the QEMU Linux server, "socat" is used on the QEMU Linux server.
Experiment: On Termux "wget http://127.0.0.1:8888" uses "termux.socket" and on the QEMU Linux Server the nginx HTTP server uses port 80, "socat" is used on the QEMU Linux server.
Experiment: On Termux "wget http://127.0.0.1:8888" uses "termux.socket" and on the QEMU Linux server the nginx HTTP server uses "termux.socket", "socat" is used on the QEMU Linux server.
Excerpt from "wget http://127.0.0.1:9999/test/100mb" ("listen 80 default_server;"):
Length: 104857600 (100M) [application/octet-stream] 100%[=========================>] 100.00M 340KB/s in 3m 44s 2024-04-12 13:07:45 (456 KB/s) - ‘100mb’ saved [104857600/104857600]
Excerpt from "wget http://127.0.0.1:8888/test/100mb" ("termux.socket" on Termux, "listen 80 default_server;" on QEMU Linux server):
Length: 104857600 (100M) [application/octet-stream] Saving to: ‘100mb.1’ 100%[=========================>] 100.00M 3.12MB/s in 32s
Excerpt from "wget http://127.0.0.1:8888/test/100mb" ("termux.socket" on Termux and "termux.socket" on the QEMU Linux server):
Length: 104857600 (100M) [application/octet-stream] Saving to: ‘100mb.2’ 100%[=========================>] 100.00M 4.41MB/s in 22s 2024-04-12 13:24:51 (4.45 MB/s) - ‘100mb.2’ saved [104857600/104857600]
https://fedoraproject.org/wiki/Features/VirtioSerial , http://www.linux-kvm.org/page/VMchannel_Requirements , http://www.linux-kvm.org/page/Virtio-serial_API , http://www.dest-unreach.org/socat/doc/socat.html , https://nginx.org , https://nginx.org/en/docs/http/ngx_http_proxy_module.html , https://www.nginx.com/blog/avoiding-top-10-nginx-configuration-mistakes/
https://stackoverflow.com/questions/24453388/nginx-reverse-proxy-causing-504-gateway-timeout , https://stackoverflow.com/questions/18740635/nginx-upstream-timed-out-110-connection-timed-out-while-reading-response-hea , "NGINX as a WebSocket Proxy" at https://www.nginx.com/blog/websocket-nginx/
https://www.cs.rpi.edu/~moorthy/Courses/os98/Pgms/socket.html (via https://www.cs.rpi.edu/~moorthy/Courses/os98/), https://www.cs.rpi.edu/academics/courses/spring06/netprog/c02.html (via https://www.cs.rpi.edu/academics/courses/spring06/netprog/)
Termux session: USB flash drive
~/.../build/tools $
~/.../build/tools $ termux-usb -l
[
"/dev/bus/usb/001/009"
~/.../build/tools $
~/.../build/tools $ termux-usb -r /dev/bus/usb/001/009
Access granted.
~/.../build/tools $
~/.../build/tools $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/009 --as 127.0.0.1:40000" /dev/bus/usb/001/009
QEMU Session (Termux):
~/qemu $
~/qemu $ export ISO1=$HOME/qemu/alpine-virt-3.19.0-x86_64.iso ; export ISO2=$HOME/qemu/alpine-extended-3.19.0-x86_64.iso ; qemu-system-x86_64 -m 1024M -machine q35 -smp 4 -device virtio-rng-pci -nographic -readconfig $HOME/ich9-ehci-uhci.cfg -drive if=none,id=iso1,readonly=on,format=raw,file=$ISO1 -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1 -drive if=none,id=iso2,readonly=on,format=raw,file=$ISO2 -device virtio-blk-pci,id=virt2,drive=iso2 -virtfs local,security_model=none,id=termux,mount_tag=termux,path=/data/data/com.termux/files -virtfs local,security_model=none,id=host,mount_tag=host,path=/storage/emulated/0/Download/usb1 -device virtio-serial -chardev socket,path=$HOME/qemu/termux.socket,id=termux-socket,name=talk-to-termux,server=on,wait=off -device virtserialport,id=port1,chardev=termux-socket -device virtio-net-pci,netdev=net0,mac=52:54:12:34:56:78 -netdev user,id=net0,ipv6=off,hostfwd=tcp::9999-:80
In The QEMU Monitor (Press CTRL-a c):
QEMU 8.0.2 monitor - type 'help' for more information
(qemu)
(qemu) chardev-add socket,id=c1,host=127.0.0.1,port=40000
(qemu) device_add usb-redir,id=u1,chardev=c1,debug=3
(qemu) qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bitss
qemu-system-x86_64: usb-redir: attaching high speed device 0718:7722 version 1.0 class 0
(qemu)
(qemu) info chardev
parallel0: filename=null
serial0: filename=mux
c1: filename=tcp:127.0.0.1:33302 <-> 127.0.0.1:40000
serial0-base: filename=stdio
termux-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/termux.n
(qemu)
(qemu) info virtio
/machine/peripheral-anon/device[4]/virtio-backend [virtio-net]
/machine/peripheral-anon/device[3]/virtio-backend [virtio-serial]
/machine/peripheral-anon/device[2]/virtio-backend [virtio-9p]
/machine/peripheral-anon/device[1]/virtio-backend [virtio-9p]
/machine/peripheral/virt2/virtio-backend [virtio-blk]
/machine/peripheral/virt1/virtio-backend [virtio-blk]
/machine/peripheral-anon/device[0]/virtio-backend [virtio-rng]
(qemu)
(qemu) info virtio-status /machine/peripheral-anon/device[3]/virtio-backend
/machine/peripheral-anon/device[3]/virtio-backend:
device_name: virtio-serial
device_id: 3
vhost_started: false
bus_name: (NULL)
broken: false
disabled: false
disable_legacy_check: false
started: true
use_started: true
start_on_kick: false
use_guest_notifier_mask: true
vm_running: true
num_vqs: 64
queue_sel: 63
isr: 1
endianness: little
status:
VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found,
VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device,
VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete,
VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready
Guest features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled,
VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)
VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported
unknown-features(0x0000010000000000)
Host features:
VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled,
VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported,
VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy),
VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts,
VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. descs. on VQ
VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported,
VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported
unknown-features(0x0000010040000000)
Backend features:
(qemu)
(qemu)
Leave The QEMU Monitor (Press CTRL-a c).
Welcome to Alpine Linux 3.19
Kernel 6.6.4-1-virt on an x86_64 (/dev/ttyS0)
localhost login: root
localhost:~#
localhost:~# ls -l /dev
total 0
drwxrwxrwx 2 root root 220 Apr 12 16:38 block
drwxr-xr-x 2 root root 80 Apr 12 16:35 bsg
drwxr-xr-x 3 root root 60 Apr 12 16:35 bus
lrwxrwxrwx 1 root root 3 Apr 12 16:38 cdrom -> sr0
crw------- 1 root tty 5, 1 Apr 12 16:34 console
crw-rw---- 1 root root 10, 127 Apr 12 16:34 cpu_dma_latency
drwxrwxrwx 5 root root 100 Apr 12 16:36 disk
drwxr-xr-x 2 root root 60 Apr 12 16:39 dri
crw-rw---- 1 root video 29, 0 Apr 12 16:39 fb0
lrwxrwxrwx 1 root root 13 Apr 12 16:37 fd -> /proc/self/fd
crw-rw-rw- 1 root root 1, 7 Apr 12 16:34 full
crw-rw---- 1 root root 10, 183 Apr 12 16:39 hwrng
drwxr-xr-x 2 root root 140 Apr 12 16:39 input
crw-rw---- 1 root root 1, 11 Apr 12 16:34 kmsg
srw-rw-rw- 1 root wheel 0 Apr 12 16:40 log
drwxr-xr-x 2 root root 200 Apr 12 16:35 loop
crw-rw---- 1 root root 10, 237 Apr 12 16:34 loop-control
brw------- 1 root root 7, 0 Apr 12 16:34 loop0
brw------- 1 root root 7, 1 Apr 12 16:34 loop1
brw------- 1 root root 7, 2 Apr 12 16:34 loop2
brw------- 1 root root 7, 3 Apr 12 16:34 loop3
brw------- 1 root root 7, 4 Apr 12 16:34 loop4
brw------- 1 root root 7, 5 Apr 12 16:34 loop5
brw------- 1 root root 7, 6 Apr 12 16:34 loop6
brw------- 1 root root 7, 7 Apr 12 16:34 loop7
crw-r----- 1 root kmem 1, 1 Apr 12 16:34 mem
drwxr-xr-x 2 root root 60 Apr 12 16:39 misc
drwxrwxrwt 2 root root 40 Apr 12 16:34 mqueue
crw-rw-rw- 1 root root 1, 3 Apr 12 16:34 null
crw-r----- 1 root kmem 1, 4 Apr 12 16:34 port
crw------- 1 root root 10, 1 Apr 12 16:39 psaux
crw-rw-rw- 1 root tty 5, 2 Apr 12 16:34 ptmx
drwxr-xr-x 2 root root 0 Apr 12 16:34 pts
crw-rw-rw- 1 root root 1, 8 Apr 12 16:34 random
crw-rw---- 1 root root 251, 0 Apr 12 16:34 rtc0
brw-rw---- 1 root disk 8, 0 Apr 12 16:35 sda
brw-rw---- 1 root disk 8, 1 Apr 12 16:35 sda1
drwxrwxrwt 2 root root 40 Apr 12 16:34 shm
brw-rw---- 1 root cdrom 11, 0 Apr 12 16:35 sr0
lrwxrwxrwx 1 root root 15 Apr 12 16:37 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root 15 Apr 12 16:37 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root 15 Apr 12 16:37 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root tty 5, 0 Apr 12 16:41 tty
crw------- 1 root root 4, 0 Apr 12 16:34 tty0
crw--w---- 1 root root 4, 1 Apr 12 16:40 tty1
crw-rw---- 1 root tty 4, 10 Apr 12 16:34 tty10
crw-rw---- 1 root tty 4, 11 Apr 12 16:34 tty11
crw-rw---- 1 root tty 4, 12 Apr 12 16:34 tty12
crw-rw---- 1 root tty 4, 13 Apr 12 16:34 tty13
crw-rw---- 1 root tty 4, 14 Apr 12 16:34 tty14
crw-rw---- 1 root tty 4, 15 Apr 12 16:34 tty15
crw-rw---- 1 root tty 4, 16 Apr 12 16:34 tty16
crw-rw---- 1 root tty 4, 17 Apr 12 16:34 tty17
crw-rw---- 1 root tty 4, 18 Apr 12 16:34 tty18
crw-rw---- 1 root tty 4, 19 Apr 12 16:34 tty19
crw--w---- 1 root root 4, 2 Apr 12 16:40 tty2
crw-rw---- 1 root tty 4, 20 Apr 12 16:34 tty20
crw-rw---- 1 root tty 4, 21 Apr 12 16:34 tty21
crw-rw---- 1 root tty 4, 22 Apr 12 16:34 tty22
crw-rw---- 1 root tty 4, 23 Apr 12 16:34 tty23
crw-rw---- 1 root tty 4, 24 Apr 12 16:34 tty24
crw-rw---- 1 root tty 4, 25 Apr 12 16:34 tty25
crw-rw---- 1 root tty 4, 26 Apr 12 16:34 tty26
crw-rw---- 1 root tty 4, 27 Apr 12 16:34 tty27
crw-rw---- 1 root tty 4, 28 Apr 12 16:34 tty28
crw-rw---- 1 root tty 4, 29 Apr 12 16:34 tty29
crw--w---- 1 root root 4, 3 Apr 12 16:40 tty3
crw-rw---- 1 root tty 4, 30 Apr 12 16:34 tty30
crw-rw---- 1 root tty 4, 31 Apr 12 16:34 tty31
crw-rw---- 1 root tty 4, 32 Apr 12 16:34 tty32
crw-rw---- 1 root tty 4, 33 Apr 12 16:34 tty33
crw-rw---- 1 root tty 4, 34 Apr 12 16:34 tty34
crw-rw---- 1 root tty 4, 35 Apr 12 16:34 tty35
crw-rw---- 1 root tty 4, 36 Apr 12 16:34 tty36
crw-rw---- 1 root tty 4, 37 Apr 12 16:34 tty37
crw-rw---- 1 root tty 4, 38 Apr 12 16:34 tty38
crw-rw---- 1 root tty 4, 39 Apr 12 16:34 tty39
crw--w---- 1 root root 4, 4 Apr 12 16:40 tty4
crw-rw---- 1 root tty 4, 40 Apr 12 16:34 tty40
crw-rw---- 1 root tty 4, 41 Apr 12 16:34 tty41
crw-rw---- 1 root tty 4, 42 Apr 12 16:34 tty42
crw-rw---- 1 root tty 4, 43 Apr 12 16:34 tty43
crw-rw---- 1 root tty 4, 44 Apr 12 16:34 tty44
crw-rw---- 1 root tty 4, 45 Apr 12 16:34 tty45
crw-rw---- 1 root tty 4, 46 Apr 12 16:34 tty46
crw-rw---- 1 root tty 4, 47 Apr 12 16:34 tty47
crw-rw---- 1 root tty 4, 48 Apr 12 16:34 tty48
crw-rw---- 1 root tty 4, 49 Apr 12 16:34 tty49
crw--w---- 1 root root 4, 5 Apr 12 16:40 tty5
crw-rw---- 1 root tty 4, 50 Apr 12 16:34 tty50
crw-rw---- 1 root tty 4, 51 Apr 12 16:34 tty51
crw-rw---- 1 root tty 4, 52 Apr 12 16:34 tty52
crw-rw---- 1 root tty 4, 53 Apr 12 16:34 tty53
crw-rw---- 1 root tty 4, 54 Apr 12 16:34 tty54
crw-rw---- 1 root tty 4, 55 Apr 12 16:34 tty55
crw-rw---- 1 root tty 4, 56 Apr 12 16:34 tty56
crw-rw---- 1 root tty 4, 57 Apr 12 16:34 tty57
crw-rw---- 1 root tty 4, 58 Apr 12 16:34 tty58
crw-rw---- 1 root tty 4, 59 Apr 12 16:34 tty59
crw--w---- 1 root root 4, 6 Apr 12 16:40 tty6
crw-rw---- 1 root tty 4, 60 Apr 12 16:34 tty60
crw-rw---- 1 root tty 4, 61 Apr 12 16:34 tty61
crw-rw---- 1 root tty 4, 62 Apr 12 16:34 tty62
crw-rw---- 1 root tty 4, 63 Apr 12 16:34 tty63
crw------- 1 root root 4, 7 Apr 12 16:34 tty7
crw------- 1 root root 4, 8 Apr 12 16:34 tty8
crw------- 1 root root 4, 9 Apr 12 16:34 tty9
crw------- 1 root root 4, 64 Apr 12 16:41 ttyS0
crw-rw---- 1 root uucp 4, 65 Apr 12 16:34 ttyS1
crw-rw---- 1 root uucp 4, 66 Apr 12 16:34 ttyS2
crw-rw---- 1 root uucp 4, 67 Apr 12 16:34 ttyS3
cr--r--r-- 1 root root 1, 9 Apr 12 16:34 urandom
lrwxrwxrwx 1 root root 3 Apr 12 16:38 usbdisk -> sda
crw-rw---- 1 root tty 7, 0 Apr 12 16:34 vcs
crw-rw---- 1 root tty 7, 1 Apr 12 16:34 vcs1
crw-rw---- 1 root tty 7, 2 Apr 12 16:40 vcs2
crw-rw---- 1 root tty 7, 3 Apr 12 16:40 vcs3
crw-rw---- 1 root tty 7, 4 Apr 12 16:40 vcs4
crw-rw---- 1 root tty 7, 5 Apr 12 16:40 vcs5
crw-rw---- 1 root tty 7, 6 Apr 12 16:40 vcs6
crw-rw---- 1 root tty 7, 128 Apr 12 16:34 vcsa
crw-rw---- 1 root tty 7, 129 Apr 12 16:34 vcsa1
crw-rw---- 1 root tty 7, 130 Apr 12 16:40 vcsa2
crw-rw---- 1 root tty 7, 131 Apr 12 16:40 vcsa3
crw-rw---- 1 root tty 7, 132 Apr 12 16:40 vcsa4
crw-rw---- 1 root tty 7, 133 Apr 12 16:40 vcsa5
crw-rw---- 1 root tty 7, 134 Apr 12 16:40 vcsa6
crw-rw---- 1 root root 7, 64 Apr 12 16:34 vcsu
crw-rw---- 1 root root 7, 65 Apr 12 16:34 vcsu1
crw-rw---- 1 root root 7, 66 Apr 12 16:40 vcsu2
crw-rw---- 1 root root 7, 67 Apr 12 16:40 vcsu3
crw-rw---- 1 root root 7, 68 Apr 12 16:40 vcsu4
crw-rw---- 1 root root 7, 69 Apr 12 16:40 vcsu5
crw-rw---- 1 root root 7, 70 Apr 12 16:40 vcsu6
brw-rw---- 1 root disk 253, 0 Apr 12 16:35 vda
brw-rw---- 1 root disk 253, 1 Apr 12 16:35 vda1
brw-rw---- 1 root disk 253, 2 Apr 12 16:35 vda2
brw-rw---- 1 root disk 253, 16 Apr 12 16:35 vdb
brw-rw---- 1 root disk 253, 17 Apr 12 16:35 vdb1
brw-rw---- 1 root disk 253, 18 Apr 12 16:35 vdb2
drwxrwxrwx 2 root root 60 Apr 12 16:38 virtio-ports
crw------- 1 root root 246, 1 Apr 12 16:34 vport5p1
crw-rw-rw- 1 root root 1, 5 Apr 12 16:34 zero
localhost:~#
localhost:~# ls -l /dev/virtio-ports
total 0
lrwxrwxrwx 1 root root 11 Apr 12 16:38 vport5p1 -> ../vport5p1
localhost:~#
localhost:~# blkid
/dev/loop0: TYPE="squashfs"
/dev/sda1: LABEL="ext4-drive" UUID="c6a6570a-0a09-46b3-aaa9-f908b017b583" TYPE="ext4"
/dev/vda: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda1: LABEL="alpine-virt 3.19.0 x86_64" TYPE="iso9660"
/dev/vda2: TYPE="vfat"
/dev/vdb: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb1: LABEL="alpine-ext 3.19.0 x86_64" TYPE="iso9660"
/dev/vdb2: TYPE="vfat"
/dev/loop/0: TYPE="squashfs"
localhost:~#
localhost:~# # Excerpt from "dmesg"
localhost:~#
[ 61.006091] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 61.455005] scsi host6: usb-storage 1-1:1.0
[ 63.106499] scsi 6:0:0:0: Direct-Access Memorex USB Flash Drive PMAP PQ: 0 ANS6
[ 63.484861] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[ 63.516423] sd 6:0:0:0: [sda] Write Protect is off
[ 63.520492] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00
[ 63.544467] sd 6:0:0:0: [sda] No Caching mode page found
[ 63.545145] sd 6:0:0:0: [sda] Assuming drive cache: write through
[ 63.883226] sda: sda1
[ 63.937232] sd 6:0:0:0: [sda] Attached SCSI removable disk
localhost:~#
localhost:~# mkdir /media/usb1 /media/test
localhost:~# mount -t ext4 /dev/sda1 /media/usb1
localhost:~#
localhost:~# df -h
Filesystem Size Used Available Use% Mounted on
devtmpfs 10.0M 0 10.0M 0% /dev
shm 487.4M 0 487.4M 0% /dev/shm
/dev/vda 60.0M 60.0M 0 100% /media/vda
/dev/vdb 957.0M 957.0M 0 100% /media/vdb
tmpfs 487.4M 10.1M 477.3M 2% /
tmpfs 195.0M 44.0K 194.9M 0% /run
/dev/loop0 19.1M 19.1M 0 100% /.modloop
/dev/sda1 14.1G 6.7G 7.4G 47% /media/usb1
localhost:~#
localhost:~# apk add --repositories-file /media/usb1/repository-index.txt nginx
(1/4) Installing hiredis (1.2.0-r0)
(2/4) Installing pcre (8.45-r3)
(3/4) Installing nginx (1.24.0-r14)
Executing nginx-1.24.0-r14.pre-install
Executing nginx-1.24.0-r14.post-install
(4/4) Installing nginx-openrc (1.24.0-r14)
Executing busybox-1.36.1-r15.trigger
OK: 12 MiB in 31 packages
localhost:~#
localhost:~# apk add socat curl
(1/12) Installing ca-certificates (20230506-r0)
(2/12) Installing brotli-libs (1.1.0-r1)
(3/12) Installing c-ares (1.22.1-r0)
(4/12) Installing libunistring (1.1-r2)
(5/12) Installing libidn2 (2.3.4-r4)
(6/12) Installing nghttp2-libs (1.58.0-r0)
(7/12) Installing libcurl (8.5.0-r0)
(8/12) Installing curl (8.5.0-r0)
(9/12) Installing ncurses-terminfo-base (6.4_p20231125-r0)
(10/12) Installing libncursesw (6.4_p20231125-r0)
(11/12) Installing readline (8.2.1-r2)
(12/12) Installing socat (1.8.0.0-r0)
Executing busybox-1.36.1-r15.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 18 MiB in 43 packages
localhost:~#
localhost:~# cd /media/test
localhost:/media/test#
localhost:/media/test# dd if=/dev/random of=/media/test/100mb bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (100.0MB) copied, 17.739540 seconds, 5.6MB/s
localhost:/media/test#
localhost:/media/test# sha256sum 100mb > checksum
localhost:/media/test#
localhost:/media/test# cat checksum
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925 100mb
localhost:/media/test#
localhost:/media/test# setup-interfaces
Available interfaces are: eth0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0]
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]
Do you want to do any manual network configuration? (y/n) [n]
localhost:/media/test#
localhost:/media/test# rc-service networking start
* Caching service dependencies ...
[ ok ]
* Starting networking ...
* lo ...
[ ok ]
* eth0 ...
udhcpc: started, v1.36.1
udhcpc: broadcasting discover
udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400
[ ok ]
localhost:/media/test#
localhost:/media/test# cd
localhost:~#
localhost:~# cp -pr /media/usb1/*WORKING2*/etc /media/usb1/*WORKING2*/root
localhost:~#
localhost:~# cp root/*conf .
Termux Session:
.../etc/nginx $ pwd
/data/data/com.termux/files/usr/etc/nginx
.../etc/nginx $
.../etc/nginx $ cat nginx.conf
.../etc/nginx $
#user nobody;
worker_processes 1;
error_log etc/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root /data/data/com.termux/files/usr/share/nginx/html;
# index index.html index.htm;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://unix:/data/data/com.termux/files/home/qemu/termux.socket;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# root /data/data/com.termux/files/usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# }
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
.../etc/nginx $ pwd
/data/data/com.termux/files/usr/etc/nginx
.../etc/nginx $
QEMU Linux Server:
localhost:~# ls
etc root use-socket.conf
fromWORKSdefault.conf use-network.conf
localhost:~# cat use-network.conf
localhost:/etc/nginx/http.d#
server {
listen 80 default_server;
location / {
root /media;
autoindex on;
index index.html index.htm;
}
}
localhost:/etc/nginx/http.d#
localhost:~# cd /etc/nginx/http.d
localhost:/etc/nginx/http.d# ls
default.conf
localhost:/etc/nginx/http.d# mv default.conf default.conf-original
localhost:/etc/nginx/http.d# cp -p /root/use-network.conf .
localhost:/etc/nginx/http.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# nginx
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# cat /var/log/nginx/access.log /var/log/nginx/
Termux Session:
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:9999/test/100mb
--2024-04-12 13:04:01-- http://127.0.0.1:9999/test/100mb
Connecting to 127.0.0.1:9999... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100mb’
100mb 100%[=========================>] 100.00M 340KB/s in 3m 44s
2024-04-12 13:07:45 (456 KB/s) - ‘100mb’ saved [104857600/104857600]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:9999/test/checksum
--2024-04-12 13:11:34-- http://127.0.0.1:9999/test/checksum
Connecting to 127.0.0.1:9999... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72 [application/octet-stream]
Saving to: ‘checksum’
checksum 100%[=========================>] 72 --.-KB/s in 0s
2024-04-12 13:11:34 (1.76 MB/s) - ‘checksum’ saved [72/72]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $
QEMU Linux Server:
localhost:/etc/nginx/http.d# ls /dev|grep vport
vport5p1
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# ls /dev|grep virt
virtio-ports
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# ls -R /dev/virtio-ports
/dev/virtio-ports:
vport5p1
localhost:/etc/nginx/http.d# socat -t 1000 /dev/vport5p1,ignoreeof TCP4-CONNECT:127.0.0.1:80
Termux Session:
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/100mb
--2024-04-12 13:18:02-- http://127.0.0.1:8888/test/100mb
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100mb.1’
100mb.1 100%[=========================>] 100.00M 3.12MB/s in 32s
2024-04-12 13:18:34 (3.10 MB/s) - ‘100mb.1’ saved [104857600/104857600]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/checksum
--2024-04-12 13:18:47-- http://127.0.0.1:8888/test/checksum
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72 [application/octet-stream]
Saving to: ‘checksum.1’
checksum.1 100%[=========================>] 72 --.-KB/s in 0s
2024-04-12 13:18:47 (1.06 MB/s) - ‘checksum.1’ saved [72/72]
~/.../usbredir-main/tools $
QEMU Linux Server, "^C" (CTRL-C) Stops "socat":
^C
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# ls
default.conf-original use-network.conf
localhost:/etc/nginx/http.d# mv use-network.conf use-network.conf-works
localhost:/etc/nginx/http.d# cp -p /root/use-socket.conf .
localhost:/etc/nginx/http.d# ls
default.conf-original use-network.conf-works use-socket.conf
localhost:/etc/nginx/http.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# cat /root/use-socket.conf
server {
listen unix:/tmp/termux.socket;
location / {
root /media;
autoindex on;
index index.html index.htm;
}
}
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# pkill nginx
localhost:/etc/nginx/http.d# pgrep nginx
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# nginx
localhost:/etc/nginx/http.d#
localhost:/etc/nginx/http.d# socat -t 1000 /dev/vport5p1,ignoreeof UNIX-CONNECT:/tmp/termux.socket
Termux Session:
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/100mb
--2024-04-12 13:24:28-- http://127.0.0.1:8888/test/100mb
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 104857600 (100M) [application/octet-stream]
Saving to: ‘100mb.2’
100mb.2 100%[=========================>] 100.00M 4.41MB/s in 22s
2024-04-12 13:24:51 (4.45 MB/s) - ‘100mb.2’ saved [104857600/104857600]
~/.../usbredir-main/tools $ wget http://127.0.0.1:8888/test/checksum
--2024-04-12 13:24:56-- http://127.0.0.1:8888/test/checksum
Connecting to 127.0.0.1:8888... connected.
HTTP request sent, awaiting response... 200 OK
Length: 72 [application/octet-stream]
Saving to: ‘checksum.2’
checksum.2 100%[=========================>] 72 --.-KB/s in 0s
2024-04-12 13:24:56 (1.00 MB/s) - ‘checksum.2’ saved [72/72]
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cat checksum
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925 100mb
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cat checksum.1
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925 100mb
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cat checksum.2
b738d45880117ab5d9d6686674287936fc079d2c15ee4543f9d576e4d5dea925 100mb
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ sha256sum -c checksum
100mb: OK
~/.../usbredir-main/tools $
~/.../usbredir-main/tools $ cmp 100mb 100mb.1
~/.../usbredir-main/tools $ cmp 100mb 100mb.2
~/.../usbredir-main/tools $
QEMU Linux Server, "^C" (CTRL-C) Stops "socat":
^C
localhost:/etc/nginx/http.d#
There is a lot of information here to parse. The first sentence is just
What's the correct way to use termux-usb to solve this?
followed by updates, custom usbredirect implementation and what not.
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 https://github.com/termux/termux-packages/issues/19635
(https://github.com/termux/termux-packages/issues/19635) is used on the Android 11 smartphone (not rooted, 4 cores, 3 gigabytes of RAM) and the QEMU Linux Server is currently running Alpine Linux. Have to share an update: A 5-terabyte platters-are-rotating USB hard drive was plugged in a Fedora Linux server (a physical machine with many USB ports) and connected to the QEMU Linux Server with termux-usb and usbredirect, and querying the drive with "hdparm" and "smartctl" from the QEMU Linux Server worked.
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 https://github.com/termux/termux-packages/issues/19635#issuecomment-205251940
(https://github.com/termux/termux-packages/issues/19635#issuecomment-205251940) with "-device virtserialport" and the Unix domain socket "termux.socket" works and it's faster than using the Internet domain socket interface, but is the experimental configuration safe or correct?
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.
Reference-1: "On-My-Mind-5" at https://github.com/termux/termux-packages/issues/19635#issuecomment-2053889740
(https://github.com/termux/termux-packages/issues/19635#issuecomment-2053889740)
Reference-2: "Termux, sockets, QEMU, and the Linux operating system" at https://github.com/termux/termux-packages/issues/19635#issuecomment-2052519401
(https://github.com/termux/termux-packages/issues/19635#issuecomment-2052519401)
Observation-1: Listing shares with "smbclient --configfile=$HOME/smb.conf --no-pass --ip-address=127.0.0.1 --port=44444 --debuglevel=10 --timeout=60 -L 127.0.0.1" doesn't work.
Conclusion: For "termux.socket" use the path to the share. Skip share listing.
Observation-2: Two Android file manager apps connected to the Samba (SMB) server using "termux.socket" when given "127.0.0.1:44444/public".
Termux Session, USB flash drive in the smartphone's USB port:
~/.../build/tools $
~/.../build/tools $ termux-usb -l
[
"/dev/bus/usb/001/025"
]
~/.../build/tools $
~/.../build/tools $ termux-usb -r /dev/bus/usb/001/025
Access granted.
~/.../build/tools $
~/.../build/tools $ termux-usb -e "/data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/025 --as 127.0.0.1:10000" /dev/bus/usb/001/025
IN-MAIN-BEFORE-parse_opts argc = 6
IN-MAIN-BEFORE-parse_opts argv[0] = /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect
IN-MAIN-BEFORE-parse_opts argv[1] = --device
IN-MAIN-BEFORE-parse_opts argv[2] = /dev/bus/usb/001/025
IN-MAIN-BEFORE-parse_opts argv[3] = --as
IN-MAIN-BEFORE-parse_opts argv[4] = 127.0.0.1:10000
IN-MAIN-BEFORE-parse_opts argv[5] = 7
IN-MAIN-BEFORE sscanf argc = 2
IN-MAIN-BEFORE sscanf argv[0] = /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect
IN-MAIN-BEFORE sscanf argv[1] = 7
IN-MAIN-BEFORE sscanf argv[2] = (null)
IN-MAIN-BEFORE sscanf argv[3] = (null)
IN-MAIN-BEFORE sscanf argv[4] = (null)
IN-MAIN-BEFORE sscanf argv[5] = (null)
Vendor ID: 0718
Product ID: 7722
Manufacturer: Memorex
Product: USB Flash Drive
QEMU Monitor:
(qemu)
(qemu) info chardev
c2: filename=disconnected:tcp:127.0.0.1:50000
serial0: filename=mux
c1: filename=disconnected:tcp:127.0.0.1:50000
serial0-base: filename=stdio
parallel0: filename=null
console-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/console.socket,server=on
termux-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/termux.socket,server=on
(qemu)
(qemu) device_del u1
(qemu) device_del u2
(qemu)
(qemu) chardev-add socket,host=127.0.0.1,port=10000,id=c1
(qemu)
(qemu) device_add usb-redir,id=u1,debug=3,chardev=c1
(qemu) qemu-system-x86_64: usbredirparser: Peer version: usbredir 0.14.0, using 64-bits ids qemu-system-x86_64: usb-redir: attaching high speed device 0718:7722 version 1.0 class 00
(qemu)
(qemu) info chardev
serial0: filename=mux
c1: filename=tcp:127.0.0.1:42376 <-> 127.0.0.1:10000
serial0-base: filename=stdio
parallel0: filename=null
console-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/console.socket,server=on
termux-socket: filename=disconnected:unix:/data/data/com.termux/files/home/qemu/termux.socket,server=on
(qemu)
Termux Session:
~/qemu $ pwd
/data/data/com.termux/files/home/qemu
~/qemu $ ps -eaf|cat
UID PID PPID C STIME TTY TIME CMD
u0_a189 2668 457 1 1970 ? 01:49:54 com.termux
u0_a189 2872 2668 0 1970 pts/16 00:00:01 /data/data/com.termux/files/usr/bin/bash -l
u0_a189 3606 2668 0 1970 pts/17 00:00:04 /data/data/com.termux/files/usr/bin/bash -l
u0_a189 4268 2668 0 1970 pts/18 00:00:05 /data/data/com.termux/files/usr/bin/bash -l
u0_a189 4477 2668 0 1970 pts/19 00:00:01 /data/data/com.termux/files/usr/bin/bash -l
u0_a189 8110 8114 0 1970 ? 00:00:00 /data/data/com.termux/files/usr/bin/sshd -p 8022 -R
u0_a189 8111 8110 0 1970 pts/21 00:00:00 /data/data/com.termux/files/usr/bin/bash -l
u0_a189 8114 1 0 1970 ? 00:00:00 sshd -p 8022
u0_a189 8219 457 0 1970 ? 00:00:00 com.termux.api
u0_a189 8321 2872 0 1970 pts/16 00:00:00 /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/bin/termux-usb -e /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/025 --as 127.0.0.1:10000 /dev/bus/usb/001/025
u0_a189 8322 8321 0 1970 pts/16 00:00:00 /data/data/com.termux/files/usr/bin/bash /data/data/com.termux/files/usr/libexec/termux-callback 7
u0_a189 8340 8322 0 1970 pts/16 00:00:02 /data/data/com.termux/files/home/usb-test/usbredir-main/build/tools/usbredirect --device /dev/bus/usb/001/025 --as 127.0.0.1:10000 7
u0_a189 8591 8111 1 1970 pts/21 00:00:00 ps -eaf
u0_a189 8592 8111 1 1970 pts/21 00:00:00 cat
u0_a189 10968 2668 0 1970 pts/20 00:00:01 /data/data/com.termux/files/usr/bin/bash -l
u0_a189 14101 4477 0 1970 pts/19 00:00:00 bash
u0_a189 20326 3606 27 1970 pts/17 07:40:14 qemu-system-x86_64 -m 1024M -machine q35 -smp 4 -device virtio-rng-pci -nographic -readconfig /data/data/com.termux/files/home/ich9-ehci-uhci.cfg -drive if=none,id=iso1,readonly=on,format=raw,file=/data/data/com.termux/files/home/qemu/alpine-virt-3.19.0-x86_64.iso -device virtio-blk-pci,id=virt1,drive=iso1,bootindex=1 -drive if=none,id=iso2,readonly=on,format=raw,file=/data/data/com.termux/files/home/qemu/alpine-extended-3.19.0-x86_64.iso -device virtio-blk-pci,id=virt2,drive=iso2 -virtfs local,security_model=none,id=termux,mount_tag=termux,path=/data/data/com.termux/files -virtfs local,security_model=none,id=host,mount_tag=host,path=/storage/emulated/0/Download/usb1 -device virtio-serial -chardev socket,path=/data/data/com.termux/files/home/qemu/termux.socket,id=termux-socket,name=talk-to-termux,server=on,wait=off -device virtserialport,id=port1,chardev=termux-socket -device virtio-net-pci,netdev=net0,mac=52:54:12:34:56:78 -netdev user,id=net0,ipv6=off,hostfwd=tcp::9999-:80 -chardev socket,path=/data/data/com.termux/files/home/qemu/console.socket,id=console-socket,server=on,wait=off,name=talk-to-console -device virtconsole,id=port2,chardev=console-socket
~/qemu $
QEMU Linux Server Session:
alpine:/etc/samba# uname -a
Linux alpine 6.6.4-1-virt #2-Alpine SMP PREEMPT_DYNAMIC Tue, 05 Dec 2023 20:25:50 +0000 x86_64 GNU/Linux
alpine:/etc/samba#
alpine:/etc/samba# # Excerpt from "dmesg"
[96543.600169] usb 1-5: new high-speed USB device number 6 using ehci-pci
[96544.144221] usb 1-5: New USB device found, idVendor=0718, idProduct=7722, bcdDevice= 1.00
[96544.145762] usb 1-5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[96544.150614] usb 1-5: Product: USB Flash Drive
[96544.151198] usb 1-5: Manufacturer: Memorex
[96544.351307] usb-storage 1-5:1.0: USB Mass Storage device detected
[96544.530540] scsi host6: usb-storage 1-5:1.0
[96545.923868] scsi 6:0:0:0: Direct-Access Memorex USB Flash Drive PMAP PQ: 0 ANSI: 6
[96546.404591] sd 6:0:0:0: [sda] 30285824 512-byte logical blocks: (15.5 GB/14.4 GiB)
[96546.437153] sd 6:0:0:0: [sda] Write Protect is off
[96546.443045] sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00
[96546.467463] sd 6:0:0:0: [sda] No Caching mode page found
[96546.471992] sd 6:0:0:0: [sda] Assuming drive cache: write through
[96546.901541] sda: sda1
[96546.969643] sd 6:0:0:0: [sda] Attached SCSI removable disk
alpine:/etc/samba#
alpine:/etc/samba# blkid /dev/sda1
/dev/sda1: LABEL="ext4-drive" UUID="c6a6570a-0a09-46b3-aaa9-f908b017b583" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="e568d9fc-01"
alpine:/etc/samba#
alpine:/etc/samba# mount /dev/sda1 /media/usb1
alpine:/etc/samba# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 10M 0 10M 0% /dev
shm 488M 0 488M 0% /dev/shm
/dev/vda 60M 60M 0 100% /media/vda
/dev/vdb 957M 957M 0 100% /media/vdb
tmpfs 488M 159M 330M 33% /
tmpfs 195M 176K 195M 1% /run
/dev/loop0 20M 20M 0 100% /.modloop
host 117G 108G 8.1G 94% /media/host
termux 24G 23G 1.4G 95% /media/termux
/dev/sda1 15G 5.1G 9.1G 36% /media/usb1
alpine:/etc/samba#
alpine:/etc/samba#alpine:/etc/samba# ls -l /media/usb1
total 2090040
-rw-r--r-- 1 1000 1000 1073741824 Apr 6 18:58 1gb
-rw-r--r-- 1 root root 70 Apr 15 16:09 1gb-sha256-checksum.txt
-rw-r--r-- 1 1000 1000 1003487232 Apr 5 11:44 alpine-extended-3.19.0-x86_64.iso
-rw-r--r-- 1 1000 1000 833 Apr 5 11:44 alpine-extended-3.19.0-x86_64.iso.asc
-rw-r--r-- 1 1000 1000 100 Apr 5 11:44 alpine-extended-3.19.0-x86_64.iso.sha256
-rw-r--r-- 1 1000 1000 164 Apr 5 11:44 alpine-extended-3.19.0-x86_64.iso.sha512
-rw-r--r-- 1 1000 1000 62914560 Apr 5 11:43 alpine-virt-3.19.0-x86_64.iso
-rw-r--r-- 1 1000 1000 833 Apr 5 11:43 alpine-virt-3.19.0-x86_64.iso.asc
-rw-r--r-- 1 1000 1000 96 Apr 5 11:43 alpine-virt-3.19.0-x86_64.iso.sha256
-rw-r--r-- 1 1000 1000 160 Apr 5 11:43 alpine-virt-3.19.0-x86_64.iso.sha512
drwx------ 2 1000 1000 16384 Apr 5 11:18 lost+found
alpine:/etc/samba#
alpine:/etc/samba# cat smb.conf
#======================= Global Settings =====================================
[global]
workgroup = MYGROUP
server string = Samba Server
log file = /usr/local/samba/var/log.%m
max log size = 50
allow insecure wide links = yes
dos charset = cp866
unix charset = utf-8
security = user
map to guest = bad user
dns proxy = no
disable netbios = yes
#============================ Share Definitions ==============================
[public]
path = /media/usb1
browseable = yes
public = yes
writable = yes
guest ok = yes
follow symlinks = yes
wide links = yes
alpine:/etc/samba# testparm
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Weak crypto is allowed by GnuTLS (e.g. NTLM as a compatibility fallback)
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
allow insecure wide links = Yes
disable netbios = Yes
dns proxy = No
dos charset = cp866
log file = /usr/local/samba/var/log.%m
map to guest = Bad User
max log size = 50
security = USER
server string = Samba Server
workgroup = MYGROUP
idmap config * : backend = tdb
[public]
guest ok = Yes
path = /media/usb1
read only = No
wide links = Yes
alpine:/etc/samba#
alpine:/etc/samba#
alpine:/etc/samba# rc-service samba start
* Starting smbd ... [ ok ]
* Starting nmbd ... [ ok ]
alpine:/etc/samba# pkill nmbd
alpine:/etc/samba# pgrep nmbd
alpine:/etc/samba#
alpine:/etc/samba# socat -t 100000 /dev/vport5p1,ignoreeof TCP4-CONNECT:127.0.0.1:445 &
[1] 8351
alpine:/etc/samba#
Termux Session:
.../etc/nginx $
.../etc/nginx $ cat $HOME/smb.conf
[global]
client min protocol = NT1
.../etc/nginx $
.../etc/nginx $ socat TCP4-LISTEN:44444 UNIX-CONNECT:$HOME/qemu/termux.socket &
[1] 9408
.../etc/nginx $
.../etc/nginx $ smbclient --configfile=$HOME/smb.conf --no-pass --ip-address=127.0.0.1 --port=44444 --debuglevel=0 --timeout=60 '//127.0.0.1/public'
Try "help" to get a list of possible commands.
smb: \>
smb: \> ls alpine*
alpine-extended-3.19.0-x86_64.iso N 1003487232 Fri Apr 5 07:44:11 2024
alpine-virt-3.19.0-x86_64.iso.sha512 N 160 Fri Apr 5 07:43:58 2024
alpine-extended-3.19.0-x86_64.iso.asc N 833 Fri Apr 5 07:44:11 2024
alpine-virt-3.19.0-x86_64.iso.sha256 N 96 Fri Apr 5 07:43:58 2024
alpine-extended-3.19.0-x86_64.iso.sha512 N 164 Fri Apr 5 07:44:11 2024
alpine-extended-3.19.0-x86_64.iso.sha256 N 100 Fri Apr 5 07:44:11 2024
alpine-virt-3.19.0-x86_64.iso N 62914560 Fri Apr 5 07:43:57 2024
alpine-virt-3.19.0-x86_64.iso.asc N 833 Fri Apr 5 07:43:58 2024
14797704 blocks of size 1024. 9509404 blocks available
smb: \>
smb: \> get alpine-virt-3.19.0-x86_64.iso.sha256
smb: \> get alpine-virt-3.19.0-x86_64.iso
smb: \> quit
[1]+ Done socat TCP4-LISTEN:44444 UNIX-CONNECT:$HOME/qemu/termux.socket
.../etc/nginx $
.../etc/nginx $ ls -1
SESSION.txt
alpine-virt-3.19.0-x86_64.iso
alpine-virt-3.19.0-x86_64.iso.sha256
error.log
fastcgi.conf
fastcgi_params
koi-utf
koi-win
mime.types
nginx.conf
nginx.conf-b1
nginx.conf-orig
scgi_params
uwsgi_params
win-utf
.../etc/nginx $
.../etc/nginx $ sha256sum -c alpine-virt-3.19.0-x86_64.iso.sha256
alpine-virt-3.19.0-x86_64.iso: OK
.../etc/nginx $
.../etc/nginx $ uptime
15:59:27 up 6 days, 9:55, load average: 17.17, 17.27, 17.25
.../etc/nginx $
QEMU Linux Server:
alpine:/etc/samba# uptime
19:59:54 up 1 day, 6:26, 0 users, load average: 0.00, 0.11, 0.18
[1]+ Done socat -t 100000 /dev/vport5p1,ignoreeof TCP4-CONNECT:127.0.0.1:445
alpine:/etc/samba#
Here's an excerpt from https://github.com/termux/termux-packages/issues/19635#issuecomment-2052519401
("Termux, sockets, QEMU, and the Linux operating system"), the download speed is in kilobytes per second:
"wget http://127.0.0.1:9999/test/100mb" ("listen 80 default_server;"):
Length: 104857600 (100M) [application/octet-stream] 100%[=========================>] 100.00M 340KB/s in 3m 44s 2024-04-12 13:07:45 (456 KB/s) - ‘100mb’ saved [104857600/104857600]
Use "-device e1000" instead of "-device virtio-net-pci":
export VM=/storage/emulated/0/Download/usb1/vm-alpine-usb ; qemu-system-x86_64 -m 1500M,slots=16,maxmem=3G -machine q35 -smp 4 -device virtio-rng-pci -nographic -device ich9-usb-ehci1,id=ehci,addr=1d.7,multifunction=on -device ich9-usb-uhci1,id=uhci-1,addr=1d.0,multifunction=on,masterbus=ehci.0,firstport=0 -device ich9-usb-uhci2,id=uhci-2,addr=1d.1,multifunction=on,masterbus=ehci.0,firstport=2 -device ich9-usb-uhci3,id=uhci-3,addr=1d.2,multifunction=on,masterbus=ehci.0,firstport=4 -drive if=none,id=vm,format=raw,file=$VM -device virtio-blk-pci,id=vmvirt1,drive=vm,bootindex=1 -virtfs local,security_model=none,id=termux,mount_tag=termux,path=/data/data/com.termux/files -virtfs local,security_model=none,id=host,mount_tag=host,path=/storage/emulated/0/Download/usb1 -device virtio-serial -device e1000,netdev=net0,mac=52:54:12:34:56:78 -netdev user,id=net0,ipv6=off,hostfwd=tcp:127.0.0.1:9999-:80,hostfwd=tcp:127.0.0.1:9022-:22,hostfwd=tcp:127.0.0.1:9445-:445,hostfwd=:127.0.0.1:50021-:21,hostfwd=:127.0.0.1:50001-:50001,hostfwd=:127.0.0.1:50002-:50002,hostfwd=:127.0.0.1:50003-:50003,hostfwd=:127.0.0.1:50004-:50004,hostfwd=:127.0.0.1:50005-:50005,hostfwd=:127.0.0.1:50006-:50006,hostfwd=:127.0.0.1:50007-:50007,hostfwd=:127.0.0.1:50008-:50008,hostfwd=:127.0.0.1:50009-:50009,hostfwd=:127.0.0.1:50010-:50010,hostfwd=:127.0.0.1:50011-:50011,hostfwd=:127.0.0.1:50012-:50012,hostfwd=:127.0.0.1:50013-:50013,hostfwd=:127.0.0.1:50014-:50014,hostfwd=:127.0.0.1:50015-:50015,hostfwd=:127.0.0.1:50016-:50016,hostfwd=:127.0.0.1:50017-:50017,hostfwd=:127.0.0.1:50018-:50018,hostfwd=:127.0.0.1:50019-:50019,hostfwd=:127.0.0.1:50020-:50020 -chardev socket,host=127.0.0.1,port=10000,id=usbredirchardev1 -device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,debug=3
The QEMU Linux Server can only be accessed from 127.0.0.1.
On the QEMU Linux Server enable passive mode and anonymous mode for vsftpd by adding the following directives to the default server configuration file at "/etc/vsftpd/vsftpd.conf"; the configuration works for "lftp" and "mc" ("FTP Link" in the Midnight Commander file manager) and the FTP clients must use the passive mode and port 50021; anonymous is the username and no password is required:
anon_world_readable_only=NO
ftp_username=ftp
nopriv_user=ftp
anon_root=/media
seccomp_sandbox=NO
pasv_address=127.0.0.1
port_enable=YES
pasv_enable=YES
pasv_min_port=50001
pasv_max_port=50010
port_promiscuous=YES
connect_from_port_20=YES
anonymous_enable=YES
no_anon_password=YES
write_enable=YES
anon_other_write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
ls_recurse_enable=YES
Android: /data/data/com.termux/files/home is on internal storage. /storage/emulated/0/Download/usb1 is on adoptable storage.
QEMU Linux Server: usb1/tmp is a directory on /media/usb1. /media/usb1 is on a /dev/sda partition (ext4). /dev/sda is an 80-gigabyte, platters-are-rotating, 3.5-inch hard drive connected directly to the smartphone's USB-C 2.0 port with a cable. The hard drive is connected to the QEMU Linux Server using termux-usb and usbredirect.
Note: The best way to copy files and directories to and from the QEMU Linux Server is by logging in with "ssh root@127.0.0.1 -p 9022" and using the "cp" command ("man cp").
~ $
~ $ pwd
/data/data/com.termux/files/home
~ $
~ $ lftp 127.0.0.1 -p 50021
lftp 127.0.0.1:/> cd usb1/tmp
cd ok, cwd=/usb1/tmp
lftp 127.0.0.1:/usb1/tmp>
lftp 127.0.0.1:/usb1/tmp> put 1gb-internal-storage -o lftp-1gb-from-internal-storage
1073741824 bytes transferred in 331 seconds (3.10 MiB/s)
lftp 127.0.0.1:/usb1/tmp> quit
~ $ cd /storage/emulated/0/Download/usb1
.../Download/usb1 $
.../Download/usb1 $ pwd
/storage/emulated/0/Download/usb1
.../Download/usb1 $ lftp 127.0.0.1 -p 50021
lftp 127.0.0.1:~> cd usb1/tmp
cd ok, cwd=/usb1/tmp
lftp 127.0.0.1:/usb1/tmp> put 1gb-adoptable-storage -o lftp-1gb-from-adoptable-storage
1073741824 bytes transferred in 338 seconds (3.03 MiB/s)
lftp 127.0.0.1:/usb1/tmp> quit
.../Download/usb1 $
.../Download/usb1 $ rm -i /storage/emulated/0/Download/usb1/1gb-adoptable-storage $HOME/1gb-internal-storage
rm: remove regular file '/storage/emulated/0/Download/usb1/1gb-adoptable-storage'? y
rm: remove regular file '/data/data/com.termux/files/home/1gb-internal-storage'? y
.../Download/usb1 $
.../Download/usb1 $ lftp -p 50021 127.0.0.1
lftp 127.0.0.1:~> cd usb1/tmp
cd ok, cwd=/usb1/tmp
lftp 127.0.0.1:/usb1/tmp> get lftp-1gb-from-adoptable-storage -o 1gb-adoptable-storage
1073741824 bytes transferred in 565 seconds (1.81 MiB/s)
lftp 127.0.0.1:/usb1/tmp> quit
.../Download/usb1 $
.../Download/usb1 $ cd $HOME
~ $
~ $ lftp -p 50021 127.0.0.1
lftp 127.0.0.1:~> cd usb1/tmp
cd ok, cwd=/usb1/tmp
lftp 127.0.0.1:/usb1/tmp> get lftp-1gb-from-internal-storage -o 1gb-internal-storage
1073741824 bytes transferred in 580 seconds (1.77 MiB/s)
lftp 127.0.0.1:/usb1/tmp> quit
~ $
LFTP | Version 4.9.2
GNU Midnight Commander 4.8.30
# Termux
~ $ lscpu
Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Vendor ID: ARM
Model name: Cortex-A53
Model: 4
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
Stepping: r0p4
CPU(s) scaling MHz: 65%
CPU max MHz: 2001.0000
CPU min MHz: 850.0000
BogoMIPS: 27.96
Flags: half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vf
pd32 lpae evtstrm aes pmull sha1 sha2 crc32
QEMU emulator version 8.0.2
alpine:~# uname -a
Linux alpine 6.6.30-0-virt #1-Alpine SMP PREEMPT_DYNAMIC Mon, 06 May 2024 07:55:42 +0000 x86_64 GNU/Linux
alpine:~# apk add vsftpd archivemount hdparm util-linux-login fuse fuse-exfat exfatprogs less smartmontools grep gawk sed utmps udisks2 procps-ng coreutils findutils ntfs-3g ntfs-3g-progs xz lsof zip 7zip lvm2 mkinitfs grub grub-efi efibootmgr syslinux wget net-tools iproute2 ethtool hwdata iproute2-ss pciutils darkhttpd samba nginx socat curl ncurses shadow apache2 file mandoc man-pages mandoc-apropos docs nginx-mod-http-fancyindex nginx-mod-http-upload nginx-mod-http-upload-progress
"Documentation/Networking": https://wiki.qemu.org/Documentation/Networking
Comment from @NoteAfterNote to @victortoso and @Grimler91: https://github.com/termux/termux-packages/issues/19635#issuecomment-2053889740
("for this comment I will hold back praises")
"Termux, sockets, QEMU, and the Linux operating system": https://github.com/termux/termux-packages/issues/19635#issuecomment-2052519401
"Connecting a USB device to QEMU using termux, termux-usb, usbredirect": https://github.com/termux/termux-packages/issues/19635
"CIFS Documents Provider": https://github.com/wa2c/cifs-documents-provider (@wa2c), https://github.com/wa2c/cifs-documents-provider/wiki/Manual-ja , https://github-com.translate.goog/wa2c/cifs-documents-provider/wiki/Manual-ja?_x_tr_sl=ja&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp
"FTPClient - Simple FTP, FTPS and SFTP client for Android": https://codeberg.org/qwerty287/ftpclient , https://codeberg.org/qwerty287/ftpclient/releases
"Long download interrupted": https://codeberg.org/qwerty287/ftpclient/issues/37
"MiXplorer" "An Android file explorer": https://mixplorer.com , https://mixplorer.com/beta/ , https://xdaforums.com/t/app-2-2-mixplorer-v6-x-released-fully-featured-file-manager.1523691/
"Material Files": https://github.com/zhanghai/MaterialFiles (@zhanghai)
"Chmod calculator": https://play.google.com/store/apps/details?id=com.chmod.calc.o
Enough. That is a bug tracker for Termux packages and not a place for personal notes.
If you wish to share something with community, it is better to create a repo with docs or at least GitHub gist. Then it can be posted on https://www.reddit.com/r/termux/ or other social media.
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
(https://github.com/termux/termux-packages/issues/19635#issuecomment-2030116274) 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
Update-12: "Making A Filesystem(s) Mounted On The QEMU Linux Server More Accessible" at
https://github.com/termux/termux-packages/issues/19635#issuecomment-2115352094
(https://github.com/termux/termux-packages/issues/19635#issuecomment-2115352094)Connecting a USB device to QEMU using termux, termux-usb, usbredirect
Equivalent options for qemu-system-x86_64 if the ich9-ehci-uhci.cfg file is not used:
-device ich9-usb-ehci1,id=ehci,addr=1d.7,multifunction=on
-device ich9-usb-uhci1,id=uhci-1,addr=1d.0,multifunction=on,masterbus=ehci.0,firstport=0
-device ich9-usb-uhci2,id=uhci-2,addr=1d.1,multifunction=on,masterbus=ehci.0,firstport=2
-device ich9-usb-uhci3,id=uhci-3,addr=1d.2,multifunction=on,masterbus=ehci.0,firstport=4
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_APPVERSION_NAME=0.50.1 TERMUX_APP_PACKAGE_MANAGER=apt TERMUX_APPAM_SOCKET_SERVER_ENABLED=true TERMUX_APPAPK_PATH=/data/app/~~zMILa9TgJazQczw9C_x_Cg==/com.termux-t3s8rxYdbG9lbQ81IkrQaw==/base.apk TERMUX_APPAPK_RELEASE=GITHUB TERMUX_APPFILES_DIR=/data/user/0/com.termux/files TERMUX_APP__IS_DEBUGGABLE_BUILD=true TERMUX_APPIS_INSTALLED_ON_EXTERNAL_STORAGE=false TERMUX_APPPACKAGE_MANAGER=apt TERMUX_APPPACKAGE_NAME=com.termux TERMUX_APPPACKAGE_VARIANT=apt-android-7 TERMUX_APPSE_FILE_CONTEXT=u:object_r:app_data_file:s0:c189,c256,c512,c768 TERMUX_APPSE_INFO=default:targetSdkVersion=28:complete TERMUX_APPSE_PROCESS_CONTEXT=u:r:untrusted_app_27:s0:c189,c256,c512,c768 TERMUX_APPTARGET_SDK=28 TERMUX_APPVERSION_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/003argv[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: