1 #include "sol_cmds.hpp"
2 
3 #include "sessions_manager.hpp"
4 #include "sol/sol_context.hpp"
5 #include "sol/sol_manager.hpp"
6 
7 #include <phosphor-logging/lg2.hpp>
8 
9 namespace sol
10 {
11 
12 namespace command
13 {
14 
15 using namespace phosphor::logging;
16 
payloadHandler(const std::vector<uint8_t> & inPayload,std::shared_ptr<message::Handler> & handler)17 std::vector<uint8_t> payloadHandler(const std::vector<uint8_t>& inPayload,
18                                     std::shared_ptr<message::Handler>& handler)
19 {
20     // Check inPayload size is at least Payload
21     if (inPayload.size() < sizeof(Payload))
22     {
23         return std::vector<uint8_t>();
24     }
25 
26     auto request = reinterpret_cast<const Payload*>(inPayload.data());
27     auto solDataSize = inPayload.size() - sizeof(Payload);
28 
29     std::vector<uint8_t> charData(solDataSize);
30     if (solDataSize > 0)
31     {
32         std::copy_n(inPayload.data() + sizeof(Payload), solDataSize,
33                     charData.begin());
34     }
35 
36     try
37     {
38         auto& context = sol::Manager::get().getContext(handler->sessionID);
39 
40         context.processInboundPayload(
41             request->packetSeqNum, request->packetAckSeqNum,
42             request->acceptedCharCount, request->inOperation.ack,
43             request->inOperation.generateBreak, charData);
44     }
45     catch (const std::exception& e)
46     {
47         lg2::error("Failed to call the getContext method: {ERROR}", "ERROR", e);
48         return std::vector<uint8_t>();
49     }
50 
51     return std::vector<uint8_t>();
52 }
53 
activating(uint8_t payloadInstance,uint32_t sessionID)54 void activating(uint8_t payloadInstance, uint32_t sessionID)
55 {
56     std::vector<uint8_t> outPayload(sizeof(ActivatingRequest));
57 
58     auto request = reinterpret_cast<ActivatingRequest*>(outPayload.data());
59 
60     request->sessionState = 0;
61     request->payloadInstance = payloadInstance;
62     request->majorVersion = MAJOR_VERSION;
63     request->minorVersion = MINOR_VERSION;
64 
65     auto session = session::Manager::get().getSession(sessionID);
66 
67     message::Handler msgHandler(session->channelPtr, sessionID);
68 
69     msgHandler.sendUnsolicitedIPMIPayload(netfnTransport, solActivatingCmd,
70                                           outPayload);
71 }
72 } // namespace command
73 
74 } // namespace sol
75