Add sel entry

Add sel entry for ipmi raw command

Tested:`ipmitool raw 0x0a 0x44 0x00 0x01 0x02 0x00 0x00 0x00
0x00 0x20 0x00 0x04 0x14 0x8a 0x6f 0x00 0x00 0x00` for power_button
pressed,`ipmitool sel list` can see
 1 | 01/24/21 | 02:02:06 UTC | Button #0x8a | Power Button pressed | Asserted

Signed-off-by: Lotus Xu <xuxiaohan@bytedance.com>
Change-Id: I5a6bff109e5d12707a3a74570e6b7a584c7117bf
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 0bc842c..18a42e2 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -19,11 +19,13 @@
 #include <ipmid/utils.hpp>
 #include <optional>
 #include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/log.hpp>
 #include <sdbusplus/server.hpp>
 #include <string>
 #include <variant>
 #include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Logging/SEL/error.hpp>
 
 void register_netfn_storage_functions() __attribute__((constructor));
 
@@ -35,7 +37,7 @@
 extern const IdInfoMap sensors;
 } // namespace sensor
 } // namespace ipmi
-
+extern const ipmi::sensor::InvObjectIDMap invSensors;
 extern const FruMap frus;
 constexpr uint8_t eventDataSize = 3;
 namespace
@@ -55,6 +57,9 @@
     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 using namespace phosphor::logging;
 using namespace ipmi::fru;
+using namespace xyz::openbmc_project::Logging::SEL;
+using SELCreated =
+    sdbusplus::xyz::openbmc_project::Logging::SEL::Error::Created;
 
 using SELRecordID = uint16_t;
 using SELEntry = ipmi::sel::SELEventRecordFormat;
@@ -699,13 +704,34 @@
                       uint8_t sensorNumber, uint8_t eventDir,
                       std::array<uint8_t, eventDataSize> eventData)
 {
-    // Per the IPMI spec, need to cancel the reservation when a SEL entry is
-    // added
-    cancelSELReservation();
+    std::string objpath;
+    static constexpr auto systemRecordType = 0x02;
     // Hostboot sends SEL with OEM record type 0xDE to indicate that there is
     // a maintenance procedure associated with eSEL record.
     static constexpr auto procedureType = 0xDE;
-    if (recordType == procedureType)
+    cancelSELReservation();
+    if (recordType == systemRecordType)
+    {
+
+        for (const auto& it : invSensors)
+        {
+            if (it.second.sensorID == sensorNumber)
+            {
+                objpath = it.first;
+                break;
+            }
+        }
+        auto selDataStr = ipmi::sel::toHexStr(eventData);
+
+        bool assert = (eventDir & 0x80) ? false : true;
+
+        recordID = report<SELCreated>(Created::RECORD_TYPE(recordType),
+                                      Created::GENERATOR_ID(generatorID),
+                                      Created::SENSOR_DATA(selDataStr.c_str()),
+                                      Created::EVENT_DIR(assert),
+                                      Created::SENSOR_PATH(objpath.c_str()));
+    }
+    else if (recordType == procedureType)
     {
         // In the OEM record type 0xDE, byte 11 in the SEL record indicate the
         // procedure number.