-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add more usb support, addpkg python-hidapi, heimdall #24148
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
base: master
Are you sure you want to change the base?
Conversation
On Android we cannot use libusb_get_device_list and libusb_open directly. Instead we need to enumerate and open devices through the Android API. In Termux we have termux-api for handling this communication, so we can replace the libusb_.. functions with termux_usb_.. variants. WIP for now, code segfaults when it tries to open a device.
Required by electrum if one wants to access some hardware wallets.
Fix two text gui crashes.
The package is EOL, and should hence not be welcome in our repositories. It is however required by electrum (to support legacy hardware keys), and it is no longer possible to install it through pip without an extra patch, so let's make an exception and add it to our repositories. Hopefully electrum can be fixed so that this dependency is optional.
If a ledger hardware wallet is to be used with electrum, then these dependencies are needed.
Instead of libsecp256k1.so.1 or libsecp256k1.so.2. Termux's libsecp256k1 package provides the library without version suffix.
Add patches to use termux-api/termux-usb to enumerate and open devices.
|
Closes: #10437 |
|
Probably we should implement usb device discovery at libusb level. Patching all packages one by one may be hard and unnecessary. |
Yeah, that would be nicer. Rather than just patching
With separate |
|
Oh, that makes sense, thank you. |
Very good that you brought it up, I did not write a very detailed message here. Thanks! |
| +#include "UsbAPI.pb-c.h" | ||
| + | ||
| +#define BUF_SIZE 1024 | ||
| +#define TERMUX_PREFIX "/data/data/com.termux/files/usr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be replaced with @TERMUX_PREFIX@.
| +++ b/usb/proto/UsbAPI.proto | ||
| @@ -0,0 +1,57 @@ | ||
| +syntax = "proto3"; | ||
| + | ||
| +package usbapi; | ||
| + | ||
| +option java_package = "com.termux.api"; | ||
| +option java_outer_classname = "UsbAPIProto"; | ||
| + | ||
| +/* Modelled after libusb's struct libusb_endpoint_descriptor */ | ||
| +message termuxUsbEndpointDescriptor { | ||
| + int32 endpointAddress = 1; | ||
| + int32 attributes = 2; | ||
| + int32 maxPacketSize = 3; | ||
| + int32 interval = 4; | ||
| +} | ||
| + | ||
| +/* Modelled after libusb's struct libusb_interface_descriptor */ | ||
| +message termuxUsbInterfaceDescriptor { | ||
| + int32 alternateSetting = 1; | ||
| + int32 interfaceClass = 2; | ||
| + int32 interfaceSubclass = 3; | ||
| + int32 interfaceProtocol = 4; | ||
| + string interface = 5; | ||
| + repeated termuxUsbEndpointDescriptor endpoint = 6; | ||
| +} | ||
| + | ||
| +/* Modelled after libusb's struct libusb_config_descriptor */ | ||
| +message termuxUsbConfigDescriptor { | ||
| + int32 configurationValue = 1; | ||
| + int32 maxPower = 2; | ||
| + string configuration = 3; | ||
| + repeated termuxUsbInterfaceDescriptor interface = 4; | ||
| +} | ||
| + | ||
| +/* Modelled after libusb's struct libusb_device_descriptor */ | ||
| +message termuxUsbDeviceDescriptor { | ||
| + int32 configurationCount = 1; | ||
| + int32 deviceClass = 2; | ||
| + int32 deviceProtocol = 3; | ||
| + int32 deviceSubclass = 4; | ||
| + int32 productId = 5; | ||
| + int32 vendorId = 6; | ||
| + string manufacturerName = 7; | ||
| + string productName = 8; | ||
| + string serialNumber = 9; | ||
| +} | ||
| + | ||
| +/* Loosely modelled after libusb's internal struct libusb_device */ | ||
| +message termuxUsbDevice { | ||
| + int32 busNumber = 1; | ||
| + int32 portNumber = 2; | ||
| + string deviceAddress = 3; | ||
| + termuxUsbDeviceDescriptor device = 4; | ||
| +} | ||
| + | ||
| +message termuxUsb { | ||
| + repeated termuxUsbDevice device = 1; | ||
| +} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is easy to loose this with package update. Probably this file should be somehow downloaded from correct termux/termux-api git branch or at least be versioned and the version should be checked somewhere in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, maybe we should have some sort of termux-shared repo with the protobuf definitions. I think Apollo had some ideas already for the upcoming termux-api re-work. Having a version is a good idea, I'll think a bit on where/how to add it!
This PR adds patches for termux-api from termux/termux-api-package#204, and patches hidapi to make use of them, and adds a patched variant of heimdall that uses the patches.
If python-hidapi is installed, then electrum can also make use of it and termux-api to access hardware wallets (this only works in electrum if qt gui is used through github.com/termux/termux-x11 or vnc though).
More packages can and should be patched to make use of this new termux-usb library. For many packages it is as easy as replacing libusb_get_device_list with termux_usb_device_list and libusb_open with termux_usb_open+libusb_wrap_sys_device+libusb_get_device.
When termux_usb_open is run it shows a prompt in android, so it will not be possible to use termux-usb "un-attended".
To test this out one also needs the termux-api app built from the branch here: termux/termux-api#759