process: add IPMI error return mechanism and update errors

The IPMI packet validation code must return specific IPMI errors
corresponding to what error has occurred instead of the invalid command
error.

Update all IPMI handler pieces to return more specific errors.

Change-Id: I8d21e92015d84cc0880e3b83991aed7288e19eab
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/process.cpp b/process.cpp
index 245da69..7e6410d 100644
--- a/process.cpp
+++ b/process.cpp
@@ -48,7 +48,8 @@
 };
 
 IpmiBlobHandler validateBlobCommand(CrcInterface* crc, const uint8_t* reqBuf,
-                                    uint8_t* replyCmdBuf, size_t* dataLen)
+                                    uint8_t* replyCmdBuf, size_t* dataLen,
+                                    ipmi_ret_t* code)
 {
     size_t requestLength = (*dataLen);
     /* We know dataLen is at least 1 already */
@@ -57,6 +58,7 @@
     /* Validate it's at least well-formed. */
     if (!validateRequestLength(command, requestLength))
     {
+        *code = IPMI_CC_REQ_DATA_LEN_INVALID;
         return nullptr;
     }
 
@@ -66,6 +68,7 @@
         /* Verify the request includes: command, crc16, data */
         if (requestLength < sizeof(struct BmcRx))
         {
+            *code = IPMI_CC_REQ_DATA_LEN_INVALID;
             return nullptr;
         }
 
@@ -91,6 +94,7 @@
         /* Crc expected but didn't match. */
         if (crcValue != crc->get())
         {
+            *code = IPMI_CC_UNSPECIFIED_ERROR;
             return nullptr;
         }
     }
@@ -99,6 +103,7 @@
     auto found = handlers.find(command);
     if (found == handlers.end())
     {
+        *code = IPMI_CC_INVALID_FIELD_REQUEST;
         return nullptr;
     }
 
@@ -126,7 +131,7 @@
     /* The response, if it has one byte, has three, to include the crc16. */
     if (replyLength < (sizeof(uint16_t) + 1))
     {
-        return IPMI_CC_INVALID;
+        return IPMI_CC_UNSPECIFIED_ERROR;
     }
 
     /* The command, whatever it was, replied, so let's set the CRC. */