IPMI OEM BIC - Clear CMOS

Register an IPMI command handler with NetFn 0x38 Cmd 0x25
and send this command to BIC through IPMB to clear CMOS.

TESTED : Tested and verified in Facebook YosemiteV2 platform.

Signed-off-by: Jayashree Dhanapal <jayashree-d@hcl.com>
Change-Id: I5df7a637c5860ae7b0fc7e65e5737614fb3c4293
diff --git a/include/biccommands.hpp b/include/biccommands.hpp
index 1520702..44d0e76 100644
--- a/include/biccommands.hpp
+++ b/include/biccommands.hpp
@@ -6,6 +6,7 @@
     CMD_OEM_SEND_POST_BUFFER_TO_BMC = 0x8,
     CMD_OEM_SET_HOST_POWER_STATE = 0x0C,
     CMD_OEM_GET_FLASH_SIZE = 0x19,
+    CMD_OEM_CLEAR_CMOS = 0x25,
 };
 
 // Flash size response length
diff --git a/src/biccommands.cpp b/src/biccommands.cpp
index 91416ad..e0bb322 100644
--- a/src/biccommands.cpp
+++ b/src/biccommands.cpp
@@ -262,6 +262,50 @@
     return ipmi::responseSuccess(ianaResp, flashResp);
 }
 
+//----------------------------------------------------------------------
+// ipmiOemClearCmos (CMD_OEM_CLEAR_CMOS)
+// This Function will clear the CMOS.
+// netfn=0x38 and cmd=0x25
+//----------------------------------------------------------------------
+ipmi::RspType<IanaType> ipmiOemClearCmos(ipmi::Context::ptr ctx,
+                                         IanaType ianaReq)
+{
+    if (iana != ianaReq)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Invalid request of IANA ID length received");
+        return ipmi::responseReqDataLenInvalid();
+    }
+
+    uint8_t bicAddr = (uint8_t)ctx->hostIdx << 2;
+
+    std::vector<uint8_t> respData;
+    std::vector<uint8_t> reqData(ianaReq.begin(), ianaReq.end());
+
+    if (sendBicCmd(ctx->netFn, ctx->cmd, bicAddr, reqData, respData))
+    {
+        return ipmi::responseUnspecifiedError();
+    }
+
+    if (respData.size() != iana.size())
+    {
+        return ipmi::responseReqDataLenInvalid();
+    }
+
+    IanaType resp;
+    std::copy_n(respData.begin(), resp.size(), resp.begin());
+
+    if (iana != resp)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Invalid response of IANA ID received");
+        return ipmi::responseUnspecifiedError();
+    }
+
+    // sending the success response.
+    return ipmi::responseSuccess(resp);
+}
+
 [[maybe_unused]] static void registerBICFunctions(void)
 {
 
@@ -286,6 +330,9 @@
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFive,
                           static_cast<Cmd>(fb_bic_cmds::CMD_OEM_GET_FLASH_SIZE),
                           ipmi::Privilege::User, ipmiOemGetBiosFlashSize);
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnOemFive,
+                          static_cast<Cmd>(fb_bic_cmds::CMD_OEM_CLEAR_CMOS),
+                          ipmi::Privilege::User, ipmiOemClearCmos);
     return;
 }