From 83fc45a41346d12037486214b935e392c5eceee7 Mon Sep 17 00:00:00 2001 From: cslashm Date: Thu, 28 Mar 2019 17:14:24 +0100 Subject: [PATCH] Add NanoX support --- src/device/device_io_hid.cpp | 21 ++++++++++++++++++--- src/device/device_io_hid.hpp | 3 ++- src/device/device_ledger.cpp | 7 ++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/device/device_io_hid.cpp b/src/device/device_io_hid.cpp index f07e0eaae..721bed9ca 100644 --- a/src/device/device_io_hid.cpp +++ b/src/device/device_io_hid.cpp @@ -85,7 +85,18 @@ namespace hw { void device_io_hid::connect(void *params) { hid_conn_params *p = (struct hid_conn_params*)params; - this->connect(p->vid, p->pid, p->interface_number, p->usage_page); + if (!this->connect(p->vid, p->pid, p->interface_number, p->usage_page)) { + ASSERT_X(false, "No device found"); + } + } + + void device_io_hid::connect(const std::vector &hcpV) { + for (auto p: hcpV) { + if (this->connect(p.vid, p.pid, p.interface_number, p.usage_page)) { + return; + } + } + ASSERT_X(false, "No device found"); } hid_device_info *device_io_hid::find_device(hid_device_info *devices_list, boost::optional interface_number, boost::optional usage_page) { @@ -124,14 +135,17 @@ namespace hw { return result; } - void device_io_hid::connect(unsigned int vid, unsigned int pid, boost::optional interface_number, boost::optional usage_page) { + hid_device *device_io_hid::connect(unsigned int vid, unsigned int pid, boost::optional interface_number, boost::optional usage_page) { hid_device_info *hwdev_info_list; hid_device *hwdev; this->disconnect(); hwdev_info_list = hid_enumerate(vid, pid); - ASSERT_X(hwdev_info_list, "Unable to enumerate device "+std::to_string(vid)+":"+std::to_string(vid)+ ": "+ safe_hid_error(this->usb_device)); + if (!hwdev_info_list) { + MDEBUG("Unable to enumerate device "+std::to_string(vid)+":"+std::to_string(vid)+ ": "+ safe_hid_error(this->usb_device)); + return NULL; + } hwdev = NULL; if (hid_device_info *device = find_device(hwdev_info_list, interface_number, usage_page)) { hwdev = hid_open_path(device->path); @@ -141,6 +155,7 @@ namespace hw { this->usb_vid = vid; this->usb_pid = pid; this->usb_device = hwdev; + return hwdev; } diff --git a/src/device/device_io_hid.hpp b/src/device/device_io_hid.hpp index ed22058d6..96cb8d993 100644 --- a/src/device/device_io_hid.hpp +++ b/src/device/device_io_hid.hpp @@ -98,7 +98,8 @@ namespace hw { void init(); void connect(void *params); - void connect(unsigned int vid, unsigned int pid, boost::optional interface_number, boost::optional usage_page); + void connect(const std::vector &conn); + hid_device *connect(unsigned int vid, unsigned int pid, boost::optional interface_number, boost::optional usage_page); bool connected() const; int exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input); void disconnect(); diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index d6033e189..200370564 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -389,10 +389,15 @@ namespace hw { MDEBUG( "Device "<id <<" HIDUSB inited"); return true; } + + static const std::vector known_devices { + {0x2c97, 0x0001, 0, 0xffa0}, + {0x2c97, 0x0004, 0, 0xffa0}, + }; bool device_ledger::connect(void) { this->disconnect(); - hw_device.connect(0x2c97, 0x0001, 0, 0xffa0); + hw_device.connect(known_devices); this->reset(); #ifdef DEBUG_HWDEVICE cryptonote::account_public_address pubkey;