diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2018-06-28 11:30:05 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2018-06-28 11:30:05 +0200 |
commit | 9601681dd9aea8a87444d36711e0a908ad4ec7d2 (patch) | |
tree | 79b6f00c541d71a2488fbe48c619e57a99605fce /NK_C_API.cc | |
parent | 5d4003a6053667ec4ef75a5b39e38cf3f305cbea (diff) | |
download | libnitrokey-9601681dd9aea8a87444d36711e0a908ad4ec7d2.tar.gz libnitrokey-9601681dd9aea8a87444d36711e0a908ad4ec7d2.tar.bz2 |
Handle command for getting production data
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r-- | NK_C_API.cc | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index 103f34d..1d9ff4f 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -631,7 +631,44 @@ extern "C" { return 0; } - NK_C_API char* NK_get_SD_usage_data_as_string() { + NK_C_API int NK_get_storage_production_info(NK_storage_ProductionTest * out){ + if (out == nullptr) { + return -1; + } + auto m = NitrokeyManager::instance(); + auto result = get_with_status([&]() { + return m->production_info(); + }, proto::stick20::ProductionTest::ResponsePayload()); + + auto error_code = std::get<0>(result); + if (error_code != 0) { + return error_code; + } + + stick20::ProductionTest::ResponsePayload status = std::get<1>(result); + // Cannot use memcpy without declaring C API struct packed + // (which is not parsed by Python's CFFI apparently), hence the manual way. +#define a(x) out->x = status.x; + a(FirmwareVersion_au8[0]); + a(FirmwareVersion_au8[1]); + a(FirmwareVersionInternal_u8); + a(SD_Card_Size_u8); + a(CPU_CardID_u32); + a(SmartCardID_u32); + a(SD_CardID_u32); + a(SC_UserPwRetryCount); + a(SC_AdminPwRetryCount); + a(SD_Card_ManufacturingYear_u8); + a(SD_Card_ManufacturingMonth_u8); + a(SD_Card_OEM_u16); + a(SD_WriteSpeed_u16); + a(SD_Card_Manufacturer_u8); +#undef a + return 0; + } + + +NK_C_API char* NK_get_SD_usage_data_as_string() { auto m = NitrokeyManager::instance(); return get_with_string_result([&]() { return m->get_SD_usage_data_as_string(); |