Only allow IPMI1.5 for non-session requests

Some IPMI messages must be sent out-of-session in order to set up the
session. In order to be counted as out-of-session, they must use the
0x00000000 session ID. And the only IPMI1.5 packets that are allowed in
OpenBMC are the out-of-session messages used to initiate the RMCP+
sessions. This commit enforces that all messages that contain a non-zero
session ID must be a part of a valid session, which means they must be
RMCP2.0 messages because RMCP1.5 sessions are not supported.

Tested: 1) establish a session; send an RMCP1.5 message with that same
           session ID and see that it gets rejected.
        2) establish a session; send an RMCP2.0 message with a 0 session
           ID and see that it gets rejected.

Change-Id: I01e33f1d8ea9b9c6972238eaaf1b032493f46953
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/command_table.cpp b/command_table.cpp
index 3dc531a..6779d55 100644
--- a/command_table.cpp
+++ b/command_table.cpp
@@ -52,6 +52,16 @@
     {
         CommandID command(inCommand);
 
+        // Do not forward any session zero commands to ipmid
+        if (handler->sessionID == session::sessionZero)
+        {
+            log<level::INFO>("Table: refuse to forward session-zero command",
+                             entry("LUN=%x", command.lun()),
+                             entry("NETFN=%x", command.netFn()),
+                             entry("CMD=%x", command.cmd()));
+            return;
+        }
+
         auto bus = getSdBus();
         // forward the request onto the main ipmi queue
         using IpmiDbusRspType = std::tuple<uint8_t, uint8_t, uint8_t, uint8_t,
diff --git a/message_parsers.cpp b/message_parsers.cpp
index b3d8dbd..7b8d832 100644
--- a/message_parsers.cpp
+++ b/message_parsers.cpp
@@ -100,12 +100,18 @@
         throw std::runtime_error("IPMI1.5 Session Header Missing");
     }
 
-    auto message = std::make_shared<Message>();
-
     auto header = reinterpret_cast<SessionHeader_t*>(inPacket.data());
 
+    uint32_t sessionID = endian::from_ipmi(header->sessId);
+    if (sessionID != session::sessionZero)
+    {
+        throw std::runtime_error("IPMI1.5 session packets are unsupported");
+    }
+
+    auto message = std::make_shared<Message>();
+
     message->payloadType = PayloadType::IPMI;
-    message->bmcSessionID = endian::from_ipmi(header->sessId);
+    message->bmcSessionID = session::sessionZero;
     message->sessionSeqNum = endian::from_ipmi(header->sessSeqNum);
     message->isPacketEncrypted = false;
     message->isPacketAuthenticated = false;