aboutsummaryrefslogtreecommitdiff
path: root/include/device_proto.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-06 19:51:16 +0100
committerSzczepan Zalega <szczepan.zalega@gmail.com>2016-03-06 19:51:16 +0100
commitf66b89b493fd282d4170617f85c29c47fca75cf4 (patch)
tree3aa49a562bcd7a81d6dca3340ffe5ae9d845b430 /include/device_proto.h
parent85506009d3323e977b6de63b9b9c31760a2200fc (diff)
downloadlibnitrokey-f66b89b493fd282d4170617f85c29c47fca75cf4.tar.gz
libnitrokey-f66b89b493fd282d4170617f85c29c47fca75cf4.tar.bz2
Checking device status after completion of get_feature report and retrying receiving if device status!=0, added FIXME notes of further work
Diffstat (limited to 'include/device_proto.h')
-rw-r--r--include/device_proto.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/include/device_proto.h b/include/device_proto.h
index 142b45b..f2ed84d 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -1,6 +1,7 @@
#ifndef DEVICE_PROTO_H
#define DEVICE_PROTO_H
#include <utility>
+#include <thread>
#include <type_traits>
#include <stdexcept>
#include <string>
@@ -179,7 +180,18 @@ class Transaction : semantics::non_constructible {
std::string("Device error while sending command ") +
std::to_string((int)(status)));
- status = dev.recv(&resp);
+ // FIXME make checks done in device:recv here
+ int retry = dev.get_retry_count();
+ while (retry-- > 0) {
+ status = dev.recv(&resp);
+ if (resp.device_status == 0) break;
+ Log::instance()("Device status is not ready (CRC error?) retrying..",
+ Loglevel::DEBUG); // FIXME translate device_status to log
+ Log::instance()("Invalid incoming HID packet:", Loglevel::DEBUG_L2);
+ Log::instance()((std::string)(resp), Loglevel::DEBUG_L2);
+ std::this_thread::sleep_for(dev.get_retry_timeout());
+ continue;
+ }
if ((int)(status) < 0 && status != CommError::ERR_NO_ERROR)
throw std::runtime_error(
std::string("Device error while executing command ") +