blob: 7c844fabd70f5da55b9299a9ddbb0c982980fa09 [file] [log] [blame]
Tom Josepha65c0412020-07-03 21:14:44 +05301#include "libpldm/entity.h"
2#include "libpldm/state_set.h"
3
4#include "common/types.hpp"
George Liud6649362019-11-27 19:06:51 +08005#include "pldm_cmd_helper.hpp"
6
George Liud6649362019-11-27 19:06:51 +08007namespace pldmtool
8{
9
10namespace platform
11{
12
13namespace
14{
15
16using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060017
18static const std::map<uint8_t, std::string> sensorPresState{
19 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
20 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
21 {PLDM_SENSOR_WARNING, "Sensor Warning"},
22 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
23 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
24 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
25 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
26 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
27 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
28 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
29 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
30
31static const std::map<uint8_t, std::string> sensorOpState{
32 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
33 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
34 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
35 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
36 {PLDM_SENSOR_FAILED, "Sensor Failed"},
37 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Intializing"},
38 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
39 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
40
George Liud6649362019-11-27 19:06:51 +080041std::vector<std::unique_ptr<CommandInterface>> commands;
42
43} // namespace
44
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050045using ordered_json = nlohmann::ordered_json;
46
George Liud6649362019-11-27 19:06:51 +080047class GetPDR : public CommandInterface
48{
49 public:
50 ~GetPDR() = default;
51 GetPDR() = delete;
52 GetPDR(const GetPDR&) = delete;
53 GetPDR(GetPDR&&) = default;
54 GetPDR& operator=(const GetPDR&) = delete;
55 GetPDR& operator=(GetPDR&&) = default;
56
57 using CommandInterface::CommandInterface;
58
George Liud6649362019-11-27 19:06:51 +080059 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
60 CommandInterface(type, name, app)
61 {
62 app->add_option(
63 "-d,--data", recordHandle,
64 "retrieve individual PDRs from a PDR Repository\n"
65 "eg: The recordHandle value for the PDR to be retrieved and 0 "
66 "means get first PDR in the repository.")
67 ->required();
68 }
69
70 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
71 {
72 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
73 PLDM_GET_PDR_REQ_BYTES);
74 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
75
Deepak Kodihallia59cdc62020-07-14 05:11:33 -050076 auto rc =
77 encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
78 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +080079 return {rc, requestMsg};
80 }
81
82 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
83 {
84 uint8_t completionCode = 0;
Deepak Kodihallia59cdc62020-07-14 05:11:33 -050085 uint8_t recordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +080086 uint32_t nextRecordHndl = 0;
87 uint32_t nextDataTransferHndl = 0;
88 uint8_t transferFlag = 0;
89 uint16_t respCnt = 0;
90 uint8_t transferCRC = 0;
91
92 auto rc = decode_get_pdr_resp(
93 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
94 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
95 sizeof(recordData), &transferCRC);
96
97 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
98 {
99 std::cerr << "Response Message Error: "
100 << "rc=" << rc << ",cc=" << (int)completionCode
101 << std::endl;
102 return;
103 }
104
George Liu62d12ec2020-02-05 16:27:08 +0800105 printPDRMsg(nextRecordHndl, respCnt, recordData);
George Liud6649362019-11-27 19:06:51 +0800106 }
107
108 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530109 const std::map<pldm::pdr::EntityType, std::string> entityType = {
110 {PLDM_ENTITY_COMM_CHANNEL, "Communication Channel"},
111 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
112 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
113 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
114 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500115 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
Tom Josepha65c0412020-07-03 21:14:44 +0530116 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
117 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
118 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
119 "Chassis front panel board (control panel)"},
120 {PLDM_ENTITY_POWER_CONVERTER, "Power converter"},
121 {PLDM_ENTITY_PROC, "Processor"},
122 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
123 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500124 {PLDM_ENTITY_FAN, "Fan"},
125 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Deepak Kodihallie05dcc22020-07-14 05:13:58 -0500126 {PLDM_ENTITY_POWER_SUPPLY, "Power Supply"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500127 {PLDM_ENTITY_MEMORY_CHIP, "Memory chip"},
128 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
129 {PLDM_ENTITY_SLOT, "Slot"},
130 {PLDM_ENTITY_CABLE, "Cable (electrical or optical)"},
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500131 {11521, "System (logical)"},
132 };
133
Tom Josepha65c0412020-07-03 21:14:44 +0530134 const std::map<uint16_t, std::string> stateSet = {
135 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
136 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
137 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
138 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
139 "Operational Running Status"},
140 {PLDM_STATE_SET_PRESENCE, "Presence"},
141 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
142 {PLDM_STATE_SET_LINK_STATE, "Link State"},
143 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
144 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
145 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500146 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State"},
Tom Josepha65c0412020-07-03 21:14:44 +0530147 };
148
149 const std::array<std::string_view, 4> sensorInit = {
150 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
151
Tom Joseph97a7a762020-07-06 10:37:18 +0530152 const std::array<std::string_view, 4> effecterInit = {
153 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
154
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500155 const std::map<uint8_t, std::string> pdrType = {
156 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
157 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
158 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
159 "Numeric Sensor Initialization PDR"},
160 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
161 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
162 "State Sensor Initialization PDR"},
163 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
164 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
165 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
166 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
167 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
168 "Numeric Effecter Initialization PDR"},
169 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
170 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
171 "State Effecter Initialization PDR"},
172 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
173 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
174 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
175 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
176 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
177 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
178 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
179 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
180 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
181 {PLDM_OEM_PDR, "OEM PDR"},
182 };
183
Tom Josepha65c0412020-07-03 21:14:44 +0530184 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500185 {
186 try
187 {
188 return entityType.at(type);
189 }
190 catch (const std::out_of_range& e)
191 {
192 return std::to_string(static_cast<unsigned>(type)) + "(OEM)";
193 }
194 }
195
Tom Josepha65c0412020-07-03 21:14:44 +0530196 std::string getStateSetName(uint16_t id)
197 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500198 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530199 try
200 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500201 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530202 }
203 catch (const std::out_of_range& e)
204 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500205 return typeString;
206 }
207 }
208
209 std::string getPDRType(uint8_t type)
210 {
211 auto typeString = std::to_string(type);
212 try
213 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500214 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500215 }
216 catch (const std::out_of_range& e)
217 {
218 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530219 }
220 }
221
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500222 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530223 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500224 output["recordHandle"] = hdr->record_handle;
225 output["PDRHeaderVersion"] = unsigned(hdr->version);
226 output["PDRType"] = getPDRType(hdr->type);
227 output["recordChangeNumber"] = hdr->record_change_num;
228 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530229 }
230
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500231 std::string printPossibleStates(uint8_t possibleStatesSize,
232 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530233 {
234 uint8_t possibleStatesPos{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500235 std::string data;
236 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
237 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530238 for (int i = 0; i < CHAR_BIT; i++)
239 {
240 if (val.byte & (1 << i))
241 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500242 pstates << " " << (possibleStatesPos * CHAR_BIT + i);
243 data.append(pstates.str());
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600244 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530245 }
246 }
247 possibleStatesPos++;
248 };
249 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500250 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530251 }
252
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500253 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530254 {
255 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500256 output["PLDMTerminusHandle"] = pdr->terminus_handle;
257 output["sensorID"] = pdr->sensor_id;
258 output["entityType"] = getEntityName(pdr->entity_type);
259 output["entityInstanceNumber"] = pdr->entity_instance;
260 output["containerID"] = pdr->container_id;
261 output["sensorInit"] = sensorInit[pdr->sensor_init];
262 output["sensorAuxiliaryNamesPDR"] =
263 (pdr->sensor_auxiliary_names_pdr ? true : false);
264 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530265
266 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600267 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530268
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600269 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530270 {
271 auto state = reinterpret_cast<const state_sensor_possible_states*>(
272 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600273 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
274 getStateSetName(state->state_set_id));
275 output.emplace(
276 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
277 state->possible_states_size);
278 output.emplace(
279 ("possibleStates[" + std::to_string(compCount) + "]"),
280 printPossibleStates(state->possible_states_size,
281 state->states));
Tom Josepha65c0412020-07-03 21:14:44 +0530282
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600283 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530284 {
285 statesPtr += sizeof(state_sensor_possible_states) +
286 state->possible_states_size - 1;
287 }
288 }
289 }
290
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500291 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500292 {
George Liu62d12ec2020-02-05 16:27:08 +0800293 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500294 {
295 return;
296 }
297
298 data += sizeof(pldm_pdr_hdr);
299 pldm_pdr_fru_record_set* pdr =
300 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530301 if (!pdr)
302 {
303 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
304 return;
305 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500306
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500307 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
308 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
309 output["entityType"] = getEntityName(pdr->entity_type);
310 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
311 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500312 }
313
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500314 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500315 {
316 const std::map<uint8_t, const char*> assocationType = {
317 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
318 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
319 };
320
George Liu62d12ec2020-02-05 16:27:08 +0800321 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500322 {
323 return;
324 }
325
326 data += sizeof(pldm_pdr_hdr);
327 pldm_pdr_entity_association* pdr =
328 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530329 if (!pdr)
330 {
331 std::cerr << "Failed to get the PDR eneity association"
332 << std::endl;
333 return;
334 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500335
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500336 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800337 if (assocationType.contains(pdr->association_type))
338 {
339 output["associationType"] =
340 assocationType.at(pdr->association_type);
341 }
342 else
343 {
344 std::cout << "Get associationType failed.\n";
345 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500346 output["containerEntityType"] =
347 getEntityName(pdr->container.entity_type);
348 output["containerEntityInstanceNumber"] =
349 int(pdr->container.entity_instance_num);
350 output["containerEntityContainerID"] =
351 int(pdr->container.entity_container_id);
352 output["containedEntityCount"] =
353 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500354
355 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
356 for (int i = 0; i < pdr->num_children; ++i)
357 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500358 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
359 getEntityName(child->entity_type));
360 output.emplace("containedEntityInstanceNumber[" +
361 std::to_string(i + 1) + "]",
362 unsigned(child->entity_instance_num));
363 output.emplace("containedEntityContainerID[" +
364 std::to_string(i + 1) + "]",
365 unsigned(child->entity_container_id));
366
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500367 ++child;
368 }
369 }
370
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500371 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800372 {
373 struct pldm_numeric_effecter_value_pdr* pdr =
374 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530375 if (!pdr)
376 {
377 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
378 return;
379 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500380
381 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
382 output["effecterID"] = int(pdr->effecter_id);
383 output["entityType"] = int(pdr->entity_type);
384 output["entityInstanceNumber"] = int(pdr->entity_instance);
385 output["containerID"] = int(pdr->container_id);
386 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
387 output["effecterInit"] = unsigned(pdr->effecter_init);
388 output["effecterAuxiliaryNames"] =
389 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
390 output["baseUnit"] = unsigned(pdr->base_unit);
391 output["unitModifier"] = unsigned(pdr->unit_modifier);
392 output["rateUnit"] = unsigned(pdr->rate_unit);
393 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
394 output["auxUnit"] = unsigned(pdr->aux_unit);
395 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
396 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
397 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
398 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
399 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
400 output["resolution"] = unsigned(pdr->resolution);
401 output["offset"] = unsigned(pdr->offset);
402 output["accuracy"] = unsigned(pdr->accuracy);
403 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
404 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
405 output["stateTransitionInterval"] =
406 unsigned(pdr->state_transition_interval);
407 output["TransitionInterval"] = unsigned(pdr->transition_interval);
408
George Liu62d12ec2020-02-05 16:27:08 +0800409 switch (pdr->effecter_data_size)
410 {
411 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500412 output["maxSettable"] = unsigned(pdr->max_set_table.value_u8);
413 output["minSettable"] = unsigned(pdr->min_set_table.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800414 break;
415 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500416 output["maxSettable"] = unsigned(pdr->max_set_table.value_s8);
417 output["minSettable"] = unsigned(pdr->min_set_table.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800418 break;
419 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500420 output["maxSettable"] = unsigned(pdr->max_set_table.value_u16);
421 output["minSettable"] = unsigned(pdr->min_set_table.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800422 break;
423 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500424 output["maxSettable"] = unsigned(pdr->max_set_table.value_s16);
425 output["minSettable"] = unsigned(pdr->min_set_table.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800426 break;
427 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500428 output["maxSettable"] = unsigned(pdr->max_set_table.value_u32);
429 output["minSettable"] = unsigned(pdr->min_set_table.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800430 break;
431 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500432 output["maxSettable"] = unsigned(pdr->max_set_table.value_s32);
433 output["minSettable"] = unsigned(pdr->min_set_table.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800434 break;
435 default:
436 break;
437 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500438
439 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
440 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
441
George Liu62d12ec2020-02-05 16:27:08 +0800442 switch (pdr->range_field_format)
443 {
444 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500445 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
446 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
447 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
448 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
449 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800450 break;
451 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500452 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
453 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
454 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
455 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
456 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800457 break;
458 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500459 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
460 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
461 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
462 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
463 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800464 break;
465 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500466 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
467 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
468 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
469 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
470 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800471 break;
472 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500473 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
474 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
475 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
476 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
477 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800478 break;
479 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500480 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
481 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
482 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
483 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
484 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800485 break;
486 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500487 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
488 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
489 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
490 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
491 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800492 break;
493 default:
494 break;
495 }
496 }
497
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500498 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800499 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530500 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800501
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500502 output["PLDMTerminusHandle"] = pdr->terminus_handle;
503 output["effecterID"] = pdr->effecter_id;
504 output["entityType"] = getEntityName(pdr->entity_type);
505 output["entityInstanceNumber"] = pdr->entity_instance;
506 output["containerID"] = pdr->container_id;
507 output["effecterSemanticID"] = pdr->effecter_semantic_id;
508 output["effecterInit"] = effecterInit[pdr->effecter_init];
509 output["effecterDescriptionPDR"] =
510 (pdr->has_description_pdr ? true : false);
511 output["compositeEffecterCount"] =
512 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +0800513
Tom Joseph97a7a762020-07-06 10:37:18 +0530514 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600515 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +0530516
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600517 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +0800518 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530519 auto state =
520 reinterpret_cast<const state_effecter_possible_states*>(
521 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600522 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
523 getStateSetName(state->state_set_id));
524 output.emplace(
525 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
526 state->possible_states_size);
527 output.emplace(
528 ("possibleStates[" + std::to_string(compEffCount) + "]"),
529 printPossibleStates(state->possible_states_size,
530 state->states));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500531
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600532 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +0530533 {
534 statesPtr += sizeof(state_effecter_possible_states) +
535 state->possible_states_size - 1;
536 }
George Liud6649362019-11-27 19:06:51 +0800537 }
538 }
539
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500540 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -0500541 {
542 const std::array<std::string_view, 4> terminusLocatorType = {
543 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
544
545 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
546
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500547 output["PLDMTerminusHandle"] = pdr->terminus_handle;
548 output["validity"] = (pdr->validity ? "valid" : "notValid");
549 output["TID"] = unsigned(pdr->tid);
550 output["containerID"] = pdr->container_id;
551 output["terminusLocatorType"] =
552 terminusLocatorType[pdr->terminus_locator_type];
553 output["terminusLocatorValueSize"] =
554 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -0500555
556 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
557 {
558 auto locatorValue =
559 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
560 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500561 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -0500562 }
563 }
564
George Liud6649362019-11-27 19:06:51 +0800565 void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt,
George Liu62d12ec2020-02-05 16:27:08 +0800566 uint8_t* data)
George Liud6649362019-11-27 19:06:51 +0800567 {
George Liu62d12ec2020-02-05 16:27:08 +0800568 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800569 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530570 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +0800571 return;
572 }
573
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500574 ordered_json output;
575 output["nextRecordHandle"] = nextRecordHndl;
576 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +0800577
578 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530579 if (!pdr)
580 {
581 return;
582 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500583 printCommonPDRHeader(pdr, output);
584
George Liud6649362019-11-27 19:06:51 +0800585 switch (pdr->type)
586 {
Sampa Misra12afe112020-05-25 11:40:44 -0500587 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500588 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -0500589 break;
Tom Josepha65c0412020-07-03 21:14:44 +0530590 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500591 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +0530592 break;
George Liu62d12ec2020-02-05 16:27:08 +0800593 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500594 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +0800595 break;
George Liud6649362019-11-27 19:06:51 +0800596 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500597 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +0800598 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500599 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500600 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500601 break;
602 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500603 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500604 break;
George Liud6649362019-11-27 19:06:51 +0800605 default:
606 break;
607 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500608 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +0800609 }
610
611 private:
612 uint32_t recordHandle;
613};
614
615class SetStateEffecter : public CommandInterface
616{
617 public:
618 ~SetStateEffecter() = default;
619 SetStateEffecter() = delete;
620 SetStateEffecter(const SetStateEffecter&) = delete;
621 SetStateEffecter(SetStateEffecter&&) = default;
622 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
623 SetStateEffecter& operator=(SetStateEffecter&&) = default;
624
George Liuba4c1fb2020-02-05 14:13:30 +0800625 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
626 static constexpr auto maxEffecterDataSize = 16;
627
628 // compositeEffecterCount(value: 0x01 to 0x08)
629 static constexpr auto minEffecterCount = 1;
630 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +0800631 explicit SetStateEffecter(const char* type, const char* name,
632 CLI::App* app) :
633 CommandInterface(type, name, app)
634 {
635 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +0800636 "-i, --id", effecterId,
637 "A handle that is used to identify and access the effecter")
638 ->required();
639 app->add_option("-c, --count", effecterCount,
640 "The number of individual sets of effecter information")
641 ->required();
642 app->add_option(
George Liud6649362019-11-27 19:06:51 +0800643 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +0800644 "Set effecter state data\n"
645 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
646 ->required();
George Liud6649362019-11-27 19:06:51 +0800647 }
648
649 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
650 {
651 std::vector<uint8_t> requestMsg(
652 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
653 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
654
George Liuba4c1fb2020-02-05 14:13:30 +0800655 if (effecterCount > maxEffecterCount ||
656 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +0800657 {
George Liuba4c1fb2020-02-05 14:13:30 +0800658 std::cerr << "Request Message Error: effecterCount size "
659 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +0800660 auto rc = PLDM_ERROR_INVALID_DATA;
661 return {rc, requestMsg};
662 }
663
George Liuba4c1fb2020-02-05 14:13:30 +0800664 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +0800665 {
George Liuba4c1fb2020-02-05 14:13:30 +0800666 std::cerr << "Request Message Error: effecterData size "
667 << effecterData.size() << "is invalid\n";
668 auto rc = PLDM_ERROR_INVALID_DATA;
669 return {rc, requestMsg};
670 }
671
672 auto stateField = parseEffecterData(effecterData, effecterCount);
673 if (!stateField)
674 {
675 std::cerr << "Failed to parse effecter data, effecterCount size "
676 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +0800677 auto rc = PLDM_ERROR_INVALID_DATA;
678 return {rc, requestMsg};
679 }
680
681 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600682 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +0800683 return {rc, requestMsg};
684 }
685
686 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
687 {
688 uint8_t completionCode = 0;
689 auto rc = decode_set_state_effecter_states_resp(
690 responsePtr, payloadLength, &completionCode);
691
692 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
693 {
694 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +0800695 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +0800696 return;
697 }
698
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500699 ordered_json data;
700 data["Response"] = "SUCCESS";
701 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +0800702 }
703
704 private:
George Liuba4c1fb2020-02-05 14:13:30 +0800705 uint16_t effecterId;
706 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +0800707 std::vector<uint8_t> effecterData;
708};
709
George Liucc9c20d2020-02-05 10:24:11 +0800710class SetNumericEffecterValue : public CommandInterface
711{
712 public:
713 ~SetNumericEffecterValue() = default;
714 SetNumericEffecterValue() = delete;
715 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
716 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
717 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
718 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default;
719
720 explicit SetNumericEffecterValue(const char* type, const char* name,
721 CLI::App* app) :
722 CommandInterface(type, name, app)
723 {
724 app->add_option(
725 "-i, --id", effecterId,
726 "A handle that is used to identify and access the effecter")
727 ->required();
728 app->add_option("-s, --size", effecterDataSize,
729 "The bit width and format of the setting value for the "
730 "effecter. enum value: {uint8, sint8, uint16, sint16, "
731 "uint32, sint32}\n")
732 ->required();
733 app->add_option("-d,--data", maxEffecterValue,
734 "The setting value of numeric effecter being "
735 "requested\n")
736 ->required();
737 }
738
739 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
740 {
741 std::vector<uint8_t> requestMsg(
742 sizeof(pldm_msg_hdr) +
743 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
744
745 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
746
747 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
748 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
749
750 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
751 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
752 {
753 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
754 }
755 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
756 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
757 {
758 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
759 }
760 auto rc = encode_set_numeric_effecter_value_req(
761 0, effecterId, effecterDataSize, effecterValue, request,
762 payload_length);
763
764 return {rc, requestMsg};
765 }
766
767 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
768 {
769 uint8_t completionCode = 0;
770 auto rc = decode_set_numeric_effecter_value_resp(
771 responsePtr, payloadLength, &completionCode);
772
773 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
774 {
775 std::cerr << "Response Message Error: "
776 << "rc=" << rc << ",cc=" << (int)completionCode
777 << std::endl;
778 return;
779 }
780
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500781 ordered_json data;
782 data["Response"] = "SUCCESS";
783 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +0800784 }
785
786 private:
787 uint16_t effecterId;
788 uint8_t effecterDataSize;
789 uint64_t maxEffecterValue;
790};
791
Sridevi Rameshf31b5042021-01-22 05:42:07 -0600792class GetStateSensorReadings : public CommandInterface
793{
794 public:
795 ~GetStateSensorReadings() = default;
796 GetStateSensorReadings() = delete;
797 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
798 GetStateSensorReadings(GetStateSensorReadings&&) = default;
799 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
800 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default;
801
802 explicit GetStateSensorReadings(const char* type, const char* name,
803 CLI::App* app) :
804 CommandInterface(type, name, app)
805 {
806 app->add_option(
807 "-i, --sensor_id", sensorId,
808 "Sensor ID that is used to identify and access the sensor")
809 ->required();
810 app->add_option("-r, --rearm", sensorRearm,
811 "Each bit location in this field corresponds to a "
812 "particular sensor")
813 ->required();
814 }
815
816 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
817 {
818 std::vector<uint8_t> requestMsg(
819 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
820 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
821
822 uint8_t reserved = 0;
823 bitfield8_t bf;
824 bf.byte = sensorRearm;
825 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
826 reserved, request);
827
828 return {rc, requestMsg};
829 }
830
831 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
832 {
833 uint8_t completionCode = 0;
834 uint8_t compSensorCount = 0;
835 std::array<get_sensor_state_field, 8> stateField{};
836 auto rc = decode_get_state_sensor_readings_resp(
837 responsePtr, payloadLength, &completionCode, &compSensorCount,
838 stateField.data());
839
840 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
841 {
842 std::cerr << "Response Message Error: "
843 << "rc=" << rc << ",cc=" << (int)completionCode
844 << std::endl;
845 return;
846 }
847 ordered_json output;
848 output["compositeSensorCount"] = (int)compSensorCount;
849
850 for (size_t i = 0; i < compSensorCount; i++)
851 {
George Liubd5e2ea2021-04-22 20:33:06 +0800852 if (sensorOpState.contains(stateField[i].sensor_op_state))
853 {
854 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
855 sensorOpState.at(stateField[i].sensor_op_state));
856 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -0600857
George Liubd5e2ea2021-04-22 20:33:06 +0800858 if (sensorPresState.contains(stateField[i].present_state))
859 {
860 output.emplace(("presentState[" + std::to_string(i) + "]"),
861 sensorPresState.at(stateField[i].present_state));
862 }
863
864 if (sensorPresState.contains(stateField[i].previous_state))
865 {
866 output.emplace(
867 ("previousState[" + std::to_string(i) + "]"),
868 sensorPresState.at(stateField[i].previous_state));
869 }
870
871 if (sensorPresState.contains(stateField[i].event_state))
872 {
873 output.emplace(("eventState[" + std::to_string(i) + "]"),
874 sensorPresState.at(stateField[i].event_state));
875 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -0600876 }
877
878 pldmtool::helper::DisplayInJson(output);
879 }
880
881 private:
882 uint16_t sensorId;
883 uint8_t sensorRearm;
884};
885
George Liud6649362019-11-27 19:06:51 +0800886void registerCommand(CLI::App& app)
887{
888 auto platform = app.add_subcommand("platform", "platform type command");
889 platform->require_subcommand(1);
890
891 auto getPDR =
892 platform->add_subcommand("GetPDR", "get platform descriptor records");
893 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
894
895 auto setStateEffecterStates = platform->add_subcommand(
896 "SetStateEffecterStates", "set effecter states");
897 commands.push_back(std::make_unique<SetStateEffecter>(
898 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +0800899
900 auto setNumericEffecterValue = platform->add_subcommand(
901 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
902 commands.push_back(std::make_unique<SetNumericEffecterValue>(
903 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -0600904
905 auto getStateSensorReadings = platform->add_subcommand(
906 "GetStateSensorReadings", "get the state sensor readings");
907 commands.push_back(std::make_unique<GetStateSensorReadings>(
908 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +0800909}
910
911} // namespace platform
912} // namespace pldmtool