Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add termux-api support to libusb #5831

Open
normanr opened this issue Sep 20, 2020 · 7 comments
Open

Add termux-api support to libusb #5831

normanr opened this issue Sep 20, 2020 · 7 comments
Labels
enhancement inactive No activity in a certiain period of time.

Comments

@normanr
Copy link

normanr commented Sep 20, 2020

It should be possible to use existing apps that use libusb without requiring them to individually support termux-usb.

Places where this has come up recently:

My proposal would be to enhance libusb so that (on non-rooted devices) it can use termux-api to enumerate and connect to usb devices. It would then be transparent to apps how they end up getting access to the usb devices that they use.

@normanr
Copy link
Author

normanr commented Sep 20, 2020

Aa part of pyusb/pyusb#287 I had the idea that the usb library can open the device by executing termux-usb and exec'ing a small helper that passes the device fd back to the original app (via a unix pipe similar to how termux-api sends the fd back to termux). I wrote https://gist.github.com/normanr/9816a5db24dda0ce87a17da342a9684c as a proof of concept and it works very well.

A couple of small changes to termux-api would make this smoother:

  • add a verbose list mode that also returns the usb descriptors (would avoid having to open every usb device when the app is only interested in a subset),
  • add an option to return the device fd via another unix socket instead of launching the callback (would save invoking the callback just to send the fd to another unix socket).
    Neither of these are required, they would just reduce the number of "moving parts".

@Grimler91
Copy link
Member

Hi, this would be a great improvement and we would be very happy to merge such a PR!

@stale
Copy link

stale bot commented Nov 18, 2021

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix Issue won't be fixed. label Nov 18, 2021
@stale stale bot closed this as completed Dec 2, 2021
@Grimler91 Grimler91 reopened this Dec 2, 2021
@stale stale bot removed the wontfix Issue won't be fixed. label Dec 2, 2021
@xtkoba xtkoba removed the not stale label Dec 24, 2022
@stale stale bot added the inactive No activity in a certiain period of time. label Mar 9, 2023
@twaik
Copy link
Member

twaik commented Dec 22, 2023

I think we may patch libusb to use termux-api for enumerating devices and getting device fds. I think it may be done by implementing some pretty dumb binary which will be invoked by termux-usb binary in order to get answers and file descriptors through some temporary unix socket (maybe passed as non-closeable on exec to target process).

@stale stale bot removed the inactive No activity in a certiain period of time. label Dec 22, 2023
@Grimler91
Copy link
Member

@twaik I did some proof-of-concept stuff in usb branch of termux-api{,-package} were programs could link to libtermux-api.so and get file descriptors through two functions termux_usb_get_fd_from_usbfs and termux_usb_get_fd_from_ids. As a more proper solution I then started looking into implementing a proper termux backend to libusb (where libusb would then communicate with termux-api to get info for filling in libusb_device_descriptor structs), but didn't get very far.

Having some simple functions as in the first attempt at an implementation would probably be useful, I should try to clean that up.. Maybe during the upcoming holidays

@knyipab
Copy link

knyipab commented Jan 11, 2024

See if this may help: there is a project called AnotherTerm similar to Termux and they implement a patched version libusb with helper service in the app: https://green-green-avk.github.io/AnotherTerm-docs/installing-libusb-for-nonrooted-android.html#main_content

I do not have much knowledge in this field but really glad to see progress of libusb in Termux. Look forward to being able to run Arduino IDE and PlatformIO one day in Termux (perhaps with proot-distro) and we can burn a program into microcontrollers!

@twaik
Copy link
Member

twaik commented Jan 11, 2024

See if this may help: there is a project called AnotherTerm similar to Termux and they implement a patched version libusb with helper service in the app: https://green-green-avk.github.io/AnotherTerm-docs/installing-libusb-for-nonrooted-android.html#main_content

I do not have much knowledge in this field but really glad to see progress of libusb in Termux. Look forward to run Arduino IDE and PlatformIO one day in Termux (perhaps with proot-distro) and we can burn a program into microcontrollers!

green-green-avk implemented the same thing as @Grimler91 did. Libusb simply interacts with some socket owned by Android Activity.

@stale stale bot added the inactive No activity in a certiain period of time. label Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement inactive No activity in a certiain period of time.
Projects
None yet
Development

No branches or pull requests

5 participants