Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 3 | #include "message.hpp" |
| 4 | #include "message_parsers.hpp" |
| 5 | #include "session.hpp" |
Tom Joseph | f846fb3 | 2017-03-31 10:36:23 +0530 | [diff] [blame] | 6 | #include "sol/console_buffer.hpp" |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 7 | |
Vernon Mauery | d999ffc | 2018-10-25 09:16:05 -0700 | [diff] [blame] | 8 | #include <memory> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 9 | |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 10 | namespace message |
| 11 | { |
| 12 | |
| 13 | class Handler |
| 14 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 15 | 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 Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 23 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 24 | Handler() = delete; |
| 25 | ~Handler() = default; |
Vernon Mauery | 7f268e4 | 2018-10-26 10:26:01 -0700 | [diff] [blame] | 26 | Handler(const Handler&) = delete; |
| 27 | Handler& operator=(const Handler&) = delete; |
| 28 | Handler(Handler&&) = delete; |
| 29 | Handler& operator=(Handler&&) = delete; |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 30 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 31 | /** |
| 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 Mauery | d999ffc | 2018-10-25 09:16:05 -0700 | [diff] [blame] | 40 | std::shared_ptr<Message> receive(); |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 41 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 42 | /** |
| 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 Mauery | d999ffc | 2018-10-25 09:16:05 -0700 | [diff] [blame] | 53 | std::shared_ptr<Message> executeCommand(std::shared_ptr<Message> inMessage); |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 54 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 55 | /** @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 Mauery | d999ffc | 2018-10-25 09:16:05 -0700 | [diff] [blame] | 62 | void send(std::shared_ptr<Message> outMessage); |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 63 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 64 | /** @brief Set socket channel in session object */ |
| 65 | void setChannelInSession() const; |
Tom Joseph | ff84849 | 2017-03-31 10:43:48 +0530 | [diff] [blame] | 66 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 67 | /** @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 Joseph | 22596f2 | 2017-03-31 10:52:27 +0530 | [diff] [blame] | 74 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 75 | /** @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 Joseph | 63d3e49 | 2017-03-31 11:01:08 +0530 | [diff] [blame] | 87 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 88 | // BMC Session ID for the Channel |
| 89 | session::SessionID sessionID; |
Tom Joseph | f846fb3 | 2017-03-31 10:36:23 +0530 | [diff] [blame] | 90 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 91 | private: |
| 92 | /** @brief Socket channel for communicating with the remote client.*/ |
| 93 | std::shared_ptr<udpsocket::Channel> channel; |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 94 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 95 | parser::SessionHeader sessionHeader = parser::SessionHeader::IPMI20; |
Tom Joseph | e6361a2 | 2016-08-10 06:56:25 -0500 | [diff] [blame] | 96 | }; |
| 97 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 98 | } // namespace message |