blob: 599b3d62b19e8927cfcd8e8892bb9e4e1ba68bb3 [file] [log] [blame]
Tom Josephe6361a22016-08-10 06:56:25 -05001#pragma once
2
Tom Josephe6361a22016-08-10 06:56:25 -05003#include "message.hpp"
4#include "message_parsers.hpp"
5#include "session.hpp"
Tom Josephf846fb32017-03-31 10:36:23 +05306#include "sol/console_buffer.hpp"
Tom Josephe6361a22016-08-10 06:56:25 -05007
Vernon Maueryd999ffc2018-10-25 09:16:05 -07008#include <memory>
Vernon Mauery9e801a22018-10-12 13:20:49 -07009
Tom Josephe6361a22016-08-10 06:56:25 -050010namespace message
11{
12
13class Handler
14{
Vernon Mauery9e801a22018-10-12 13:20:49 -070015 public:
16 explicit Handler(
17 std::shared_ptr<udpsocket::Channel> channel,
18 uint32_t sessionID = message::Message::MESSAGE_INVALID_SESSION_ID) :
19 sessionID(sessionID),
20 channel(channel)
21 {
22 }
Tom Josephe6361a22016-08-10 06:56:25 -050023
Vernon Mauery9e801a22018-10-12 13:20:49 -070024 Handler() = delete;
25 ~Handler() = default;
Vernon Mauery7f268e42018-10-26 10:26:01 -070026 Handler(const Handler&) = delete;
27 Handler& operator=(const Handler&) = delete;
28 Handler(Handler&&) = delete;
29 Handler& operator=(Handler&&) = delete;
Tom Josephe6361a22016-08-10 06:56:25 -050030
Vernon Mauery9e801a22018-10-12 13:20:49 -070031 /**
32 * @brief Receive the IPMI packet
33 *
34 * Read the data on the socket, get the parser based on the Session
35 * header type and flatten the payload and generate the IPMI message
36 *
37 * @return IPMI Message on success and nullptr on failure
38 *
39 */
Vernon Maueryd999ffc2018-10-25 09:16:05 -070040 std::shared_ptr<Message> receive();
Tom Josephe6361a22016-08-10 06:56:25 -050041
Vernon Mauery9e801a22018-10-12 13:20:49 -070042 /**
43 * @brief Process the incoming IPMI message
44 *
45 * The incoming message payload is handled and the command handler for
46 * the Network function and Command is executed and the response message
47 * is returned
48 *
49 * @param[in] inMessage - Incoming Message
50 *
51 * @return Outgoing message on success and nullptr on failure
52 */
Vernon Maueryd999ffc2018-10-25 09:16:05 -070053 std::shared_ptr<Message> executeCommand(std::shared_ptr<Message> inMessage);
Tom Josephe6361a22016-08-10 06:56:25 -050054
Vernon Mauery9e801a22018-10-12 13:20:49 -070055 /** @brief Send the outgoing message
56 *
57 * The payload in the outgoing message is flattened and sent out on the
58 * socket
59 *
60 * @param[in] outMessage - Outgoing Message
61 */
Vernon Maueryd999ffc2018-10-25 09:16:05 -070062 void send(std::shared_ptr<Message> outMessage);
Tom Josephe6361a22016-08-10 06:56:25 -050063
Vernon Mauery9e801a22018-10-12 13:20:49 -070064 /** @brief Set socket channel in session object */
65 void setChannelInSession() const;
Tom Josephff848492017-03-31 10:43:48 +053066
Vernon Mauery9e801a22018-10-12 13:20:49 -070067 /** @brief Send the SOL payload
68 *
69 * The SOL payload is flattened and sent out on the socket
70 *
71 * @param[in] input - SOL Payload
72 */
73 void sendSOLPayload(const std::vector<uint8_t>& input);
Tom Joseph22596f22017-03-31 10:52:27 +053074
Vernon Mauery9e801a22018-10-12 13:20:49 -070075 /** @brief Send the unsolicited IPMI payload to the remote console.
76 *
77 * This is used by commands like SOL activating, in which case the BMC
78 * has to notify the remote console that a SOL payload is activating
79 * on another channel.
80 *
81 * @param[in] netfn - Net function.
82 * @param[in] cmd - Command.
83 * @param[in] input - Command request data.
84 */
85 void sendUnsolicitedIPMIPayload(uint8_t netfn, uint8_t cmd,
86 const std::vector<uint8_t>& input);
Tom Joseph63d3e492017-03-31 11:01:08 +053087
Vernon Mauery9e801a22018-10-12 13:20:49 -070088 // BMC Session ID for the Channel
89 session::SessionID sessionID;
Tom Josephf846fb32017-03-31 10:36:23 +053090
Vernon Mauery9e801a22018-10-12 13:20:49 -070091 private:
92 /** @brief Socket channel for communicating with the remote client.*/
93 std::shared_ptr<udpsocket::Channel> channel;
Tom Josephe6361a22016-08-10 06:56:25 -050094
Vernon Mauery9e801a22018-10-12 13:20:49 -070095 parser::SessionHeader sessionHeader = parser::SessionHeader::IPMI20;
Tom Josephe6361a22016-08-10 06:56:25 -050096};
97
Vernon Mauery9e801a22018-10-12 13:20:49 -070098} // namespace message