initial commit
Add initial code from phosphor-ipmi-flash/tools that was not specific to
firmware update over ipmi-blobs.
Change-Id: I360537a7392347fe989397a699f6a712bc36e62c
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/src/ipmiblob/ipmi_errors.hpp b/src/ipmiblob/ipmi_errors.hpp
new file mode 100644
index 0000000..9f1a9f9
--- /dev/null
+++ b/src/ipmiblob/ipmi_errors.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <exception>
+#include <map>
+#include <sstream>
+#include <string>
+
+namespace host_tool
+{
+
+class IpmiException : public std::exception
+{
+ public:
+ const std::map<int, std::string> commonFailures = {
+ {0xc0, "busy"},
+ {0xc1, "invalid"},
+ {0xc3, "timeout"},
+ };
+
+ explicit IpmiException(int cc)
+ {
+ std::ostringstream smessage;
+
+ auto search = commonFailures.find(cc);
+ if (search != commonFailures.end())
+ {
+ smessage << "Received IPMI_CC: " << search->second;
+ }
+ else
+ {
+ smessage << "Received IPMI_CC: " << cc;
+ }
+
+ message = smessage.str();
+ }
+ explicit IpmiException(const std::string& message) : message(message){};
+
+ virtual const char* what() const noexcept override
+ {
+ return message.c_str();
+ }
+
+ private:
+ std::string message;
+};
+
+} // namespace host_tool