aboutsummaryrefslogtreecommitdiff
path: root/device.cc
diff options
context:
space:
mode:
authorszszszsz <szszszsz@users.noreply.github.com>2016-10-19 17:33:30 +0200
committerGitHub <noreply@github.com>2016-10-19 17:33:30 +0200
commit82a0fc21f039971acac18df0ee57e2bb010865e1 (patch)
treef4f487257c99826a6d208fa6ea6f48b4ab7392ed /device.cc
parent10631378c61b7ce54ad6f31dc1d16c3ba4c49d32 (diff)
parente81a132c210e03b6b0a7404a8c96ebda889a5676 (diff)
downloadlibnitrokey-82a0fc21f039971acac18df0ee57e2bb010865e1.tar.gz
libnitrokey-82a0fc21f039971acac18df0ee57e2bb010865e1.tar.bz2
Merge pull request #42 from Nitrokey/13-storage_pro_cmds
Support Pro stick commands on Storage device
Diffstat (limited to 'device.cc')
-rw-r--r--device.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/device.cc b/device.cc
index 6660276..8b40984 100644
--- a/device.cc
+++ b/device.cc
@@ -13,7 +13,8 @@ using namespace nitrokey::log;
Device::Device()
: m_vid(0),
m_pid(0),
- m_retry_count(40),
+ m_retry_sending_count(3),
+ m_retry_receiving_count(40),
m_retry_timeout(100),
mp_devhandle(NULL),
last_command_status(0){}
@@ -21,14 +22,16 @@ Device::Device()
bool Device::disconnect() {
Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
- hid_exit();
+ if(mp_devhandle== nullptr) return false;
+ hid_close(mp_devhandle);
mp_devhandle = NULL;
+ hid_exit();
return true;
}
bool Device::connect() {
Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2);
- // hid_init();
+// hid_init();
mp_devhandle = hid_open(m_vid, m_pid, NULL);
// hid_init();
return mp_devhandle != NULL;
@@ -67,7 +70,7 @@ int Device::recv(void *packet) {
Loglevel::DEBUG_L2);
if (status > 0) break; // success
- if (retry_count++ >= m_retry_count) {
+ if (retry_count++ >= m_retry_receiving_count) {
Log::instance()(
"Maximum retry count reached" + std::to_string(retry_count),
Loglevel::WARNING);
@@ -86,13 +89,14 @@ Stick10::Stick10() {
m_pid = 0x4108;
m_model = DeviceModel::PRO;
m_send_receive_delay = 100ms;
- m_retry_count = 100;
+ m_retry_receiving_count = 100;
}
Stick20::Stick20() {
m_vid = 0x20a0;
m_pid = 0x4109;
- m_retry_timeout = std::chrono::milliseconds(500);
+ m_retry_timeout = 20ms;
m_model = DeviceModel::STORAGE;
- m_send_receive_delay = 1000ms;
+ m_send_receive_delay = 20ms;
+ m_retry_receiving_count = 40;
}