Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device discovery in NitrokeyManager::connect_with_path #194

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions NitrokeyManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,44 +217,44 @@ using nitrokey::misc::strcpyT;
}
}

auto vendor_id = NITROKEY_VID;
auto info_ptr = hid_enumerate(vendor_id, 0);
if (!info_ptr) {
vendor_id = PURISM_VID;
info_ptr = hid_enumerate(vendor_id, 0);
}
auto first_info_ptr = info_ptr;
if (!info_ptr)
return false;
auto vendor_ids = { NITROKEY_VID, PURISM_VID };
for (auto vendor_id : vendor_ids) {
auto info_ptr = hid_enumerate(vendor_id, 0);
if (!info_ptr) {
continue;
}
auto first_info_ptr = info_ptr;

misc::Option<DeviceModel> model;
while (info_ptr && !model.has_value()) {
if (path == std::string(info_ptr->path)) {
model = product_id_to_model(info_ptr->vendor_id, info_ptr->product_id);
}
info_ptr = info_ptr->next;
}
hid_free_enumeration(first_info_ptr);

misc::Option<DeviceModel> model;
while (info_ptr && !model.has_value()) {
if (path == std::string(info_ptr->path)) {
model = product_id_to_model(info_ptr->vendor_id, info_ptr->product_id);
}
info_ptr = info_ptr->next;
}
hid_free_enumeration(first_info_ptr);
if (!model.has_value())
continue;

if (!model.has_value())
return false;
auto p = Device::create(model.value());
if (!p)
continue;
p->set_path(path);

auto p = Device::create(model.value());
if (!p)
return false;
p->set_path(path);
if(!p->connect()) continue;

if(!p->connect()) return false;
if(cache_connections){
connected_devices [path] = p;
}

if(cache_connections){
connected_devices [path] = p;
device = p; //previous device will be disconnected automatically
current_device_id = path;
nitrokey::log::Log::setPrefix(path);
LOGD1("Device successfully changed");
return true;
}

device = p; //previous device will be disconnected automatically
current_device_id = path;
nitrokey::log::Log::setPrefix(path);
LOGD1("Device successfully changed");
return true;
return false;
}

bool NitrokeyManager::connect() {
Expand Down