Add function to send unsolicited IPMI payload to remote console.
Change-Id: Ifd9c711c16a6640d36d6247a7c3b46a7db1c6596
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/message.hpp b/message.hpp
index 331c5bf..a53727a 100644
--- a/message.hpp
+++ b/message.hpp
@@ -63,6 +63,9 @@
namespace LAN
{
+constexpr uint8_t requesterBMCAddress = 0x20;
+constexpr uint8_t responderBMCAddress = 0x81;
+
namespace header
{
diff --git a/message_handler.cpp b/message_handler.cpp
index e8dbe7d..ef9eb06 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -207,5 +207,55 @@
send(outMessage);
}
+void Handler::sendUnsolicitedIPMIPayload(uint8_t netfn,
+ uint8_t cmd,
+ const std::vector<uint8_t>& output)
+{
+ Message outMessage;
+
+ auto session = (std::get<session::Manager&>(singletonPool).getSession(
+ sessionID)).lock();
+
+ outMessage.payloadType = PayloadType::IPMI;
+ outMessage.isPacketEncrypted = session->isCryptAlgoEnabled();
+ outMessage.isPacketAuthenticated = session->isIntegrityAlgoEnabled();
+ outMessage.rcSessionID = session->getRCSessionID();
+ outMessage.bmcSessionID = sessionID;
+
+ outMessage.payload.resize(sizeof(LAN::header::Request) +
+ output.size() +
+ sizeof(LAN::trailer::Request));
+
+ auto respHeader = reinterpret_cast<LAN::header::Request*>
+ (outMessage.payload.data());
+
+ // Add IPMI LAN Message Request Header
+ respHeader->rsaddr = LAN::requesterBMCAddress;
+ respHeader->netfn = (netfn << 0x02);
+ respHeader->cs = crc8bit(&(respHeader->rsaddr), 2);
+ respHeader->rqaddr = LAN::responderBMCAddress;
+ respHeader->rqseq = 0;
+ respHeader->cmd = cmd;
+
+ auto assembledSize = sizeof(LAN::header::Request);
+
+ // Copy the output by the execution of the command
+ std::copy(output.begin(),
+ output.end(),
+ outMessage.payload.begin() + assembledSize);
+ assembledSize += output.size();
+
+ // Add the IPMI LAN Message Trailer
+ auto trailer = reinterpret_cast<LAN::trailer::Request*>
+ (outMessage.payload.data() + assembledSize);
+
+ // Calculate the checksum for the field rqaddr in the header to the
+ // command data, 3 corresponds to size of the fields before rqaddr( rsaddr,
+ // netfn, cs).
+ trailer->checksum = crc8bit(&respHeader->rqaddr, assembledSize - 3);
+
+ send(outMessage);
+}
+
} //namespace message
diff --git a/message_handler.hpp b/message_handler.hpp
index 60b7a6d..0f553b7 100644
--- a/message_handler.hpp
+++ b/message_handler.hpp
@@ -73,6 +73,20 @@
*/
void sendSOLPayload(const sol::Buffer& input);
+ /** @brief Send the unsolicited IPMI payload to the remote console.
+ *
+ * This is used by commands like SOL activating, in which case the BMC
+ * has to notify the remote console that a SOL payload is activating
+ * on another channel.
+ *
+ * @param[in] netfn - Net function.
+ * @param[in] cmd - Command.
+ * @param[in] input - Command request data.
+ */
+ void sendUnsolicitedIPMIPayload(uint8_t netfn,
+ uint8_t cmd,
+ const std::vector<uint8_t>& input);
+
// BMC Session ID for the Channel
session::SessionID sessionID;