sensorcommands:Platform Event Message command corrected

Add support to check the incoming channel type and update the
generatorID based on requester slave address.

Add support to check for valid evmRev and Sensor Type.

Tested:
Command: ipmitool  -I lanplus -H <BMC_IP> -U root -P 0penBmc raw 0x04
0x02 0x04 0x6a 0xcd 0xf6 0x6b 0xed 0x0f
Response: Unable to send RAW command (channel=0x0 netfn=0x4 lun=0x0
cmd=0x2 rsp=0xcc): Invalid data field in request

Command: ipmitool  -I lanplus -H <BMC_IP> -U root -P 0penBmc raw 0x04
0x02 0x54 0x6a 0xcd 0xf6 0x6b 0xed 0x0f
Response: Unable to send RAW command (channel=0x0 netfn=0x4 lun=0x0
cmd=0x2 rsp=0xcc): Invalid data field in request

Ported From: https://gerrit.openbmc-project.xyz/c/openbmc/intel-ipmi-oem/+/44255

Signed-off-by: Chalapathi Venkataramashetty <chalapathix.venkataramashetty@intel.com>
Change-Id: Ibb93d09777f5a7c515d45a4aa910c657d503d9ce
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index 7cbd29f..0271c77 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -38,6 +38,7 @@
 #include <sdbusplus/bus.hpp>
 #include <stdexcept>
 #include <string>
+#include <user_channel/channel_layer.hpp>
 #include <utility>
 #include <variant>
 
@@ -506,12 +507,61 @@
 }
 } // namespace sensor
 
-ipmi::RspType<> ipmiSenPlatformEvent(uint8_t generatorID, uint8_t evmRev,
-                                     uint8_t sensorType, uint8_t sensorNum,
-                                     uint8_t eventType, uint8_t eventData1,
-                                     std::optional<uint8_t> eventData2,
-                                     std::optional<uint8_t> eventData3)
+ipmi::RspType<> ipmiSenPlatformEvent(ipmi::Context::ptr ctx,
+                                     ipmi::message::Payload& p)
 {
+    constexpr const uint8_t validEnvmRev = 0x04;
+    constexpr const uint8_t lastSensorType = 0x2C;
+    constexpr const uint8_t oemReserved = 0xC0;
+
+    uint8_t generatorID = 0;
+    uint8_t evmRev = 0;
+    uint8_t sensorType = 0;
+    uint8_t sensorNum = 0;
+    uint8_t eventType = 0;
+    uint8_t eventData1 = 0;
+    std::optional<uint8_t> eventData2 = 0;
+    std::optional<uint8_t> eventData3 = 0;
+    ipmi::ChannelInfo chInfo;
+
+    if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess)
+    {
+        phosphor::logging::log<phosphor::logging::level::ERR>(
+            "Failed to get Channel Info",
+            phosphor::logging::entry("CHANNEL=%d", ctx->channel));
+        return ipmi::responseUnspecifiedError();
+    }
+
+    if (static_cast<ipmi::EChannelMediumType>(chInfo.mediumType) ==
+        ipmi::EChannelMediumType::systemInterface)
+    {
+
+        p.unpack(generatorID, evmRev, sensorType, sensorNum, eventType,
+                 eventData1, eventData2, eventData3);
+    }
+    else
+    {
+
+        p.unpack(evmRev, sensorType, sensorNum, eventType, eventData1,
+                 eventData2, eventData3);
+        generatorID = ctx->rqSA;
+    }
+
+    if (!p.fullyUnpacked())
+    {
+        return ipmi::responseReqDataLenInvalid();
+    }
+
+    // Check for valid evmRev and Sensor Type(per Table 42 of spec)
+    if (evmRev != validEnvmRev)
+    {
+        return ipmi::responseInvalidFieldRequest();
+    }
+    if ((sensorType > lastSensorType) && (sensorType < oemReserved))
+    {
+        return ipmi::responseInvalidFieldRequest();
+    }
+
     return ipmi::responseSuccess();
 }