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.
60 Replies
Cuteness
Cuteness5mo 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
davidawesome01OP5mo 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
Cuteness5mo ago
It depends on if your device's ROM supports it or not.
davidawesome01
davidawesome01OP5mo 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
Cuteness5mo 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
davidawesome01OP5mo 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
davidawesome01OP5mo 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
Cuteness5mo ago
First question: Are you actually using a physical Android phone / tablet, or are you using a Chromebook / etc.?
davidawesome01
davidawesome01OP5mo ago
Android phone Github apk Android 13
ted
ted5mo 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
twaik5mo 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
davidawesome01OP5mo ago
I was thinking of just doing that lol, seams not tooo bad. I was hoping this existed hense the question.
ted
ted5mo 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
twaik5mo ago
Probably I could implement something similar, but I do not have any usb serial devices for tests.
davidawesome01
davidawesome01OP5mo 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
davidawesome01OP5mo 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
davidawesome01OP5mo 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
davidawesome01OP5mo 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
ted5mo ago
do you see how this specifically lists the hardware it supports
davidawesome01
davidawesome01OP5mo 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
ted5mo ago
USB is standardized; I don't think the way you implement a serial adapter over USB is
davidawesome01
davidawesome01OP5mo ago
That is extra things like control flow that are not in the CDCAMC spec
ted
ted5mo ago
sure that's the point
davidawesome01
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
davidawesome01OP5mo 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
ted5mo ago
^
davidawesome01
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
ted5mo ago
you should try that on termux don't know if it'll work, this exceeds me
davidawesome01
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo ago
nodejs 😎
ted
ted5mo ago
I guess it might be easier to get python reviews than js
davidawesome01
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo 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
ted5mo 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
davidawesome01OP5mo ago
Looks like pyserial plus reimplemented usb CDC parser would be fine, then just open a pty in python for that
davidawesome01
davidawesome01OP5mo 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
ted5mo ago
GitHub
PyVirtualSerialPorts/virtualserialports.py at b624c5f91715ccd5b180c...
A Python implementation of virtual serial ports for *nix - ezramorris/PyVirtualSerialPorts
ted
ted5mo ago
I'd check that first
ted
ted5mo ago
No description
ted
ted5mo ago
huh welp. cheering for your success in this
davidawesome01
davidawesome01OP4mo ago
Update! Finished AP's, still got finals soon, but im done now Lookin into it, I prob need to write this in c, libusb and the direct usb file descriptor seam to like being used directly, most wrapers for other langs abstract away the low level function it needs to not do scanning, and take the fd. it seams not too hard, just gonna put some stuff here for my notes if anyone wants to take it too: https://wiki.termux.com/wiki/Termux-usb https://man7.org/linux/man-pages/man3/openpty.3.html https://man7.org/linux/man-pages/man2/ioctl_tty.2.html -- need to figure this out, because these devices can take data at diffrent speeds, how can I find what speed the terminal reader is requesting? I think I can just get the CBAUD as discussed shortly here https://man7.org/linux/man-pages/man2/TCGETS.2const.html -- oh god https://stackoverflow.com/questions/4968529/how-can-i-set-the-baud-rate-to-307-200-on-linux -- may only support normal bauds then lol mby https://libusb.readthedocs.io/en/latest/#libusb can be used, but its a lot smaller of a project, and is just a ctypes wraper for libusb Posting an image from prob lying google AI bs
No description
No description
davidawesome01
davidawesome01OP4mo ago
looks like we have to use ioctl, because termios only supports some baud rates???? linux is strage lol I may have to support both, because I dont know if they convert properly, I think they do, but not sure lol
Cuteness
Cuteness4mo ago
Don't trust AI-generated code. Often times it will contain unnecessary code, or even malicious code. Also, since when did C/C++ allow code to execute outside of a function?
davidawesome01
davidawesome01OP4mo ago
Its not, its a separate idea its just writing out Oh yeah I know, I hate it, just was including that because the documentation for usb is long af
Cuteness
Cuteness4mo ago
AI might help but it is up to the user of the AI to verify everything that the AI generated is correct. (also it is the developer's responsibility to state what was used for AI, be it code or art / audio assets)

Did you find this page helpful?