blob: 02c854acbb9ddbcc6a3e4c989831242b28847210 [file] [log] [blame]
Tom Joseph5c846a82017-04-03 01:59:39 +05301#include <host-ipmid/ipmid-api.h>
2#include <phosphor-logging/log.hpp>
3#include "main.hpp"
4#include "payload_cmds.hpp"
5#include "sol/sol_manager.hpp"
6#include "sol_cmds.hpp"
7
8namespace sol
9{
10
11namespace command
12{
13
14using namespace phosphor::logging;
15
16std::vector<uint8_t> activatePayload(std::vector<uint8_t>& inPayload,
17 const message::Handler& handler)
18{
19 std::vector<uint8_t> outPayload(sizeof(ActivatePayloadResponse));
20 auto request = reinterpret_cast<ActivatePayloadRequest*>(inPayload.data());
21 auto response = reinterpret_cast<ActivatePayloadResponse*>
22 (outPayload.data());
23
24 response->completionCode = IPMI_CC_OK;
25
26 // SOL is the payload currently supported for activation.
27 if (static_cast<uint8_t>(message::PayloadType::SOL) != request->payloadType)
28 {
29 response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
30 return outPayload;
31 }
32
33 // Only one instance of SOL is currently supported.
34 if (request->payloadInstance != 1)
35 {
36 response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
37 return outPayload;
38 }
39
40 auto session = (std::get<session::Manager&>(singletonPool).getSession(
41 handler.sessionID)).lock();
42
43 if (!request->encryption && session->isCryptAlgoEnabled())
44 {
45 response->completionCode = IPMI_CC_PAYLOAD_WITHOUT_ENCRYPTION;
46 return outPayload;
47 }
48
49 auto status = std::get<sol::Manager&>(singletonPool).isPayloadActive(
50 request->payloadInstance);
51 if (status)
52 {
53 response->completionCode = IPMI_CC_PAYLOAD_ALREADY_ACTIVE;
54 return outPayload;
55 }
56
57 // Set the current command's socket channel to the session
58 handler.setChannelInSession();
59
60 // Start the SOL payload
61 try
62 {
63 std::get<sol::Manager&>(singletonPool).startPayloadInstance(
64 request->payloadInstance,
65 handler.sessionID);
66 }
67 catch (std::exception& e)
68 {
69 log<level::ERR>(e.what());
70 response->completionCode = IPMI_CC_UNSPECIFIED_ERROR;
71 return outPayload;
72 }
73
74 response->inPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE);
75 response->outPayloadSize = endian::to_ipmi<uint16_t>(MAX_PAYLOAD_SIZE);
76 response->portNum = endian::to_ipmi<uint16_t>(IPMI_STD_PORT);
77
78 // VLAN addressing is not used
79 response->vlanNum = 0xFFFF;
80
81 return outPayload;
82}
83
84} // namespace command
85
86} // namespace sol