Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 1 | #include "sol_cmds.hpp" |
| 2 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 3 | #include "sessions_manager.hpp" |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 4 | #include "sol/sol_context.hpp" |
| 5 | #include "sol/sol_manager.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 6 | |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 8 | |
| 9 | namespace sol |
| 10 | { |
| 11 | |
| 12 | namespace command |
| 13 | { |
| 14 | |
| 15 | using namespace phosphor::logging; |
| 16 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 17 | std::vector<uint8_t> payloadHandler(const std::vector<uint8_t>& inPayload, |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 18 | std::shared_ptr<message::Handler>& handler) |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 19 | { |
Zhikui Ren | 2b1edef | 2020-07-24 14:32:13 -0700 | [diff] [blame] | 20 | // Check inPayload size is at least Payload |
| 21 | if (inPayload.size() < sizeof(Payload)) |
| 22 | { |
| 23 | return std::vector<uint8_t>(); |
| 24 | } |
| 25 | |
Tom Joseph | 18a45e9 | 2017-04-11 11:30:44 +0530 | [diff] [blame] | 26 | auto request = reinterpret_cast<const Payload*>(inPayload.data()); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 27 | auto solDataSize = inPayload.size() - sizeof(Payload); |
| 28 | |
Vernon Mauery | 70fd29c | 2017-11-30 13:11:43 -0800 | [diff] [blame] | 29 | std::vector<uint8_t> charData(solDataSize); |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 30 | if (solDataSize > 0) |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 31 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 32 | std::copy_n(inPayload.data() + sizeof(Payload), solDataSize, |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 33 | charData.begin()); |
| 34 | } |
| 35 | |
| 36 | try |
| 37 | { |
Vernon Mauery | 41ff9b5 | 2021-06-11 11:37:40 -0700 | [diff] [blame] | 38 | auto& context = sol::Manager::get().getContext(handler->sessionID); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 39 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 40 | context.processInboundPayload( |
| 41 | request->packetSeqNum, request->packetAckSeqNum, |
Tingting Chen | ec43741 | 2022-09-27 18:35:22 +0800 | [diff] [blame] | 42 | request->acceptedCharCount, request->inOperation.ack, |
| 43 | request->inOperation.generateBreak, charData); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 44 | } |
Patrick Williams | 12d199b | 2021-10-06 12:36:48 -0500 | [diff] [blame] | 45 | catch (const std::exception& e) |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 46 | { |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 47 | lg2::error("Failed to call the getContext method: {ERROR}", "ERROR", e); |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 48 | return std::vector<uint8_t>(); |
| 49 | } |
| 50 | |
| 51 | return std::vector<uint8_t>(); |
| 52 | } |
| 53 | |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 54 | void activating(uint8_t payloadInstance, uint32_t sessionID) |
| 55 | { |
| 56 | std::vector<uint8_t> outPayload(sizeof(ActivatingRequest)); |
| 57 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 58 | auto request = reinterpret_cast<ActivatingRequest*>(outPayload.data()); |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 59 | |
| 60 | request->sessionState = 0; |
| 61 | request->payloadInstance = payloadInstance; |
| 62 | request->majorVersion = MAJOR_VERSION; |
| 63 | request->minorVersion = MINOR_VERSION; |
| 64 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 65 | auto session = session::Manager::get().getSession(sessionID); |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 66 | |
| 67 | message::Handler msgHandler(session->channelPtr, sessionID); |
| 68 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 69 | msgHandler.sendUnsolicitedIPMIPayload(netfnTransport, solActivatingCmd, |
Tom Joseph | e14ac96 | 2017-04-03 01:56:04 +0530 | [diff] [blame] | 70 | outPayload); |
| 71 | } |
Tom Joseph | 64b3dec | 2017-04-03 01:53:44 +0530 | [diff] [blame] | 72 | } // namespace command |
| 73 | |
| 74 | } // namespace sol |