aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc7
-rw-r--r--NK_C_API.h6
-rw-r--r--NitrokeyManager.cc16
-rw-r--r--include/NitrokeyManager.h3
-rw-r--r--include/stick20_commands.h10
5 files changed, 41 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index d42840b..e513a3b 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -471,6 +471,13 @@ extern int NK_get_progress_bar_value() {
});
}
+extern int NK_get_major_firmware_version(){
+ auto m = NitrokeyManager::instance();
+ return get_with_result([&](){
+ return m->get_major_firmware_version();
+ });
+}
+
}
diff --git a/NK_C_API.h b/NK_C_API.h
index a446a62..7f01900 100644
--- a/NK_C_API.h
+++ b/NK_C_API.h
@@ -324,7 +324,11 @@ extern int NK_erase_password_safe_slot(uint8_t slot_number);
*/
extern int NK_is_AES_supported(const char *user_password);
-
+/**
+ * Get device's major firmware version
+ * @return 7,8 for Pro and major for Storage
+ */
+extern int NK_get_major_firmware_version();
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index b130f4f..da31c8d 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -4,6 +4,7 @@
#include "include/LibraryException.h"
#include <algorithm>
#include <unordered_map>
+#include <stick20_commands.h>
#include "include/misc.h"
namespace nitrokey{
@@ -589,9 +590,24 @@ namespace nitrokey{
{DeviceModel::STORAGE, 43},
});
auto status_p = GetStatus::CommandTransaction::run(*device);
+ //FIXME use different function for checking storage firmware version
return status_p.data().firmware_version <= m[device->get_device_model()];
}
+ int NitrokeyManager::get_major_firmware_version(){
+ switch(device->get_device_model()){
+ case DeviceModel::PRO:{
+ auto status_p = GetStatus::CommandTransaction::run(*device);
+ return status_p.data().firmware_version; //7 or 8
+ }
+ case DeviceModel::STORAGE:{
+ auto status = stick20::GetDeviceStatus::CommandTransaction::run(*device);
+ return status.data().versionInfo.major;
+ }
+ }
+ return 0;
+ }
+
bool NitrokeyManager::is_AES_supported(const char *user_password) {
auto a = get_payload<IsAESSupported>();
strcpyT(a.user_password, user_password);
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index 14fa1e5..fd39445 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -115,6 +115,8 @@ namespace nitrokey {
template <typename S, typename A, typename T>
void authorize_packet(T &package, const char *admin_temporary_password, shared_ptr<Device> device);
+ int get_major_firmware_version();
+
private:
NitrokeyManager();
@@ -145,6 +147,7 @@ namespace nitrokey {
uint64_t counter_or_interval,
bool use_8_digits, bool use_enter, bool use_tokenID, const char *token_ID,
const char *temporary_password) const;
+
};
}
diff --git a/include/stick20_commands.h b/include/stick20_commands.h
index 1af9da3..e6df770 100644
--- a/include/stick20_commands.h
+++ b/include/stick20_commands.h
@@ -125,7 +125,17 @@ namespace nitrokey {
uint16_t MagicNumber_StickConfig_u16;
uint8_t ReadWriteFlagUncryptedVolume_u8;
uint8_t ReadWriteFlagCryptedVolume_u8;
+
+ union{
uint8_t VersionInfo_au8[4];
+ struct {
+ uint8_t __unused;
+ uint8_t major;
+ uint8_t __unused2;
+ uint8_t minor;
+ } __packed versionInfo;
+ };
+
uint8_t ReadWriteFlagHiddenVolume_u8;
uint8_t FirmwareLocked_u8;
uint8_t NewSDCardFound_u8;