intel-ipmi-oem: add clear CMOS command

There is an i2c device on bus4, the slave address is 0x70. Based on the
spec, writing 0x1 to address 0x60 on this device, will trigger the clear
CMOS action.

Tested:
Run the below command in MFG mode:
ipmitool raw 0x32 0x91

Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Change-Id: I2e549de7ab18c448e81cc8b431cf90bab8fd9dd0
diff --git a/src/manufacturingcommands.cpp b/src/manufacturingcommands.cpp
index 8b8adab..eefdc76 100644
--- a/src/manufacturingcommands.cpp
+++ b/src/manufacturingcommands.cpp
@@ -784,6 +784,26 @@
 
     return ipmi::responseSuccess(readBuf);
 }
+
+ipmi::RspType<> clearCMOS()
+{
+    // There is an i2c device on bus 4, the slave address is 0x70. Based on the
+    // spec, writing 0x1 to address 0x60 on this device, will trigger the clear
+    // CMOS action.
+    constexpr uint8_t slaveAddr = 0x70;
+    std::string i2cBus = "/dev/i2c-4";
+    std::vector<uint8_t> writeData = {0x60, 0x1};
+    std::vector<uint8_t> readBuf(0);
+
+    // TODO Needs to enhance the below security checking
+    if (mtm.getAccessLvl() < MtmLvl::mtmAvailable)
+    {
+        return ipmi::responseInsufficientPrivilege();
+    }
+
+    ipmi::Cc retI2C = ipmi::i2cWriteRead(i2cBus, slaveAddr, writeData, readBuf);
+    return ipmi::response(retI2C);
+}
 } // namespace ipmi
 
 void register_mtm_commands() __attribute__((constructor));
@@ -815,6 +835,10 @@
                           ipmi::Privilege::Admin,
                           ipmi::appSlotI2CMasterWriteRead);
 
+    ipmi::registerHandler(ipmi::prioOemBase, ipmi::intel::netFnPlatform,
+                          ipmi::intel::platform::cmdClearCMOS,
+                          ipmi::Privilege::Admin, ipmi::clearCMOS);
+
     ipmi::registerFilter(ipmi::prioOemBase,
                          [](ipmi::message::Request::ptr request) {
                              return ipmi::mfgFilterMessage(request);