diff options
| author | Robin Krahl <me@robin-krahl.de> | 2019-01-13 12:04:12 +0100 | 
|---|---|---|
| committer | Robin Krahl <me@robin-krahl.de> | 2019-01-13 12:04:12 +0100 | 
| commit | 6c52c50d59eafa5acc7ae650695f199b7a014841 (patch) | |
| tree | e76c59dde7ddf2cba0873487901bdee4a31513df | |
| parent | d0d934e8333cffe093569b9f48a10b3500d1ff60 (diff) | |
| download | libnitrokey-6c52c50d59eafa5acc7ae650695f199b7a014841.tar.gz libnitrokey-6c52c50d59eafa5acc7ae650695f199b7a014841.tar.bz2 | |
Add product_id_to_model function
| -rw-r--r-- | device.cc | 12 | ||||
| -rw-r--r-- | libnitrokey/device.h | 7 | 
2 files changed, 19 insertions, 0 deletions
| @@ -36,12 +36,24 @@ std::mutex mex_dev_com;  using namespace nitrokey::device;  using namespace nitrokey::log; +using namespace nitrokey::misc;  using namespace std::chrono;  const uint16_t nitrokey::device::NITROKEY_VID = 0x20a0;  const uint16_t nitrokey::device::NITROKEY_PRO_PID = 0x4108;  const uint16_t nitrokey::device::NITROKEY_STORAGE_PID = 0x4109; +Option<DeviceModel> nitrokey::device::product_id_to_model(uint16_t product_id) { +  switch (product_id) { +    case NITROKEY_PRO_PID: +      return DeviceModel::PRO; +    case NITROKEY_STORAGE_PID: +      return DeviceModel::STORAGE; +    default: +      return {}; +  } +} +  std::atomic_int Device::instances_count{0};  std::chrono::milliseconds Device::default_delay {0} ; diff --git a/libnitrokey/device.h b/libnitrokey/device.h index 477640f..8fbb385 100644 --- a/libnitrokey/device.h +++ b/libnitrokey/device.h @@ -26,6 +26,7 @@  #include <cstdint>  #include <string>  #include <vector> +#include "misc.h"  #define HID_REPORT_SIZE 65 @@ -64,6 +65,12 @@ extern const uint16_t NITROKEY_PRO_PID;  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 | 
