blob: 8203a6ef17972c66da51750dc4e1628c7ca90563 [file] [log] [blame]
Vernon Mauery9e801a22018-10-12 13:20:49 -07001#include "sol_cmds.hpp"
2
Vernon Mauery2085ae02021-06-10 11:51:00 -07003#include "sessions_manager.hpp"
Tom Joseph64b3dec2017-04-03 01:53:44 +05304#include "sol/sol_context.hpp"
5#include "sol/sol_manager.hpp"
Vernon Mauery9e801a22018-10-12 13:20:49 -07006
7#include <phosphor-logging/log.hpp>
Tom Joseph64b3dec2017-04-03 01:53:44 +05308
9namespace sol
10{
11
12namespace command
13{
14
15using namespace phosphor::logging;
16
Tom Joseph18a45e92017-04-11 11:30:44 +053017std::vector<uint8_t> payloadHandler(const std::vector<uint8_t>& inPayload,
Vernon Mauery41ff9b52021-06-11 11:37:40 -070018 std::shared_ptr<message::Handler>& handler)
Tom Joseph64b3dec2017-04-03 01:53:44 +053019{
Zhikui Ren2b1edef2020-07-24 14:32:13 -070020 // Check inPayload size is at least Payload
21 if (inPayload.size() < sizeof(Payload))
22 {
23 return std::vector<uint8_t>();
24 }
25
Tom Joseph18a45e92017-04-11 11:30:44 +053026 auto request = reinterpret_cast<const Payload*>(inPayload.data());
Tom Joseph64b3dec2017-04-03 01:53:44 +053027 auto solDataSize = inPayload.size() - sizeof(Payload);
28
Vernon Mauery70fd29c2017-11-30 13:11:43 -080029 std::vector<uint8_t> charData(solDataSize);
Vernon Mauery9e801a22018-10-12 13:20:49 -070030 if (solDataSize > 0)
Tom Joseph64b3dec2017-04-03 01:53:44 +053031 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070032 std::copy_n(inPayload.data() + sizeof(Payload), solDataSize,
Tom Joseph64b3dec2017-04-03 01:53:44 +053033 charData.begin());
34 }
35
36 try
37 {
Vernon Mauery41ff9b52021-06-11 11:37:40 -070038 auto& context = sol::Manager::get().getContext(handler->sessionID);
Tom Joseph64b3dec2017-04-03 01:53:44 +053039
Vernon Mauery9e801a22018-10-12 13:20:49 -070040 context.processInboundPayload(
41 request->packetSeqNum, request->packetAckSeqNum,
42 request->acceptedCharCount, request->inOperation.ack, charData);
Tom Joseph64b3dec2017-04-03 01:53:44 +053043 }
Patrick Williams12d199b2021-10-06 12:36:48 -050044 catch (const std::exception& e)
Tom Joseph64b3dec2017-04-03 01:53:44 +053045 {
46 log<level::ERR>(e.what());
47 return std::vector<uint8_t>();
48 }
49
50 return std::vector<uint8_t>();
51}
52
Tom Josephe14ac962017-04-03 01:56:04 +053053void activating(uint8_t payloadInstance, uint32_t sessionID)
54{
55 std::vector<uint8_t> outPayload(sizeof(ActivatingRequest));
56
Vernon Mauery9e801a22018-10-12 13:20:49 -070057 auto request = reinterpret_cast<ActivatingRequest*>(outPayload.data());
Tom Josephe14ac962017-04-03 01:56:04 +053058
59 request->sessionState = 0;
60 request->payloadInstance = payloadInstance;
61 request->majorVersion = MAJOR_VERSION;
62 request->minorVersion = MINOR_VERSION;
63
Vernon Mauery2085ae02021-06-10 11:51:00 -070064 auto session = session::Manager::get().getSession(sessionID);
Tom Josephe14ac962017-04-03 01:56:04 +053065
66 message::Handler msgHandler(session->channelPtr, sessionID);
67
Vernon Mauery9e801a22018-10-12 13:20:49 -070068 msgHandler.sendUnsolicitedIPMIPayload(netfnTransport, solActivatingCmd,
Tom Josephe14ac962017-04-03 01:56:04 +053069 outPayload);
70}
Tom Joseph64b3dec2017-04-03 01:53:44 +053071} // namespace command
72
73} // namespace sol