summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-14 13:35:13 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-10-19 16:34:11 +0200
commita8965c05ff8b69d6f0dc51e41655acf8b198869b (patch)
treea5a64c6a3d79a7b68689b99aa888cea170bafe4d /include
parentb70c1e855a25abdf4c9e25d9c5275ac9866b4e2d (diff)
downloadlibnitrokey-a8965c05ff8b69d6f0dc51e41655acf8b198869b.tar.gz
libnitrokey-a8965c05ff8b69d6f0dc51e41655acf8b198869b.tar.bz2
Handle NK Storage status sent on Storage commands
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include')
-rw-r--r--include/device_proto.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/include/device_proto.h b/include/device_proto.h
index ebe31df..6e99eaa 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -99,6 +99,13 @@ namespace nitrokey {
union {
uint8_t _padding[HID_REPORT_SIZE - 12];
ResponsePayload payload;
+ struct{
+ uint8_t _storageStatusPadding[20-8+1]; //starts on 20th byte minus already 8 used + zero byte
+ uint8_t CommandCounter_u8;
+ uint8_t LastCommand_u8;
+ uint8_t Status_u8; //general status - idle0/ok1/busy2/wrongpassword3
+ uint8_t ProgressBarValue_u8;
+ } StorageStatus __packed;
} __packed;
uint32_t crc;
@@ -224,9 +231,40 @@ namespace nitrokey {
while (retry-- > 0) {
status = dev.recv(&resp);
+ if (dev.get_device_model() == DeviceModel::STORAGE &&
+ resp.command_id >= 0x20 &&
+// resp.command_id <= 0x20 + 26
+ resp.command_id < 0x60
+ ){
+ Log::instance()(std::string("Detected storage device cmd, status: ") +
+ std::to_string(resp.StorageStatus.Status_u8), Loglevel::DEBUG_L2);
+
+ resp.last_command_status = 0;
+ switch(resp.StorageStatus.Status_u8){
+ case 0:
+ case 1:
+ resp.last_command_status = 0;
+ resp.device_status = 0;
+ break;
+ case 2:
+ resp.last_command_status = 0;
+ resp.device_status = 1; //pro busy
+ break;
+ case 3:
+ case 4:
+ resp.last_command_status = 4;
+ resp.device_status = 0;
+ break;
+ };
+ }
+
dev.set_last_command_status(resp.last_command_status); // FIXME should be handled on device.recv
if (resp.device_status == 0 && resp.last_command_crc == outp.crc) break;
+ Log::instance()(std::string("Retry status: ")
+ + std::to_string(resp.device_status) + " " +
+ std::to_string(resp.last_command_crc==outp.crc), Loglevel::DEBUG_L2);
+
Log::instance()(
"Device is not ready or received packet's last CRC is not equal to sent CRC packet, retrying...",
Loglevel::DEBUG);