diff options
-rw-r--r-- | NK_C_API.cc | 2 | ||||
-rw-r--r-- | NitrokeyManager.cc | 22 | ||||
-rw-r--r-- | include/NitrokeyManager.h | 11 | ||||
-rw-r--r-- | include/stick20_commands.h | 9 |
4 files changed, 36 insertions, 8 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index e513a3b..224a3a8 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -168,7 +168,7 @@ void clear_string(std::string &s){ extern const char * NK_status() { auto m = NitrokeyManager::instance(); return get_with_string_result([&](){ - string && s = m->get_status(); + string && s = m->get_status_as_string(); char * rs = strdup(s.c_str()); clear_string(s); return rs; diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index c49a449..f71c362 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -90,7 +90,7 @@ namespace nitrokey{ } bool NitrokeyManager::disconnect() { - if (device == nullptr){ + if (!is_connected()){ return false; } const auto res = device->disconnect(); @@ -98,6 +98,10 @@ namespace nitrokey{ return res; } + bool NitrokeyManager::is_connected(){ + return device != nullptr; + } + void NitrokeyManager::set_debug(bool state) { if (state){ Log::instance().set_loglevel(Loglevel::DEBUG); @@ -111,7 +115,12 @@ namespace nitrokey{ return response.data().get_card_serial_hex(); } - string NitrokeyManager::get_status() { + stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){ + auto response = GetStatus::CommandTransaction::run(*device); + return response.data(); + } + + string NitrokeyManager::get_status_as_string() { auto response = GetStatus::CommandTransaction::run(*device); return response.data().dissect(); } @@ -597,6 +606,10 @@ namespace nitrokey{ return get_major_firmware_version() <= m[device->get_device_model()]; } + DeviceModel NitrokeyManager::get_connected_device_model(){ + return device->get_device_model(); + } + int NitrokeyManager::get_major_firmware_version(){ switch(device->get_device_model()){ case DeviceModel::PRO:{ @@ -682,6 +695,11 @@ namespace nitrokey{ return strdup(p.data().dissect().c_str()); } + stick20::DeviceConfigurationResponsePacket::ResponsePayload NitrokeyManager::get_status_storage(){ + auto p = stick20::GetDeviceStatus::CommandTransaction::run(*device); + return p.data(); + } + const char * NitrokeyManager::get_SD_usage_data_as_string(){ auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(*device); return strdup(p.data().dissect().c_str()); diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index fd39445..d6b70a4 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -39,8 +39,11 @@ namespace nitrokey { bool connect(const char *device_model); bool connect(); bool disconnect(); - void set_debug(bool state); - string get_status(); + bool is_connected(); + DeviceModel get_connected_device_model(); + void set_debug(bool state); + stick10::GetStatus::ResponsePayload get_status(); + string get_status_as_string(); string get_serial_number(); const char * get_totp_slot_name(uint8_t slot_number); @@ -105,6 +108,7 @@ namespace nitrokey { void send_startup(uint64_t seconds_from_epoch); const char * get_status_storage_as_string(); + stick20::DeviceConfigurationResponsePacket::ResponsePayload get_status_storage(); const char *get_SD_usage_data_as_string(); @@ -117,11 +121,10 @@ namespace nitrokey { void authorize_packet(T &package, const char *admin_temporary_password, shared_ptr<Device> device); int get_major_firmware_version(); + explicit NitrokeyManager(); private: - NitrokeyManager(); static shared_ptr <NitrokeyManager> _instance; - bool connected; std::shared_ptr<Device> device; bool is_valid_hotp_slot_number(uint8_t slot_number) const; diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 386cbda..8080117 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -141,7 +141,14 @@ namespace nitrokey { uint8_t NewSDCardFound_u8; uint8_t SDFillWithRandomChars_u8; uint32_t ActiveSD_CardID_u32; - uint8_t VolumeActiceFlag_u8; + union{ + uint8_t VolumeActiceFlag_u8; + struct { + bool unencrypted :1; + bool encrypted :1; + bool hidden :1; + } __packed VolumeActiceFlag_st; + } __packed; uint8_t NewSmartCardFound_u8; uint8_t UserPwRetryCount; uint8_t AdminPwRetryCount; |