tools: return data or throw exception on ipmi resp

When the IPMI_CC is non-zero, throw an exception and include the code,
otherwise if the response buffer is non-null, return the bytes received.

Change-Id: Id81281d7fd79f3075fcdd4bbf86ffdd83d8a3721
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/tools/ipmi_errors.hpp b/tools/ipmi_errors.hpp
new file mode 100644
index 0000000..fd1f032
--- /dev/null
+++ b/tools/ipmi_errors.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <exception>
+#include <sstream>
+#include <string>
+
+class IpmiException : public std::exception
+{
+  public:
+    explicit IpmiException(int cc)
+    {
+        std::ostringstream smessage;
+        smessage << "Received IPMI_CC: " << cc;
+        message = smessage.str();
+    }
+
+    virtual const char* what() const noexcept override
+    {
+        return message.c_str();
+    }
+
+  private:
+    std::string message;
+};