summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NitrokeyManager.cc10
-rw-r--r--device.cc15
-rw-r--r--libnitrokey/device.h5
-rw-r--r--unittest/test_multiple_devices.cc8
4 files changed, 21 insertions, 17 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 8ca4698..3b57ba6 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -108,8 +108,7 @@ using nitrokey::misc::strcpyT;
std::vector<DeviceInfo> NitrokeyManager::list_devices(){
std::lock_guard<std::mutex> lock(mex_dev_com_manager);
- auto p = make_shared<Stick20>();
- return p->enumerate();
+ return Device::enumerate();
}
std::vector<std::string> NitrokeyManager::list_devices_by_cpuID(){
@@ -127,12 +126,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 & i: v){
+ if (i.m_deviceModel != DeviceModel::STORAGE)
+ continue;
auto p = i.m_path;
- d = make_shared<Stick20>();
+ auto d = make_shared<Stick20>();
LOGD1( std::string("Found: ") + p );
d->set_path(p);
try{
diff --git a/device.cc b/device.cc
index d3f6e09..58dc0e5 100644
--- a/device.cc
+++ b/device.cc
@@ -188,16 +188,17 @@ int Device::recv(void *packet) {
}
std::vector<DeviceInfo> Device::enumerate(){
- //TODO make static
- auto pInfo = hid_enumerate(m_vid, m_pid);
+ auto pInfo = hid_enumerate(NITROKEY_VID, 0);
auto pInfo_ = pInfo;
std::vector<DeviceInfo> res;
while (pInfo != nullptr){
- std::string path(pInfo->path);
- std::wstring serialNumber(pInfo->serial_number);
- auto deviceModel = this->get_device_model();
- DeviceInfo info = { deviceModel, path, serialNumber };
- res.push_back(info);
+ auto deviceModel = product_id_to_model(pInfo->product_id);
+ if (deviceModel.has_value()) {
+ std::string path(pInfo->path);
+ std::wstring serialNumber(pInfo->serial_number);
+ DeviceInfo info = { deviceModel.value(), path, serialNumber };
+ res.push_back(info);
+ }
pInfo = pInfo->next;
}
diff --git a/libnitrokey/device.h b/libnitrokey/device.h
index 8fbb385..418d335 100644
--- a/libnitrokey/device.h
+++ b/libnitrokey/device.h
@@ -148,12 +148,11 @@ public:
*/
bool could_be_enumerated();
/**
- * Returns a vector with all connected Nitrokey devices of the same device
- * type as this device.
+ * Returns a vector with all connected Nitrokey devices.
*
* @return information about all connected devices
*/
- std::vector<DeviceInfo> enumerate();
+ static std::vector<DeviceInfo> enumerate();
void show_stats();
diff --git a/unittest/test_multiple_devices.cc b/unittest/test_multiple_devices.cc
index f9e9ad2..183af4f 100644
--- a/unittest/test_multiple_devices.cc
+++ b/unittest/test_multiple_devices.cc
@@ -35,9 +35,11 @@ using namespace nitrokey;
TEST_CASE("List devices", "[BASIC]") {
shared_ptr<Stick20> d = make_shared<Stick20>();
- auto v = d->enumerate();
+ auto v = Device::enumerate();
REQUIRE(v.size() > 0);
for (auto i : v){
+ if (i.m_deviceModel != DeviceModel::STORAGE)
+ continue;
auto a = i.m_path;
std::cout << a;
d->set_path(a);
@@ -54,11 +56,13 @@ TEST_CASE("List devices", "[BASIC]") {
TEST_CASE("Regenerate AES keys", "[BASIC]") {
shared_ptr<Stick20> d = make_shared<Stick20>();
- auto v = d->enumerate();
+ auto v = Device::enumerate();
REQUIRE(v.size() > 0);
std::vector<shared_ptr<Stick20>> devices;
for (auto i : v){
+ if (i.m_deviceModel != DeviceModel::STORAGE)
+ continue;
auto a = i.m_path;
std::cout << a << endl;
d = make_shared<Stick20>();