Update FW Update command to new Redfish message format

The REDFISH_MESSAGE_ID requirements and format for
REDFISH_MESSAGE_ARGS have changed, so this change updates the
Redfish message to the new format and makes a couple minor fixes
for getting the instance and checking the target range.

Tested:
Ran these commands:
root@wolfpass:~# ipmitool raw 0x30 0x44 0 0x00 1 2 3 4 5 6

root@wolfpass:~# ipmitool raw 0x30 0x44 1 0x12 1 2 3 4 5 6

root@wolfpass:~# ipmitool raw 0x30 0x44 2 0x24 1 2 3 4 5 6

root@wolfpass:~# ipmitool raw 0x30 0x44 1 0x36 1 2 3 4 5 6
Unable to send RAW command (channel=0x0 netfn=0x30 lun=0x0
cmd=0x44 rsp=0xcc): Invalid data field in request

root@wolfpass:~# ipmitool raw 0x30 0x44 1 0x48 1 2 3 4 5 6

root@wolfpass:~# ipmitool raw 0x30 0x44 3 0x00 1 2 3 4 5 6
Unable to send RAW command (channel=0x0 netfn=0x30 lun=0x0
cmd=0x44 rsp=0xcc): Invalid data field in request

Confirmed that the successful commands added the expected Redfish
message.

Change-Id: I9c81cdb2b81b630c5dfd6eccea878cec14c7f076
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/src/oemcommands.cpp b/src/oemcommands.cpp
index 7cd7895..1cb8791 100644
--- a/src/oemcommands.cpp
+++ b/src/oemcommands.cpp
@@ -328,6 +328,7 @@
                                                uint32_t auxInfo)
 {
     std::string firmware;
+    int instance = (target & targetInstanceMask) >> targetInstanceShift;
     target = (target & selEvtTargetMask) >> selEvtTargetShift;
 
     /* make sure the status is 0, 1, or 2 as per the spec */
@@ -335,6 +336,11 @@
     {
         return ipmi::response(ipmi::ccInvalidFieldRequest);
     }
+    /* make sure the target is 0, 1, 2, or 4 as per the spec */
+    if (target > 4 || target == 3)
+    {
+        return ipmi::response(ipmi::ccInvalidFieldRequest);
+    }
     /*orignal OEM command is to record OEM SEL.
     But openbmc does not support OEM SEL, so we redirect it to redfish event
     logging. */
@@ -344,8 +350,7 @@
     {
         case FWUpdateTarget::targetBMC:
             firmware = "BMC";
-            buildInfo = " major: " + std::to_string(majorRevision) +
-                        " minor: " +
+            buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
                         std::to_string(bcdToDec(minorRevision)) + // BCD encoded
                         " BuildID: " + std::to_string(auxInfo);
             buildInfo += std::to_string(auxInfo);
@@ -353,7 +358,7 @@
         case FWUpdateTarget::targetBIOS:
             firmware = "BIOS";
             buildInfo =
-                " major: " +
+                "major: " +
                 std::to_string(bcdToDec(majorRevision)) + // BCD encoded
                 " minor: " +
                 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
@@ -366,7 +371,7 @@
         case FWUpdateTarget::targetME:
             firmware = "ME";
             buildInfo =
-                " major: " + std::to_string(majorRevision) + " minor1: " +
+                "major: " + std::to_string(majorRevision) + " minor1: " +
                 std::to_string(bcdToDec(minorRevision)) + // BCD encoded
                 " minor2: " +
                 std::to_string(bcdToDec(static_cast<uint8_t>(auxInfo >> 0))) +
@@ -377,37 +382,43 @@
             break;
         case FWUpdateTarget::targetOEMEWS:
             firmware = "EWS";
-            buildInfo = " major: " + std::to_string(majorRevision) +
-                        " minor: " +
+            buildInfo = "major: " + std::to_string(majorRevision) + " minor: " +
                         std::to_string(bcdToDec(minorRevision)) + // BCD encoded
                         " BuildID: " + std::to_string(auxInfo);
             break;
     }
 
+    static const std::string openBMCMessageRegistryVersion("0.1");
+    std::string redfishMsgID = "OpenBMC." + openBMCMessageRegistryVersion;
+
     switch (status)
     {
         case 0x0:
             action = "update started";
+            redfishMsgID += ".FirmwareUpdateStarted";
             break;
         case 0x1:
             action = "update completed successfully";
+            redfishMsgID += ".FirmwareUpdateCompleted";
             break;
         case 0x2:
             action = "update failure";
+            redfishMsgID += ".FirmwareUpdateFailed";
             break;
         default:
             action = "unknown";
             break;
     }
 
-    std::string message(
-        "[firmware update] " + firmware + " instance: " +
-        std::to_string((target & targetInstanceMask) >> targetInstanceShift) +
-        " status: <" + action + ">" + buildInfo);
-    static constexpr const char* redfishMsgId = "FirmwareUpdate";
+    std::string firmwareInstanceStr =
+        firmware + " instance: " + std::to_string(instance);
+    std::string message("[firmware update] " + firmwareInstanceStr +
+                        " status: <" + action + "> " + buildInfo);
 
     sd_journal_send("MESSAGE=%s", message.c_str(), "PRIORITY=%i", LOG_INFO,
-                    "REDFISH_MESSAGE_ID=%s", redfishMsgId, NULL);
+                    "REDFISH_MESSAGE_ID=%s", redfishMsgID.c_str(),
+                    "REDFISH_MESSAGE_ARGS=%s,%s", firmwareInstanceStr.c_str(),
+                    buildInfo.c_str(), NULL);
     return ipmi::responseSuccess();
 }