blob: a8fa41074492f26aa2dae429115d918915847cd2 [file] [log] [blame]
Vernon Mauery9e801a22018-10-12 13:20:49 -07001#include "sol_cmds.hpp"
2
Tom Joseph64b3dec2017-04-03 01:53:44 +05303#include "main.hpp"
4#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,
Tom Joseph64b3dec2017-04-03 01:53:44 +053018 const message::Handler& handler)
19{
Tom Joseph18a45e92017-04-11 11:30:44 +053020 auto request = reinterpret_cast<const Payload*>(inPayload.data());
Tom Joseph64b3dec2017-04-03 01:53:44 +053021 auto solDataSize = inPayload.size() - sizeof(Payload);
22
Vernon Mauery70fd29c2017-11-30 13:11:43 -080023 std::vector<uint8_t> charData(solDataSize);
Vernon Mauery9e801a22018-10-12 13:20:49 -070024 if (solDataSize > 0)
Tom Joseph64b3dec2017-04-03 01:53:44 +053025 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070026 std::copy_n(inPayload.data() + sizeof(Payload), solDataSize,
Tom Joseph64b3dec2017-04-03 01:53:44 +053027 charData.begin());
28 }
29
30 try
31 {
Vernon Mauery9e801a22018-10-12 13:20:49 -070032 auto& context = std::get<sol::Manager&>(singletonPool)
33 .getContext(handler.sessionID);
Tom Joseph64b3dec2017-04-03 01:53:44 +053034
Vernon Mauery9e801a22018-10-12 13:20:49 -070035 context.processInboundPayload(
36 request->packetSeqNum, request->packetAckSeqNum,
37 request->acceptedCharCount, request->inOperation.ack, charData);
Tom Joseph64b3dec2017-04-03 01:53:44 +053038 }
39 catch (std::exception& e)
40 {
41 log<level::ERR>(e.what());
42 return std::vector<uint8_t>();
43 }
44
45 return std::vector<uint8_t>();
46}
47
Tom Josephe14ac962017-04-03 01:56:04 +053048void activating(uint8_t payloadInstance, uint32_t sessionID)
49{
50 std::vector<uint8_t> outPayload(sizeof(ActivatingRequest));
51
Vernon Mauery9e801a22018-10-12 13:20:49 -070052 auto request = reinterpret_cast<ActivatingRequest*>(outPayload.data());
Tom Josephe14ac962017-04-03 01:56:04 +053053
54 request->sessionState = 0;
55 request->payloadInstance = payloadInstance;
56 request->majorVersion = MAJOR_VERSION;
57 request->minorVersion = MINOR_VERSION;
58
Vernon Mauery9e801a22018-10-12 13:20:49 -070059 auto session =
Vernon Maueryae1fda42018-10-15 12:55:34 -070060 std::get<session::Manager&>(singletonPool).getSession(sessionID);
Tom Josephe14ac962017-04-03 01:56:04 +053061
62 message::Handler msgHandler(session->channelPtr, sessionID);
63
Vernon Mauery9e801a22018-10-12 13:20:49 -070064 msgHandler.sendUnsolicitedIPMIPayload(netfnTransport, solActivatingCmd,
Tom Josephe14ac962017-04-03 01:56:04 +053065 outPayload);
66}
67
Tom Joseph48b99512017-04-28 01:31:08 +053068std::vector<uint8_t> setConfParams(const std::vector<uint8_t>& inPayload,
69 const message::Handler& handler)
70{
71 std::vector<uint8_t> outPayload(sizeof(SetConfParamsResponse));
Vernon Mauery9e801a22018-10-12 13:20:49 -070072 auto request =
73 reinterpret_cast<const SetConfParamsRequest*>(inPayload.data());
74 auto response = reinterpret_cast<SetConfParamsResponse*>(outPayload.data());
Tom Joseph48b99512017-04-28 01:31:08 +053075 response->completionCode = IPMI_CC_OK;
76
77 switch (static_cast<Parameter>(request->paramSelector))
78 {
79 case Parameter::PROGRESS:
80 {
81 uint8_t progress = request->value & progressMask;
82 std::get<sol::Manager&>(singletonPool).progress = progress;
83 break;
84 }
85 case Parameter::ENABLE:
86 {
87 bool enable = request->value & enableMask;
88 std::get<sol::Manager&>(singletonPool).enable = enable;
89 break;
90 }
91 case Parameter::AUTHENTICATION:
92 {
93 if (!request->auth.auth || !request->auth.encrypt)
94 {
95 response->completionCode = ipmiCCWriteReadParameter;
96 }
97 else if (request->auth.privilege <
Vernon Mauery9e801a22018-10-12 13:20:49 -070098 static_cast<uint8_t>(session::Privilege::USER) ||
Tom Joseph48b99512017-04-28 01:31:08 +053099 request->auth.privilege >
Vernon Mauery9e801a22018-10-12 13:20:49 -0700100 static_cast<uint8_t>(session::Privilege::OEM))
Tom Joseph48b99512017-04-28 01:31:08 +0530101 {
102 response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
103 }
104 else
105 {
106 std::get<sol::Manager&>(singletonPool).solMinPrivilege =
Vernon Mauery9e801a22018-10-12 13:20:49 -0700107 static_cast<session::Privilege>(request->auth.privilege);
Tom Joseph48b99512017-04-28 01:31:08 +0530108 }
109 break;
110 }
111 case Parameter::ACCUMULATE:
112 {
113 using namespace std::chrono_literals;
114
115 if (request->acc.threshold == 0)
116 {
117 response->completionCode = IPMI_CC_INVALID_FIELD_REQUEST;
118 break;
119 }
120
121 std::get<sol::Manager&>(singletonPool).accumulateInterval =
Vernon Mauery9e801a22018-10-12 13:20:49 -0700122 request->acc.interval * sol::accIntervalFactor * 1ms;
Tom Joseph48b99512017-04-28 01:31:08 +0530123 std::get<sol::Manager&>(singletonPool).sendThreshold =
Vernon Mauery9e801a22018-10-12 13:20:49 -0700124 request->acc.threshold;
Tom Joseph48b99512017-04-28 01:31:08 +0530125 break;
126 }
127 case Parameter::RETRY:
128 {
129 using namespace std::chrono_literals;
130
131 std::get<sol::Manager&>(singletonPool).retryCount =
Vernon Mauery9e801a22018-10-12 13:20:49 -0700132 request->retry.count;
Tom Joseph48b99512017-04-28 01:31:08 +0530133 std::get<sol::Manager&>(singletonPool).retryInterval =
Vernon Mauery9e801a22018-10-12 13:20:49 -0700134 request->retry.interval * sol::retryIntervalFactor * 1ms;
Tom Joseph48b99512017-04-28 01:31:08 +0530135 break;
136 }
137 case Parameter::PORT:
138 {
139 response->completionCode = ipmiCCWriteReadParameter;
140 break;
141 }
142 case Parameter::NVBITRATE:
143 case Parameter::VBITRATE:
144 case Parameter::CHANNEL:
145 default:
146 response->completionCode = ipmiCCParamNotSupported;
147 }
148
149 return outPayload;
150}
151
Tom Joseph20aef332017-04-28 01:34:10 +0530152std::vector<uint8_t> getConfParams(const std::vector<uint8_t>& inPayload,
153 const message::Handler& handler)
154{
155 std::vector<uint8_t> outPayload(sizeof(GetConfParamsResponse));
Vernon Mauery9e801a22018-10-12 13:20:49 -0700156 auto request =
157 reinterpret_cast<const GetConfParamsRequest*>(inPayload.data());
158 auto response = reinterpret_cast<GetConfParamsResponse*>(outPayload.data());
Tom Joseph20aef332017-04-28 01:34:10 +0530159 response->completionCode = IPMI_CC_OK;
160 response->paramRev = parameterRevision;
161
162 if (request->getParamRev)
163 {
164 return outPayload;
165 }
166
167 switch (static_cast<Parameter>(request->paramSelector))
168 {
169 case Parameter::PROGRESS:
170 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700171 outPayload.push_back(
172 std::get<sol::Manager&>(singletonPool).progress);
Tom Joseph20aef332017-04-28 01:34:10 +0530173 break;
174 }
175 case Parameter::ENABLE:
176 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700177 outPayload.push_back(std::get<sol::Manager&>(singletonPool).enable);
Tom Joseph20aef332017-04-28 01:34:10 +0530178 break;
179 }
180 case Parameter::AUTHENTICATION:
181 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700182 Auth value{0};
Tom Joseph20aef332017-04-28 01:34:10 +0530183
184 value.encrypt = std::get<sol::Manager&>(singletonPool).forceEncrypt;
185 value.auth = std::get<sol::Manager&>(singletonPool).forceAuth;
Vernon Mauery9e801a22018-10-12 13:20:49 -0700186 value.privilege = static_cast<uint8_t>(
187 std::get<sol::Manager&>(singletonPool).solMinPrivilege);
188 auto buffer = reinterpret_cast<const uint8_t*>(&value);
Tom Joseph20aef332017-04-28 01:34:10 +0530189
190 std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload));
191 break;
192 }
193 case Parameter::ACCUMULATE:
194 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700195 Accumulate value{0};
Tom Joseph20aef332017-04-28 01:34:10 +0530196
197 value.interval = std::get<sol::Manager&>(singletonPool)
Vernon Mauery9e801a22018-10-12 13:20:49 -0700198 .accumulateInterval.count() /
199 sol::accIntervalFactor;
200 value.threshold =
201 std::get<sol::Manager&>(singletonPool).sendThreshold;
202 auto buffer = reinterpret_cast<const uint8_t*>(&value);
Tom Joseph20aef332017-04-28 01:34:10 +0530203
204 std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload));
205 break;
206 }
207 case Parameter::RETRY:
208 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700209 Retry value{0};
Tom Joseph20aef332017-04-28 01:34:10 +0530210
211 value.count = std::get<sol::Manager&>(singletonPool).retryCount;
Vernon Mauery9e801a22018-10-12 13:20:49 -0700212 value.interval =
213 std::get<sol::Manager&>(singletonPool).retryInterval.count() /
214 sol::retryIntervalFactor;
215 auto buffer = reinterpret_cast<const uint8_t*>(&value);
Tom Joseph20aef332017-04-28 01:34:10 +0530216
217 std::copy_n(buffer, sizeof(value), std::back_inserter(outPayload));
218 break;
219 }
220 case Parameter::PORT:
221 {
222 auto port = endian::to_ipmi<uint16_t>(IPMI_STD_PORT);
Vernon Mauery9e801a22018-10-12 13:20:49 -0700223 auto buffer = reinterpret_cast<const uint8_t*>(&port);
Tom Joseph20aef332017-04-28 01:34:10 +0530224
225 std::copy_n(buffer, sizeof(port), std::back_inserter(outPayload));
226 break;
227 }
Tom Joseph6f83cbc2018-03-27 03:01:58 +0530228 case Parameter::CHANNEL:
229 {
Vernon Mauery9e801a22018-10-12 13:20:49 -0700230 outPayload.push_back(
231 std::get<sol::Manager&>(singletonPool).channel);
Tom Joseph6f83cbc2018-03-27 03:01:58 +0530232 break;
233 }
Tom Joseph20aef332017-04-28 01:34:10 +0530234 case Parameter::NVBITRATE:
235 case Parameter::VBITRATE:
Tom Joseph20aef332017-04-28 01:34:10 +0530236 default:
237 response->completionCode = ipmiCCParamNotSupported;
238 }
239
240 return outPayload;
241}
242
Tom Joseph64b3dec2017-04-03 01:53:44 +0530243} // namespace command
244
245} // namespace sol