diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-15 17:03:54 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2019-01-15 17:03:54 +0100 |
commit | 6bd77fce8400ecf531a4f7ff56431010b6bbb6f1 (patch) | |
tree | 2b428a23bddbd87c08ee47351bc31768f54b63fe /NitrokeyManager.cc | |
parent | 8d67c0f80aab724d67a1b6efb8af16aa71631a84 (diff) | |
parent | e853275784e48823be0f39f0855efbe85c0f905c (diff) | |
download | libnitrokey-6bd77fce8400ecf531a4f7ff56431010b6bbb6f1.tar.gz libnitrokey-6bd77fce8400ecf531a4f7ff56431010b6bbb6f1.tar.bz2 |
Merge branch 'contributions'
Multiple PR's merged and tested as a whole
Platform:
Pro v0.7
Storage v0.53
Fedora 29
Run Python tests
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r-- | NitrokeyManager.cc | 37 |
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; |