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 /libnitrokey/device.h | |
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 'libnitrokey/device.h')
-rw-r--r-- | libnitrokey/device.h | 57 |
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(); |