blob: 8cd15c01699e62b1e7874dad148ddfbbf7bc065f [file] [log] [blame]
George Liud6649362019-11-27 19:06:51 +08001#include "pldm_cmd_helper.hpp"
2
George Liud6649362019-11-27 19:06:51 +08003namespace pldmtool
4{
5
6namespace platform
7{
8
9namespace
10{
11
12using namespace pldmtool::helper;
13std::vector<std::unique_ptr<CommandInterface>> commands;
14
15} // namespace
16
17class GetPDR : public CommandInterface
18{
19 public:
20 ~GetPDR() = default;
21 GetPDR() = delete;
22 GetPDR(const GetPDR&) = delete;
23 GetPDR(GetPDR&&) = default;
24 GetPDR& operator=(const GetPDR&) = delete;
25 GetPDR& operator=(GetPDR&&) = default;
26
27 using CommandInterface::CommandInterface;
28
29 // The maximum number of record bytes requested to be returned in the
30 // response to this instance of the GetPDR command.
31 static constexpr uint16_t requestCount = 128;
32
33 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
34 CommandInterface(type, name, app)
35 {
36 app->add_option(
37 "-d,--data", recordHandle,
38 "retrieve individual PDRs from a PDR Repository\n"
39 "eg: The recordHandle value for the PDR to be retrieved and 0 "
40 "means get first PDR in the repository.")
41 ->required();
42 }
43
44 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
45 {
46 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
47 PLDM_GET_PDR_REQ_BYTES);
48 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
49
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -060050 auto rc = encode_get_pdr_req(instanceId, recordHandle, 0,
George Liud6649362019-11-27 19:06:51 +080051 PLDM_GET_FIRSTPART, requestCount, 0,
52 request, PLDM_GET_PDR_REQ_BYTES);
53 return {rc, requestMsg};
54 }
55
56 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
57 {
58 uint8_t completionCode = 0;
George Liu62d12ec2020-02-05 16:27:08 +080059 uint8_t recordData[65535] = {0};
George Liud6649362019-11-27 19:06:51 +080060 uint32_t nextRecordHndl = 0;
61 uint32_t nextDataTransferHndl = 0;
62 uint8_t transferFlag = 0;
63 uint16_t respCnt = 0;
64 uint8_t transferCRC = 0;
65
66 auto rc = decode_get_pdr_resp(
67 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
68 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
69 sizeof(recordData), &transferCRC);
70
71 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
72 {
73 std::cerr << "Response Message Error: "
74 << "rc=" << rc << ",cc=" << (int)completionCode
75 << std::endl;
76 return;
77 }
78
George Liu62d12ec2020-02-05 16:27:08 +080079 printPDRMsg(nextRecordHndl, respCnt, recordData);
George Liud6649362019-11-27 19:06:51 +080080 }
81
82 private:
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -050083 const std::map<uint16_t, std::string> entityType = {
84 {64, "System Board"},
Pavithra Barithayae8beb892020-04-14 23:24:25 -050085 {66, "Memory Module"},
86 {67, "Processor Module"},
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -050087 {137, "Management Controller"},
88 {69, "Chassis front panel board (control panel)"},
89 {123, "Power converter"},
90 {45, "System chassis (main enclosure)"},
91 {11521, "System (logical)"},
92 };
93
Deepak Kodihallia556eb22020-04-14 02:29:11 -050094 std::string getEntityName(uint16_t type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -050095 {
96 try
97 {
98 return entityType.at(type);
99 }
100 catch (const std::out_of_range& e)
101 {
102 return std::to_string(static_cast<unsigned>(type)) + "(OEM)";
103 }
104 }
105
Tom Joseph952abfa2020-07-03 12:25:15 +0530106 void printCommonPDRHeader(const pldm_pdr_hdr* hdr)
107 {
108 std::cout << "recordHandle: " << hdr->record_handle << std::endl;
109 std::cout << "PDRHeaderVersion: " << unsigned(hdr->version)
110 << std::endl;
111 std::cout << "PDRType: " << unsigned(hdr->type) << std::endl;
112 std::cout << "recordChangeNumber: " << hdr->record_change_num
113 << std::endl;
114 std::cout << "dataLength: " << hdr->length << std::endl << std::endl;
115 }
116
George Liu62d12ec2020-02-05 16:27:08 +0800117 void printPDRFruRecordSet(uint8_t* data)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500118 {
George Liu62d12ec2020-02-05 16:27:08 +0800119 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500120 {
121 return;
122 }
123
124 data += sizeof(pldm_pdr_hdr);
125 pldm_pdr_fru_record_set* pdr =
126 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
127
128 std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
129 << std::endl;
130 std::cout << "FRURecordSetIdentifier: " << pdr->fru_rsi << std::endl;
131 std::cout << "entityType: " << getEntityName(pdr->entity_type)
132 << std::endl;
133 std::cout << "entityInstanceNumber: " << pdr->entity_instance_num
134 << std::endl;
135 std::cout << "containerID: " << pdr->container_id << std::endl;
136 }
137
George Liu62d12ec2020-02-05 16:27:08 +0800138 void printPDREntityAssociation(uint8_t* data)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500139 {
140 const std::map<uint8_t, const char*> assocationType = {
141 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
142 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
143 };
144
George Liu62d12ec2020-02-05 16:27:08 +0800145 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500146 {
147 return;
148 }
149
150 data += sizeof(pldm_pdr_hdr);
151 pldm_pdr_entity_association* pdr =
152 reinterpret_cast<pldm_pdr_entity_association*>(data);
153
154 std::cout << "containerID: " << pdr->container_id << std::endl;
155 std::cout << "associationType: "
156 << assocationType.at(pdr->association_type) << std::endl
157 << std::endl;
158
159 std::cout << "containerEntityType: "
160 << getEntityName(pdr->container.entity_type) << std::endl;
161 std::cout << "containerEntityInstanceNumber: "
162 << pdr->container.entity_instance_num << std::endl;
163 std::cout << "containerEntityContainerID: "
164 << pdr->container.entity_container_id << std::endl;
165
166 std::cout << "containedEntityCount: "
167 << static_cast<unsigned>(pdr->num_children) << std::endl
168 << std::endl;
169
170 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
171 for (int i = 0; i < pdr->num_children; ++i)
172 {
173 std::cout << "containedEntityType[" << i + 1
174 << "]: " << getEntityName(child->entity_type)
175 << std::endl;
176 std::cout << "containedEntityInstanceNumber[" << i + 1
177 << "]: " << child->entity_instance_num << std::endl;
178 std::cout << "containedEntityContainerID[" << i + 1
179 << "]: " << child->entity_container_id << std::endl
180 << std::endl;
181 ++child;
182 }
183 }
184
George Liu62d12ec2020-02-05 16:27:08 +0800185 void printNumericEffecterPDR(uint8_t* data)
186 {
187 struct pldm_numeric_effecter_value_pdr* pdr =
188 (struct pldm_numeric_effecter_value_pdr*)data;
George Liu62d12ec2020-02-05 16:27:08 +0800189 std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
190 << std::endl;
191 std::cout << "effecterID: " << pdr->effecter_id << std::endl;
192 std::cout << "entityType: " << pdr->entity_type << std::endl;
193 std::cout << "entityInstanceNumber: " << pdr->entity_instance
194 << std::endl;
195 std::cout << "containerID: " << pdr->container_id << std::endl;
196 std::cout << "effecterSemanticID: " << pdr->effecter_semantic_id
197 << std::endl;
198 std::cout << "effecterInit: " << unsigned(pdr->effecter_init)
199 << std::endl;
200 std::cout << "effecterAuxiliaryNames: "
201 << (unsigned(pdr->effecter_auxiliary_names) ? "true"
202 : "false")
203 << std::endl;
204 std::cout << "baseUnit: " << unsigned(pdr->base_unit) << std::endl;
205 std::cout << "unitModifier: " << unsigned(pdr->unit_modifier)
206 << std::endl;
207 std::cout << "rateUnit: " << unsigned(pdr->rate_unit) << std::endl;
208 std::cout << "baseOEMUnitHandle: "
209 << unsigned(pdr->base_oem_unit_handle) << std::endl;
210 std::cout << "auxUnit: " << unsigned(pdr->aux_unit) << std::endl;
211 std::cout << "auxUnitModifier: " << unsigned(pdr->aux_unit_modifier)
212 << std::endl;
213 std::cout << "auxrateUnit: " << unsigned(pdr->aux_rate_unit)
214 << std::endl;
215 std::cout << "auxOEMUnitHandle: " << unsigned(pdr->aux_oem_unit_handle)
216 << std::endl;
217 std::cout << "isLinear: "
218 << (unsigned(pdr->is_linear) ? "true" : "false") << std::endl;
219 std::cout << "effecterDataSize: " << unsigned(pdr->effecter_data_size)
220 << std::endl;
221 std::cout << "resolution: " << pdr->resolution << std::endl;
222 std::cout << "offset: " << pdr->offset << std::endl;
223 std::cout << "accuracy: " << pdr->accuracy << std::endl;
224 std::cout << "plusTolerance: " << unsigned(pdr->plus_tolerance)
225 << std::endl;
226 std::cout << "minusTolerance: " << unsigned(pdr->minus_tolerance)
227 << std::endl;
228 std::cout << "stateTransitionInterval: "
229 << pdr->state_transition_interval << std::endl;
230 std::cout << "TransitionInterval: " << pdr->transition_interval
231 << std::endl;
232 switch (pdr->effecter_data_size)
233 {
234 case PLDM_EFFECTER_DATA_SIZE_UINT8:
235 std::cout << "maxSettable: "
236 << unsigned(pdr->max_set_table.value_u8) << std::endl;
237 std::cout << "minSettable: "
238 << unsigned(pdr->min_set_table.value_u8) << std::endl;
239 break;
240 case PLDM_EFFECTER_DATA_SIZE_SINT8:
241 std::cout << "maxSettable: "
242 << unsigned(pdr->max_set_table.value_s8) << std::endl;
243 std::cout << "minSettable: "
244 << unsigned(pdr->min_set_table.value_s8) << std::endl;
245 break;
246 case PLDM_EFFECTER_DATA_SIZE_UINT16:
247 std::cout << "maxSettable: " << pdr->max_set_table.value_u16
248 << std::endl;
249 std::cout << "minSettable: " << pdr->min_set_table.value_u16
250 << std::endl;
251 break;
252 case PLDM_EFFECTER_DATA_SIZE_SINT16:
253 std::cout << "maxSettable: " << pdr->max_set_table.value_s16
254 << std::endl;
255 std::cout << "minSettable: " << pdr->min_set_table.value_s16
256 << std::endl;
257 break;
258 case PLDM_EFFECTER_DATA_SIZE_UINT32:
259 std::cout << "maxSettable: " << pdr->max_set_table.value_u32
260 << std::endl;
261 std::cout << "minSettable: " << pdr->min_set_table.value_u32
262 << std::endl;
263 break;
264 case PLDM_EFFECTER_DATA_SIZE_SINT32:
265 std::cout << "maxSettable: " << pdr->max_set_table.value_s32
266 << std::endl;
267 std::cout << "minSettable: " << pdr->min_set_table.value_s32
268 << std::endl;
269 break;
270 default:
271 break;
272 }
273 std::cout << "rangeFieldFormat: " << unsigned(pdr->range_field_format)
274 << std::endl;
275 std::cout << "rangeFieldSupport: "
276 << unsigned(pdr->range_field_support.byte) << std::endl;
277 switch (pdr->range_field_format)
278 {
279 case PLDM_RANGE_FIELD_FORMAT_UINT8:
280 std::cout << "nominalValue: "
281 << unsigned(pdr->nominal_value.value_u8) << std::endl;
282 std::cout << "normalMax: " << unsigned(pdr->normal_max.value_u8)
283 << std::endl;
284 std::cout << "normalMin: " << unsigned(pdr->normal_min.value_u8)
285 << std::endl;
286 std::cout << "ratedMax: " << unsigned(pdr->rated_max.value_u8)
287 << std::endl;
288 std::cout << "ratedMin: " << unsigned(pdr->rated_min.value_u8)
289 << std::endl;
290 break;
291 case PLDM_RANGE_FIELD_FORMAT_SINT8:
292 std::cout << "nominalValue: "
293 << unsigned(pdr->nominal_value.value_s8) << std::endl;
294 std::cout << "normalMax: " << unsigned(pdr->normal_max.value_s8)
295 << std::endl;
296 std::cout << "normalMin: " << unsigned(pdr->normal_min.value_s8)
297 << std::endl;
298 std::cout << "ratedMax: " << unsigned(pdr->rated_max.value_s8)
299 << std::endl;
300 std::cout << "ratedMin: " << unsigned(pdr->rated_min.value_s8)
301 << std::endl;
302 break;
303 case PLDM_RANGE_FIELD_FORMAT_UINT16:
304 std::cout << "nominalValue: " << pdr->nominal_value.value_u16
305 << std::endl;
306 std::cout << "normalMax: " << pdr->normal_max.value_u16
307 << std::endl;
308 std::cout << "normalMin: " << pdr->normal_min.value_u16
309 << std::endl;
310 std::cout << "ratedMax: " << pdr->rated_max.value_u16
311 << std::endl;
312 std::cout << "ratedMin: " << pdr->rated_min.value_u16
313 << std::endl;
314 break;
315 case PLDM_RANGE_FIELD_FORMAT_SINT16:
316 std::cout << "nominalValue: " << pdr->nominal_value.value_s16
317 << std::endl;
318 std::cout << "normalMax: " << pdr->normal_max.value_s16
319 << std::endl;
320 std::cout << "normalMin: " << pdr->normal_min.value_s16
321 << std::endl;
322 std::cout << "ratedMax: " << pdr->rated_max.value_s16
323 << std::endl;
324 std::cout << "ratedMin: " << pdr->rated_min.value_s16
325 << std::endl;
326 break;
327 case PLDM_RANGE_FIELD_FORMAT_UINT32:
328 std::cout << "nominalValue: " << pdr->nominal_value.value_u32
329 << std::endl;
330 std::cout << "normalMax: " << pdr->normal_max.value_u32
331 << std::endl;
332 std::cout << "normalMin: " << pdr->normal_min.value_u32
333 << std::endl;
334 std::cout << "ratedMax: " << pdr->rated_max.value_u32
335 << std::endl;
336 std::cout << "ratedMin: " << pdr->rated_min.value_u32
337 << std::endl;
338 break;
339 case PLDM_RANGE_FIELD_FORMAT_SINT32:
340 std::cout << "nominalValue: " << pdr->nominal_value.value_s32
341 << std::endl;
342 std::cout << "normalMax: " << pdr->normal_max.value_s32
343 << std::endl;
344 std::cout << "normalMin: " << pdr->normal_min.value_s32
345 << std::endl;
346 std::cout << "ratedMax: " << pdr->rated_max.value_s32
347 << std::endl;
348 std::cout << "ratedMin: " << pdr->rated_min.value_s32
349 << std::endl;
350 break;
351 case PLDM_RANGE_FIELD_FORMAT_REAL32:
352 std::cout << "nominalValue: " << pdr->nominal_value.value_f32
353 << std::endl;
354 std::cout << "normalMax: " << pdr->normal_max.value_f32
355 << std::endl;
356 std::cout << "normalMin: " << pdr->normal_min.value_f32
357 << std::endl;
358 std::cout << "ratedMax: " << pdr->rated_max.value_f32
359 << std::endl;
360 std::cout << "ratedMin: " << pdr->rated_min.value_f32
361 << std::endl;
362 break;
363 default:
364 break;
365 }
366 }
367
368 void printStateEffecterPDR(uint8_t* data)
369 {
370 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800371 {
372 return;
373 }
374
375 struct pldm_state_effecter_pdr* pdr =
376 (struct pldm_state_effecter_pdr*)data;
George Liu62d12ec2020-02-05 16:27:08 +0800377
George Liud6649362019-11-27 19:06:51 +0800378 std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
379 << std::endl;
380 std::cout << "effecterID: " << pdr->effecter_id << std::endl;
381 std::cout << "entityType: " << pdr->entity_type << std::endl;
382 std::cout << "entityInstanceNumber: " << pdr->entity_instance
383 << std::endl;
384 std::cout << "containerID: " << pdr->container_id << std::endl;
385 std::cout << "effecterSemanticID: " << pdr->effecter_semantic_id
386 << std::endl;
387 std::cout << "effecterInit: " << unsigned(pdr->effecter_init)
388 << std::endl;
389 std::cout << "effecterDescriptionPDR: "
390 << (unsigned(pdr->has_description_pdr) ? "true" : "false")
391 << std::endl;
392 std::cout << "compositeEffecterCount: "
393 << unsigned(pdr->composite_effecter_count) << std::endl;
394
395 for (size_t i = 0; i < pdr->composite_effecter_count; ++i)
396 {
397 struct state_effecter_possible_states* state =
398 (struct state_effecter_possible_states*)pdr->possible_states +
399 i * sizeof(state_effecter_possible_states);
400 std::cout << "stateSetID: " << state->state_set_id << std::endl;
401 std::cout << "possibleStatesSize: "
402 << unsigned(state->possible_states_size) << std::endl;
403 bitfield8_t* bf = reinterpret_cast<bitfield8_t*>(state->states);
404 std::cout << "possibleStates: " << unsigned(bf->byte) << std::endl;
405 }
406 }
407
408 void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt,
George Liu62d12ec2020-02-05 16:27:08 +0800409 uint8_t* data)
George Liud6649362019-11-27 19:06:51 +0800410 {
George Liu62d12ec2020-02-05 16:27:08 +0800411 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800412 {
413 return;
414 }
415
George Liud6649362019-11-27 19:06:51 +0800416 std::cout << "nextRecordHandle: " << nextRecordHndl << std::endl;
417 std::cout << "responseCount: " << respCnt << std::endl;
418
419 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Tom Joseph952abfa2020-07-03 12:25:15 +0530420 printCommonPDRHeader(pdr);
George Liud6649362019-11-27 19:06:51 +0800421 switch (pdr->type)
422 {
George Liu62d12ec2020-02-05 16:27:08 +0800423 case PLDM_NUMERIC_EFFECTER_PDR:
424 printNumericEffecterPDR(data);
425 break;
George Liud6649362019-11-27 19:06:51 +0800426 case PLDM_STATE_EFFECTER_PDR:
George Liu62d12ec2020-02-05 16:27:08 +0800427 printStateEffecterPDR(data);
George Liud6649362019-11-27 19:06:51 +0800428 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500429 case PLDM_PDR_ENTITY_ASSOCIATION:
George Liu62d12ec2020-02-05 16:27:08 +0800430 printPDREntityAssociation(data);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500431 break;
432 case PLDM_PDR_FRU_RECORD_SET:
George Liu62d12ec2020-02-05 16:27:08 +0800433 printPDRFruRecordSet(data);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500434 break;
George Liud6649362019-11-27 19:06:51 +0800435 default:
436 break;
437 }
438 }
439
440 private:
441 uint32_t recordHandle;
442};
443
444class SetStateEffecter : public CommandInterface
445{
446 public:
447 ~SetStateEffecter() = default;
448 SetStateEffecter() = delete;
449 SetStateEffecter(const SetStateEffecter&) = delete;
450 SetStateEffecter(SetStateEffecter&&) = default;
451 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
452 SetStateEffecter& operator=(SetStateEffecter&&) = default;
453
George Liuba4c1fb2020-02-05 14:13:30 +0800454 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
455 static constexpr auto maxEffecterDataSize = 16;
456
457 // compositeEffecterCount(value: 0x01 to 0x08)
458 static constexpr auto minEffecterCount = 1;
459 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +0800460 explicit SetStateEffecter(const char* type, const char* name,
461 CLI::App* app) :
462 CommandInterface(type, name, app)
463 {
464 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +0800465 "-i, --id", effecterId,
466 "A handle that is used to identify and access the effecter")
467 ->required();
468 app->add_option("-c, --count", effecterCount,
469 "The number of individual sets of effecter information")
470 ->required();
471 app->add_option(
George Liud6649362019-11-27 19:06:51 +0800472 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +0800473 "Set effecter state data\n"
474 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
475 ->required();
George Liud6649362019-11-27 19:06:51 +0800476 }
477
478 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
479 {
480 std::vector<uint8_t> requestMsg(
481 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
482 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
483
George Liuba4c1fb2020-02-05 14:13:30 +0800484 if (effecterCount > maxEffecterCount ||
485 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +0800486 {
George Liuba4c1fb2020-02-05 14:13:30 +0800487 std::cerr << "Request Message Error: effecterCount size "
488 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +0800489 auto rc = PLDM_ERROR_INVALID_DATA;
490 return {rc, requestMsg};
491 }
492
George Liuba4c1fb2020-02-05 14:13:30 +0800493 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +0800494 {
George Liuba4c1fb2020-02-05 14:13:30 +0800495 std::cerr << "Request Message Error: effecterData size "
496 << effecterData.size() << "is invalid\n";
497 auto rc = PLDM_ERROR_INVALID_DATA;
498 return {rc, requestMsg};
499 }
500
501 auto stateField = parseEffecterData(effecterData, effecterCount);
502 if (!stateField)
503 {
504 std::cerr << "Failed to parse effecter data, effecterCount size "
505 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +0800506 auto rc = PLDM_ERROR_INVALID_DATA;
507 return {rc, requestMsg};
508 }
509
510 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600511 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +0800512 return {rc, requestMsg};
513 }
514
515 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
516 {
517 uint8_t completionCode = 0;
518 auto rc = decode_set_state_effecter_states_resp(
519 responsePtr, payloadLength, &completionCode);
520
521 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
522 {
523 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +0800524 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +0800525 return;
526 }
527
528 std::cout << "SetStateEffecterStates: SUCCESS" << std::endl;
529 }
530
531 private:
George Liuba4c1fb2020-02-05 14:13:30 +0800532 uint16_t effecterId;
533 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +0800534 std::vector<uint8_t> effecterData;
535};
536
George Liucc9c20d2020-02-05 10:24:11 +0800537class SetNumericEffecterValue : public CommandInterface
538{
539 public:
540 ~SetNumericEffecterValue() = default;
541 SetNumericEffecterValue() = delete;
542 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
543 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
544 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
545 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default;
546
547 explicit SetNumericEffecterValue(const char* type, const char* name,
548 CLI::App* app) :
549 CommandInterface(type, name, app)
550 {
551 app->add_option(
552 "-i, --id", effecterId,
553 "A handle that is used to identify and access the effecter")
554 ->required();
555 app->add_option("-s, --size", effecterDataSize,
556 "The bit width and format of the setting value for the "
557 "effecter. enum value: {uint8, sint8, uint16, sint16, "
558 "uint32, sint32}\n")
559 ->required();
560 app->add_option("-d,--data", maxEffecterValue,
561 "The setting value of numeric effecter being "
562 "requested\n")
563 ->required();
564 }
565
566 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
567 {
568 std::vector<uint8_t> requestMsg(
569 sizeof(pldm_msg_hdr) +
570 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
571
572 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
573
574 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
575 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
576
577 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
578 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
579 {
580 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
581 }
582 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
583 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
584 {
585 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
586 }
587 auto rc = encode_set_numeric_effecter_value_req(
588 0, effecterId, effecterDataSize, effecterValue, request,
589 payload_length);
590
591 return {rc, requestMsg};
592 }
593
594 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
595 {
596 uint8_t completionCode = 0;
597 auto rc = decode_set_numeric_effecter_value_resp(
598 responsePtr, payloadLength, &completionCode);
599
600 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
601 {
602 std::cerr << "Response Message Error: "
603 << "rc=" << rc << ",cc=" << (int)completionCode
604 << std::endl;
605 return;
606 }
607
608 std::cout << "SetNumericEffecterValue: SUCCESS" << std::endl;
609 }
610
611 private:
612 uint16_t effecterId;
613 uint8_t effecterDataSize;
614 uint64_t maxEffecterValue;
615};
616
George Liud6649362019-11-27 19:06:51 +0800617void registerCommand(CLI::App& app)
618{
619 auto platform = app.add_subcommand("platform", "platform type command");
620 platform->require_subcommand(1);
621
622 auto getPDR =
623 platform->add_subcommand("GetPDR", "get platform descriptor records");
624 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
625
626 auto setStateEffecterStates = platform->add_subcommand(
627 "SetStateEffecterStates", "set effecter states");
628 commands.push_back(std::make_unique<SetStateEffecter>(
629 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +0800630
631 auto setNumericEffecterValue = platform->add_subcommand(
632 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
633 commands.push_back(std::make_unique<SetNumericEffecterValue>(
634 "platform", "setNumericEffecterValue", setNumericEffecterValue));
George Liud6649362019-11-27 19:06:51 +0800635}
636
637} // namespace platform
638} // namespace pldmtool