这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@bndeff
Copy link
Contributor

@bndeff bndeff commented Oct 6, 2019

This patch along with its twin in termux-api-package should allow libusb to work without root.

@bndeff
Copy link
Contributor Author

bndeff commented Oct 6, 2019

(Apparently there are some issues with the CI server. Compiling succeeds and then signing the code fails. Anyway, we can build locally.)

Some instructions for usage/testing:

Install Termux & patched Termux:API from fresh.
Add some packages (libusb is currently in the root repo):
pkg install build-essential git root-repo
pkg install libusb

Install the patched termux-api package:
git clone https://github.com/bndeff/termux-api-package
cd termux-api-package
git checkout usbapi
make install
cd

Enable OTG mode, insert USB device, wait until it gets recognised.
Check the device list, it should contain one entry.
termux-usb -l

Let's assume /dev/bus/usb/001/002 is the device we see.
Ask for permission to access it:
termux-usb -r /dev/bus/usb/001/002

Now we can try to use it from libusb.
Download my demo utility:
git clone https://gist.github.com/bndeff/8c391bc3fd8d9f1dbd133ac6ead7f45e demo
cd demo
gcc usbtest.c -lusb-1.0 -o usbtest
termux-usb -e ./usbtest /dev/bus/usb/001/002

We can combine -r and -e in the same step.

@xalexalex xalexalex merged commit 10320ac into termux:master Oct 6, 2019
@Grimler91
Copy link
Member

Nice work! I feel that we should perhaps document somewhere (correct me if I've misunderstood something) that this won't make all usb-using linux-software work out of the box without patching the way they open the usb device (so that the fd is given from the command line). Maybe the help message of termux-usb could point to a wikipage, what do you think?

And just for future reference, here's the upstream PR that added support for android, with lots of discussion around it: libusb/libusb#242

@bndeff
Copy link
Contributor Author

bndeff commented Oct 6, 2019

Wow, that was quick. I didn't expect a full Google Play release in 12 hours. I see you also created a blank wiki page at https://wiki.termux.com/wiki/Termux-usb, so I've copied the info from this PR there.

@bubnikv
Copy link

bubnikv commented Sep 20, 2020

Hello @bndeff .

Thanks for your effort. I have already utilized your work with my prototype:
https://github.com/bubnikv/omnia-enet-server

However, to make your work a lot more useful, it would be great, if:

  1. The termux-usb API was able to report not only Unix path to the device file, but also the VID/PID and/or the device name, so that the application could use the information to resolve the proper USB device. I wonder whether the Android API could answer that question without having to request for USB access.
  2. Yet more useful would be, if the termux-usb API was packaged as a C library, ideally with some way of defining the USB device to open by VID/PID and/or the device name. For example, the C library could read a config file, which would host the VID/PID and device name properties. I can write 2) myself, but not 1).
  3. Even more useful would be a C library, which packed all the above plus an USB CDC driver over libusb-1.0. Again, I can likely help with that, but not with 1).

Thanks,
Vojtech

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants