aboutsummaryrefslogtreecommitdiff
path: root/libnitrokey/device.h
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 /libnitrokey/device.h
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 'libnitrokey/device.h')
-rw-r--r--libnitrokey/device.h57
1 files changed, 56 insertions, 1 deletions
diff --git a/libnitrokey/device.h b/libnitrokey/device.h
index f6d2380..d50080d 100644
--- a/libnitrokey/device.h
+++ b/libnitrokey/device.h
@@ -24,8 +24,11 @@
#include <chrono>
#include "hidapi/hidapi.h"
#include <cstdint>
+#include <memory>
#include <string>
+#include <ostream>
#include <vector>
+#include "misc.h"
#define HID_REPORT_SIZE 65
@@ -50,6 +53,48 @@ enum class DeviceModel{
STORAGE
};
+std::ostream& operator<<(std::ostream& stream, DeviceModel model);
+
+/**
+ * The USB vendor ID for Nitrokey devices.
+ */
+extern const uint16_t NITROKEY_VID;
+/**
+ * The USB product ID for the Nitrokey Pro.
+ */
+extern const uint16_t NITROKEY_PRO_PID;
+/**
+ * The USB product ID for the Nitrokey Storage.
+ */
+extern const uint16_t NITROKEY_STORAGE_PID;
+
+/**
+ * Convert the given USB product ID to a Nitrokey model. If there is no model
+ * with that ID, return an absent value.
+ */
+misc::Option<DeviceModel> product_id_to_model(uint16_t product_id);
+
+/**
+ * Information about a connected device.
+ *
+ * This struct contains the information about a connected device returned by
+ * hidapi when enumerating the connected devices.
+ */
+struct DeviceInfo {
+ /**
+ * The model of the connected device.
+ */
+ DeviceModel m_deviceModel;
+ /**
+ * The USB connection path for the device.
+ */
+ std::string m_path;
+ /**
+ * The serial number of the device.
+ */
+ std::string m_serialNumber;
+};
+
#include <atomic>
class Device {
@@ -106,7 +151,17 @@ public:
* @return true if visible by OS
*/
bool could_be_enumerated();
- std::vector<std::string> enumerate();
+ /**
+ * Returns a vector with all connected Nitrokey devices.
+ *
+ * @return information about all connected devices
+ */
+ static std::vector<DeviceInfo> enumerate();
+
+ /**
+ * Create a Device of the given model.
+ */
+ static std::shared_ptr<Device> create(DeviceModel model);
void show_stats();