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;
+};
diff --git a/tools/ipmi_handler.cpp b/tools/ipmi_handler.cpp
index 7a6e407..76bd3e0 100644
--- a/tools/ipmi_handler.cpp
+++ b/tools/ipmi_handler.cpp
@@ -16,7 +16,8 @@
 
 #include "ipmi_handler.hpp"
 
-int IpmiHandler::sendPacket(const std::vector<std::uint8_t>& data)
+std::vector<std::uint8_t>
+    IpmiHandler::sendPacket(const std::vector<std::uint8_t>& data)
 {
-    return 0;
+    return {};
 }
diff --git a/tools/ipmi_handler.hpp b/tools/ipmi_handler.hpp
index ea42507..9e86f42 100644
--- a/tools/ipmi_handler.hpp
+++ b/tools/ipmi_handler.hpp
@@ -7,5 +7,6 @@
   public:
     IpmiHandler() = default;
 
-    int sendPacket(const std::vector<std::uint8_t>& data) override;
+    std::vector<std::uint8_t>
+        sendPacket(const std::vector<std::uint8_t>& data) override;
 };
diff --git a/tools/ipmi_interface.hpp b/tools/ipmi_interface.hpp
index 932d2e8..082af9c 100644
--- a/tools/ipmi_interface.hpp
+++ b/tools/ipmi_interface.hpp
@@ -12,7 +12,9 @@
      * Send an IPMI packet to the BMC.
      *
      * @param[in] data - a vector of the IPMI packet contents.
-     * @return non-zero on failure.
+     * @return the bytes returned.
+     * @throws IpmiException on failure.
      */
-    virtual int sendPacket(const std::vector<std::uint8_t>& data) = 0;
+    virtual std::vector<std::uint8_t>
+        sendPacket(const std::vector<std::uint8_t>& data) = 0;
 };