summaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2019-01-15 16:02:31 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2019-01-15 16:02:31 +0100
commite853275784e48823be0f39f0855efbe85c0f905c (patch)
tree2b428a23bddbd87c08ee47351bc31768f54b63fe /NitrokeyManager.cc
parent3f3fdebbc795dc3805cd5be105ce994286598f16 (diff)
parentcd1cfdbfc4113186f80dbadf5eb76543b22e34bd (diff)
downloadlibnitrokey-e853275784e48823be0f39f0855efbe85c0f905c.tar.gz
libnitrokey-e853275784e48823be0f39f0855efbe85c0f905c.tar.bz2
Merge branch 'pr_138' into contributions
Improve support for multiple devices Fixes #138
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc37
1 files changed, 29 insertions, 8 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index a950e4b..99f0b7a 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -29,6 +29,7 @@
#include "libnitrokey/misc.h"
#include <mutex>
#include "libnitrokey/cxx_semantics.h"
+#include "libnitrokey/misc.h"
#include <functional>
#include <stick10_commands.h>
@@ -105,11 +106,10 @@ using nitrokey::misc::strcpyT;
return true;
}
- std::vector<std::string> NitrokeyManager::list_devices(){
+ std::vector<DeviceInfo> NitrokeyManager::list_devices(){
std::lock_guard<std::mutex> lock(mex_dev_com_manager);
- auto p = make_shared<Stick20>();
- return p->enumerate(); // make static
+ return Device::enumerate();
}
std::vector<std::string> NitrokeyManager::list_devices_by_cpuID(){
@@ -127,11 +127,13 @@ using nitrokey::misc::strcpyT;
LOGD1("Enumerating devices");
std::vector<std::string> res;
- auto d = make_shared<Stick20>();
- const auto v = d->enumerate();
+ const auto v = Device::enumerate();
LOGD1("Discovering IDs");
- for (auto & p: v){
- d = make_shared<Stick20>();
+ for (auto & i: v){
+ if (i.m_deviceModel != DeviceModel::STORAGE)
+ continue;
+ auto p = i.m_path;
+ auto d = make_shared<Stick20>();
LOGD1( std::string("Found: ") + p );
d->set_path(p);
try{
@@ -215,7 +217,26 @@ using nitrokey::misc::strcpyT;
}
}
- auto p = make_shared<Stick20>();
+ auto info_ptr = hid_enumerate(NITROKEY_VID, 0);
+ auto first_info_ptr = info_ptr;
+ if (!info_ptr)
+ return false;
+
+ misc::Option<DeviceModel> model;
+ while (info_ptr && !model.has_value()) {
+ if (path == std::string(info_ptr->path)) {
+ model = product_id_to_model(info_ptr->product_id);
+ }
+ info_ptr = info_ptr->next;
+ }
+ hid_free_enumeration(first_info_ptr);
+
+ if (!model.has_value())
+ return false;
+
+ auto p = Device::create(model.value());
+ if (!p)
+ return false;
p->set_path(path);
if(!p->connect()) return false;