netipmid: consolidate message-related things in message.hpp

The message::Handler class was directly manipulating a bunch of stuff
on behalf of the message::Message class. This change moves more of the
changes into the message::Message class so it can manage its own data.

Change-Id: I5d31f6c3c5760207408238d048853e36a60c73e0
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/message_handler.cpp b/message_handler.cpp
index e98955b..58630d9 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -47,49 +47,11 @@
     return message;
 }
 
-template <>
-std::shared_ptr<Message> Handler::createResponse<PayloadType::IPMI>(
-    std::vector<uint8_t>& output, std::shared_ptr<Message> inMessage)
-{
-    auto outMessage = std::make_shared<Message>();
-    outMessage->payloadType = PayloadType::IPMI;
-
-    outMessage->payload.resize(sizeof(LAN::header::Response) + output.size() +
-                               sizeof(LAN::trailer::Response));
-
-    auto reqHeader =
-        reinterpret_cast<LAN::header::Request*>(inMessage->payload.data());
-    auto respHeader =
-        reinterpret_cast<LAN::header::Response*>(outMessage->payload.data());
-
-    // Add IPMI LAN Message Response Header
-    respHeader->rqaddr = reqHeader->rqaddr;
-    respHeader->netfn = reqHeader->netfn | 0x04;
-    respHeader->cs = crc8bit(&(respHeader->rqaddr), 2);
-    respHeader->rsaddr = reqHeader->rsaddr;
-    respHeader->rqseq = reqHeader->rqseq;
-    respHeader->cmd = reqHeader->cmd;
-
-    auto assembledSize = sizeof(LAN::header::Response);
-
-    // 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::Response*>(
-        outMessage->payload.data() + assembledSize);
-    trailer->checksum = crc8bit(&respHeader->rsaddr, assembledSize - 3);
-
-    return outMessage;
-}
-
 std::shared_ptr<Message>
     Handler::executeCommand(std::shared_ptr<Message> inMessage)
 {
     // Get the CommandID to map into the command table
-    auto command = getCommand(inMessage);
+    auto command = inMessage->getCommand();
     std::vector<uint8_t> output{};
 
     if (inMessage->payloadType == PayloadType::IPMI)
@@ -112,56 +74,7 @@
         output = std::get<command::Table&>(singletonPool)
                      .executeCommand(command, inMessage->payload, *this);
     }
-
-    std::shared_ptr<Message> outMessage = nullptr;
-
-    switch (inMessage->payloadType)
-    {
-        case PayloadType::IPMI:
-            outMessage = createResponse<PayloadType::IPMI>(output, inMessage);
-            break;
-        case PayloadType::OPEN_SESSION_REQUEST:
-            outMessage = createResponse<PayloadType::OPEN_SESSION_RESPONSE>(
-                output, inMessage);
-            break;
-        case PayloadType::RAKP1:
-            outMessage = createResponse<PayloadType::RAKP2>(output, inMessage);
-            break;
-        case PayloadType::RAKP3:
-            outMessage = createResponse<PayloadType::RAKP4>(output, inMessage);
-            break;
-        case PayloadType::SOL:
-            return outMessage;
-            break;
-        default:
-            break;
-    }
-
-    outMessage->isPacketEncrypted = inMessage->isPacketEncrypted;
-    outMessage->isPacketAuthenticated = inMessage->isPacketAuthenticated;
-    outMessage->rcSessionID = inMessage->rcSessionID;
-    outMessage->bmcSessionID = inMessage->bmcSessionID;
-
-    return outMessage;
-}
-
-uint32_t Handler::getCommand(std::shared_ptr<Message> message)
-{
-    uint32_t command = 0;
-
-    command |= (static_cast<uint8_t>(message->payloadType) << 16);
-    if (message->payloadType == PayloadType::IPMI)
-    {
-        command |=
-            ((reinterpret_cast<LAN::header::Request*>(message->payload.data()))
-                 ->netfn)
-            << 8;
-        command |=
-            (reinterpret_cast<LAN::header::Request*>(message->payload.data()))
-                ->cmd;
-    }
-
-    return command;
+    return inMessage->createResponse(output);
 }
 
 void Handler::send(std::shared_ptr<Message> outMessage)