aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/CommandFailedException.cpp5
-rw-r--r--include/CommandFailedException.h27
-rw-r--r--include/device_proto.h2
3 files changed, 34 insertions, 0 deletions
diff --git a/include/CommandFailedException.cpp b/include/CommandFailedException.cpp
new file mode 100644
index 0000000..5ba4b0b
--- /dev/null
+++ b/include/CommandFailedException.cpp
@@ -0,0 +1,5 @@
+//
+// Created by sz on 23.07.16.
+//
+
+#include "CommandFailedException.h"
diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h
new file mode 100644
index 0000000..3306f7b
--- /dev/null
+++ b/include/CommandFailedException.h
@@ -0,0 +1,27 @@
+//
+// Created by sz on 23.07.16.
+//
+
+#ifndef LIBNITROKEY_COMMANDFAILEDEXCEPTION_H
+#define LIBNITROKEY_COMMANDFAILEDEXCEPTION_H
+
+#include <exception>
+#include <cstdint>
+
+class CommandFailedException : public std::exception {
+public:
+ uint8_t last_command_code;
+ uint8_t last_command_status;
+
+ CommandFailedException(uint8_t last_command_code, uint8_t last_command_status) :
+ last_command_code(last_command_code),
+ last_command_status(last_command_status){}
+
+ virtual const char *what() const throw() {
+ return "Command execution has failed on device";
+ }
+
+};
+
+
+#endif //LIBNITROKEY_COMMANDFAILEDEXCEPTION_H
diff --git a/include/device_proto.h b/include/device_proto.h
index 79632d9..2bbb38a 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -14,6 +14,7 @@
#include "log.h"
#include "command_id.h"
#include "dissect.h"
+#include "CommandFailedException.h"
#define STICK20_UPDATE_MODE_VID 0x03EB
#define STICK20_UPDATE_MODE_PID 0x2FF1
@@ -212,6 +213,7 @@ class Transaction : semantics::non_constructible {
Log::instance()((std::string)(resp), Loglevel::DEBUG);
if (!resp.isValid()) throw std::runtime_error("Invalid incoming packet");
+ if (resp.last_command_status!=0) throw CommandFailedException(resp.command_id, resp.last_command_status);
// See: DeviceResponse
return resp.payload;