Usb tty usage on unrooted

Im guessing its not in the api yet, I didnt see it Just got some tty lora modules; rq question about it, because I want to use in termux is there a easy way now, or are we still stuck with using a diffrent app, or writing a usb parser in termux? If proot can parse, thats fine too; I just want to mess with them in python, instead of directly sending at commands to it.
55 Replies
Cuteness
Cuteness2w ago
What proot really is, is just a pseudo AKA fake root. Termux is just an ordinary Android app, and as such, has no special access to the USB controller.
davidawesome01
davidawesome01OP2w ago
I understand; but other apps can access it, and its able to be parsed from the usb passthrough given from the termux api; so is there a known way to use this easily? I mean I can run a vm to parse the usb stuff but thats stupid
Cuteness
Cuteness2w ago
It depends on if your device's ROM supports it or not.
davidawesome01
davidawesome01OP2w ago
Other apps can read it; its able to work over usb, I mean is there a way to get a serial connection out of that tho easily
Cuteness
Cuteness2w ago
Did you read the EULA / ToS / whatever for the device and its official mobile app? There might be something that talks about not being allowed to decompile, use 3rd-party accessories to interact with it, or something.
davidawesome01
davidawesome01OP2w ago
I dont think there is an official mobile app for a usb uart adapter from pine64 (https://pine64.com/product/serial-console-woodpecker-edition/), nor the serial RYLR998 with datasheet published on their website for use in applications https://reyax.com/products/RYLR998 and even if there was; if I never installed, interacted with, or used the official app. Doing so would mean attempts to interact with the device is allowed. And I don't think those clauses are even legally enforceable if it was in there as long as it is not for personal gain, nor to the determent of the company, most can only remove your account. anyway, this joke about this being in any applicable has gone on long enough; its not. I just want to talk serial over termux, thats entirely legal, there is no official anything, and I just want to send AT commands automatically like I do on a computer
PINE STORE
SERIAL CONSOLE "Woodpecker" Edition - PINE STORE
The “Woodpecker” Edition Serial Console powered by CH340G chipset enabled simple USB to Serial communication for PINE64 related project development.
RYLR998|REYAX TECHNOLOGY
The RYLR998 transceiver module features the LoRa® long-range modem that provides ultra-long range spread spectrum communication and high interference immunity whilst minimizing current consumption.
davidawesome01
davidawesome01OP2w ago
waiting for the "using this product is illegal" clause to be added to everything I interact with This is why right to repare is important; it shouldnt be illegal to use my own purchased hardware for whatever I want; even if the hypothetical app says I cant, I own the hardware, and they cant stop me from decompiling the app and using that in my personal projects. That is only a factor in public information, or releases for non personal reasons and thats only the code its self; I can still make a tool for it as long as I dont use anything from the hypothetical app Can someone please help with this
Cuteness
Cuteness2w ago
First question: Are you actually using a physical Android phone / tablet, or are you using a Chromebook / etc.?
davidawesome01
davidawesome01OP2w ago
Android phone Github apk Android 13
ted
ted2w ago
@davidawesome01 the problem you're having is that linux-flavored programs expect to talk to serial devices (USB or otherwise) via /dev/tty*, which android doesn't give apps access to. any android app talking to a USB serial device is doing it via android's own APIs, which no linux-flavored program is going to be able to talk to. USB passthrough to a VM should work, as you said; reimplementing raw USB access into something that looks like a tty would work but sounds like a bad time; a proot cannot help.
twaik
twaik2w ago
Hm... But pty should be compatible with tty. I'll try to open feature request in termux:api repo for this. Oh, there is no java api for working with serial devices. Sad. But probably we could write some termux-usb + libusb based project which could spawn pty redirecting all input and output to serial usb device.
davidawesome01
davidawesome01OP2w ago
I was thinking of just doing that lol, seams not tooo bad. I was hoping this existed hense the question.
ted
ted2w ago
think you might be underestimating it. you have to fork or reimplement the entirety of the kernel drivers for these things, plus whatever common kernel functionality they use, for each chipset you want to support. might not be that much code but I will be very proud of you if you send a mergeable PR for this
twaik
twaik2w ago
Probably I could implement something similar, but I do not have any usb serial devices for tests.
davidawesome01
davidawesome01OP2w ago
1. USB is a standardized protocal, so I dont think it would be for "each chipset you want to support" 2. I think usb parsers already exist in userspace (https://github.com/pyusb/pyusb) from a google search seams to work, but we would prob want a java one if we wanted a termux api for it 3. Not sure if I have the time; Right now got a whole bunch of tests and finals to study for, may look into it in a bit
GitHub
GitHub - pyusb/pyusb: Easy USB access for Python
Easy USB access for Python. Contribute to pyusb/pyusb development by creating an account on GitHub.
davidawesome01
davidawesome01OP2w ago
If your device is not one of the above listed devices, compatible with the above models, you can try out the “generic” interface. This interface does not provide any type of control messages sent to the device, and does not support any kind of device flow control. All that is required of your device is that it has at least one bulk in endpoint, or one bulk out endpoint.
If your device is not one of the above listed devices, compatible with the above models, you can try out the “generic” interface. This interface does not provide any type of control messages sent to the device, and does not support any kind of device flow control. All that is required of your device is that it has at least one bulk in endpoint, or one bulk out endpoint.
- https://docs.kernel.org/usb/usb-serial.html Looks like generic works for alomst everything; so would need to look at it but if using somthing like https://github.com/pyusb/pyusb, adding somthing simplistic like usb parsing to fake uart should be easy if we do that, would it be part of termux api? and if so, should it make a fake file like the ones generated by termux already, or should it just allow for specifying a location for the pty / fifo?
davidawesome01
davidawesome01OP2w ago
https://github.com/mik3y/usb-serial-for-android found this as a base, let me check license
GitHub
GitHub - mik3y/usb-serial-for-android: Android USB host serial driv...
Android USB host serial driver library for CDC, FTDI, Arduino and other devices. - mik3y/usb-serial-for-android
davidawesome01
davidawesome01OP2w ago
Is termux api MIT compatable, and dose it use 3rd party libs, or are we going to just write a new lib for it;I think https://github.com/mik3y/usb-serial-for-android?tab=MIT-1-ov-file Being MIT should work, or if not can use used as a basis for termux-api's
GitHub
GitHub - mik3y/usb-serial-for-android: Android USB host serial driv...
Android USB host serial driver library for CDC, FTDI, Arduino and other devices. - mik3y/usb-serial-for-android
ted
ted2w ago
do you see how this specifically lists the hardware it supports
davidawesome01
davidawesome01OP2w ago
GitHub
usb-serial-for-android/usbSerialForAndroid/src/main/java/com/hoho/a...
Android USB host serial driver library for CDC, FTDI, Arduino and other devices. - mik3y/usb-serial-for-android
ted
ted2w ago
USB is standardized; I don't think the way you implement a serial adapter over USB is
davidawesome01
davidawesome01OP2w ago
That is extra things like control flow that are not in the CDCAMC spec
ted
ted2w ago
sure that's the point
davidawesome01
davidawesome01OP2w ago
serial its self is tho, thats why you can just add https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java and it will cover almost every device just not the extra features
ted
ted2w ago
if you think that's enough to be useful (and I don't know that it isn't), go for it if you want an unmodified program to work, the only option is LD_PRELOAD shenanigans
davidawesome01
davidawesome01OP2w ago
Will see if I have time; do we know if we can just include https://github.com/mik3y/usb-serial-for-android/tree/master as MIT code into termux or should I rewrite it? If I rewrite, can I use the MIT code (with credit) to the author in termux api? Its GPL v3 so it should be applicable
GitHub
GitHub - mik3y/usb-serial-for-android: Android USB host serial driv...
Android USB host serial driver library for CDC, FTDI, Arduino and other devices. - mik3y/usb-serial-for-android
davidawesome01
davidawesome01OP2w ago
Most dont actualy scan for the port, they just use one in /dev/ttyUSB0 or similar and in most cases thats specified on the cmdline Do you know if termux api exposes a overlay fs on the /dev folder?
ted
ted2w ago
^
davidawesome01
davidawesome01OP2w ago
can we just add a fake fifo / pty object there, or do we really need LD_PRELOAD? I mean I can write a proxy for open and read.... but is there no day?
ted
ted2w ago
it cannot you really need LD_PRELOAD, I think I don't think a fifo is expressive enough, but if you think it is, go for it "fake pty object" I don't think is a real thing you're referring to a device node there
davidawesome01
davidawesome01OP2w ago
I just mean a pty genearted by termux and as in faking it being a usbtty; sorry if I was not clear https://man7.org/linux/man-pages/man7/pty.7.html I mean socat can make one, and that works for almost any program, so I would assume that works https://unix.stackexchange.com/questions/493572/create-pty-and-connect-it-to-a-serial-port-dev-ttyusb0
Unix & Linux Stack Exchange
create pty and connect it to a serial port /dev/ttyUSB0
Problem: I have two Linux machines connected with a serial interface. I use ppp to communicate between them (I have to since it is a project requirement). Communication speed is at 9600 bits/s. ...
ted
ted2w ago
you should try that on termux don't know if it'll work, this exceeds me
davidawesome01
davidawesome01OP2w ago
Last question because I am not really in on how termux dose some stuff; is there any overlay fs in /dev/ or are they just raw android /dev? If it has a overaly fs it should be easy, if not, I need to do it in a diffrent folder, prob specified by a argument
ted
ted2w ago
there is no overlay fs in dev you need proot or other LD_PRELOAD shenanigans if you want things to see stuff in /dev/
davidawesome01
davidawesome01OP2w ago
Also, should we do this inside termuxapi, or should this just be a userprogram? beacuse it currently would work as a package requiring the usb forward function in termux api Thanks for the help btw
ted
ted2w ago
you'd have to modify something outside termux:api for this to be possible, for the reason you've been circling I'm not totally sure it's useful for this to be in :api? seems like it's implementable within the app, depending on termux-usb
davidawesome01
davidawesome01OP2w ago
You mean the /dev/? For almost all programs this is just the default place, but not required. I am kinda asking the same thing; should this be just a userspace package, I can make it easily in python based on a few projects?
ted
ted2w ago
yeah, I don't think it can be done without a termux-app-side userspace program, because :api isn't positioned to lie to programs about their vfs. and I'm not seeing why you'd bother having anything at all in :api when the part you really need (the raw USB access) is already exposed to the termux app.
davidawesome01
davidawesome01OP2w ago
Should I fully implement it there, and just put a request in at the packaging system? I have never made a project like this before, nor really worked on termux, so honestly asking
ted
ted2w ago
I would focus on a proof of concept first much easier to talk about where it might live once you've got something working
davidawesome01
davidawesome01OP2w ago
I understand; just asking how you would suggest I do this if I ever get there, also so I can deside how to implement it (language, and if its compiled or not)
ted
ted2w ago
(and faster to get something working if you're not immediately preparing for a full review / debate about where it should live) I don't think that matters
davidawesome01
davidawesome01OP2w ago
nodejs 😎
ted
ted2w ago
I guess it might be easier to get python reviews than js
davidawesome01
davidawesome01OP2w ago
Yeah looks like I may do this in python later then; it looks possiable on termuxapi with the returned fd from a api call; but most likely more versitial to do it this way
ted
ted2w ago
maybe take a look at termux-usb since it is already in the business of lying about the contents of the vfs to unmodified programs in the app
davidawesome01
davidawesome01OP2w ago
Just did; I just dont think thats how I will implement it, they seam to not actualy lie, termux dose that. Termux api just send a fd that termux can then access in that subprocess (being inherited from the upper process that calls to the termux api after termux api uses
outputSocket.setFileDescriptorsForSend(fds);
outputSocket.setFileDescriptorsForSend(fds);
in
sendFd(PrintWriter out, int fd) {
sendFd(PrintWriter out, int fd) {
)
ted
ted2w ago
I'm missing something about the implementation but I think that's the point if API is providing the raw USB access, and the lying must be done in the main app, what else would you actually want or need in :api?
davidawesome01
davidawesome01OP2w ago
Looks like pyserial plus reimplemented usb CDC parser would be fine, then just open a pty in python for that
davidawesome01
davidawesome01OP2w ago
https://github.com/ezramorris/PyVirtualSerialPorts is a good example it seams (for creating fake usb location) then just symlink from pty to specified path
GitHub
GitHub - ezramorris/PyVirtualSerialPorts: A Python implementation o...
A Python implementation of virtual serial ports for *nix - ezramorris/PyVirtualSerialPorts
ted
ted2w ago
GitHub
PyVirtualSerialPorts/virtualserialports.py at b624c5f91715ccd5b180c...
A Python implementation of virtual serial ports for *nix - ezramorris/PyVirtualSerialPorts
ted
ted2w ago
I'd check that first
ted
ted2w ago
No description
ted
ted2w ago
huh welp. cheering for your success in this

Did you find this page helpful?