device: proper handling of user input

(1) If the user denies something on the Ledger,
    a proper error message is now shown.
(2) Ledger doesn't time out anymore while waiting
    on user input.
(3) Lower the timeout to 2 seconds, this is enough for
    normal Ledger <-> System communication.
This commit is contained in:
selsta 2019-01-09 09:20:53 +01:00
parent 094b0c4d00
commit 6c060e6aaa
No known key found for this signature in database
GPG key ID: 2EA0A99A8B07AE5E
5 changed files with 43 additions and 9 deletions

View file

@ -148,7 +148,7 @@ namespace hw {
return this->usb_device != NULL;
}
int device_io_hid::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len) {
int device_io_hid::exchange(unsigned char *command, unsigned int cmd_len, unsigned char *response, unsigned int max_resp_len, bool user_input) {
unsigned char buffer[400];
unsigned char padding_buffer[MAX_BLOCK+1];
unsigned int result;
@ -177,7 +177,11 @@ namespace hw {
//get first response
memset(buffer, 0, sizeof(buffer));
hid_ret = hid_read_timeout(this->usb_device, buffer, MAX_BLOCK, this->timeout);
if (!user_input) {
hid_ret = hid_read_timeout(this->usb_device, buffer, MAX_BLOCK, this->timeout);
} else {
hid_ret = hid_read(this->usb_device, buffer, MAX_BLOCK);
}
ASSERT_X(hid_ret>=0, "Unable to read hidapi response. Error "+std::to_string(result)+": "+ safe_hid_error(this->usb_device));
result = (unsigned int)hid_ret;
io_hid_log(1, buffer, result);