blob: af2237066e8e2abe35f78a71be4e8bcc17ea4ebf [file] [log] [blame]
Tom Josepha65c0412020-07-03 21:14:44 +05301#include "common/types.hpp"
George Liud6649362019-11-27 19:06:51 +08002#include "pldm_cmd_helper.hpp"
3
George Liuc453e162022-12-21 17:16:23 +08004#include <libpldm/entity.h>
Thu Nguyen846d38f2022-03-26 08:57:21 +07005#include <libpldm/platform.h>
George Liuc453e162022-12-21 17:16:23 +08006#include <libpldm/state_set.h>
7
Thu Nguyen846d38f2022-03-26 08:57:21 +07008#include <algorithm>
Brad Bishop02d71142021-10-14 19:00:17 -04009#include <cstddef>
Tal Yacobi8570fcc2024-05-28 11:11:23 +030010#include <format>
Brad Bishop02d71142021-10-14 19:00:17 -040011#include <map>
Tal Yacobi8570fcc2024-05-28 11:11:23 +030012#include <memory>
Thu Nguyen846d38f2022-03-26 08:57:21 +070013#include <ranges>
Brad Bishop02d71142021-10-14 19:00:17 -040014
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -050015#ifdef OEM_IBM
16#include "oem/ibm/oem_ibm_state_set.hpp"
17#endif
18
Brad Bishop5079ac42021-08-19 18:35:06 -040019using namespace pldm::utils;
20
George Liud6649362019-11-27 19:06:51 +080021namespace pldmtool
22{
George Liud6649362019-11-27 19:06:51 +080023namespace platform
24{
George Liud6649362019-11-27 19:06:51 +080025namespace
26{
George Liud6649362019-11-27 19:06:51 +080027using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060028
29static const std::map<uint8_t, std::string> sensorPresState{
30 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
31 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
32 {PLDM_SENSOR_WARNING, "Sensor Warning"},
33 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
34 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
35 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
36 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
37 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
38 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
39 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
40 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
41
42static const std::map<uint8_t, std::string> sensorOpState{
43 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
44 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
45 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
46 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
47 {PLDM_SENSOR_FAILED, "Sensor Failed"},
Manojkiran Eda2576aec2024-06-17 12:05:17 +053048 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Initializing"},
Sridevi Rameshf31b5042021-01-22 05:42:07 -060049 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
50 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
51
Tal Yacobi8570fcc2024-05-28 11:11:23 +030052const std::map<uint8_t, std::string> effecterOpState{
53 {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING,
54 "Effecter Enabled Update Pending"},
55 {EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING,
56 "Effecter Enabled No Update Pending"},
57 {EFFECTER_OPER_STATE_DISABLED, "Effecter Disabled"},
58 {EFFECTER_OPER_STATE_UNAVAILABLE, "Effecter Unavailable"},
59 {EFFECTER_OPER_STATE_STATUSUNKNOWN, "Effecter Status Unknown"},
60 {EFFECTER_OPER_STATE_FAILED, "Effecter Failed"},
61 {EFFECTER_OPER_STATE_INITIALIZING, "Effecter Initializing"},
62 {EFFECTER_OPER_STATE_SHUTTINGDOWN, "Effecter Shutting Down"},
63 {EFFECTER_OPER_STATE_INTEST, "Effecter In Test"}};
64
65std::string getEffecterOpState(uint8_t state)
66{
67 return effecterOpState.contains(state) ? effecterOpState.at(state)
68 : std::to_string(state);
69}
70
George Liud6649362019-11-27 19:06:51 +080071std::vector<std::unique_ptr<CommandInterface>> commands;
72
73} // namespace
74
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050075using ordered_json = nlohmann::ordered_json;
76
Roger G. Coscojuela4aea4bd2025-03-18 15:51:55 +010077class GetEventReceiver : public CommandInterface
78{
79 public:
80 ~GetEventReceiver() = default;
81 GetEventReceiver() = delete;
82 GetEventReceiver(const GetEventReceiver&) = delete;
83 GetEventReceiver(GetEventReceiver&&) = default;
84 GetEventReceiver& operator=(const GetEventReceiver&) = delete;
85 GetEventReceiver& operator=(GetEventReceiver&&) = delete;
86
87 explicit GetEventReceiver(const char* type, const char* name,
88 CLI::App* app) : CommandInterface(type, name, app)
89 {}
90 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
91 {
92 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
93 auto request = new (requestMsg.data()) pldm_msg;
94 auto rc =
95 encode_pldm_header_only(PLDM_REQUEST, instanceId, PLDM_PLATFORM,
96 PLDM_GET_EVENT_RECEIVER, request);
97 if (rc != PLDM_SUCCESS)
98 {
99 std::cerr << "Failed to encode_pldm_header_only, return code " << rc
100 << std::endl;
101 }
102 return {rc, requestMsg};
103 }
104 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
105 {
106 struct pldm_get_event_receiver_resp event_receiver_resp_data;
107 auto rc = decode_get_event_receiver_resp(responsePtr, payloadLength,
108 &event_receiver_resp_data);
109 if (rc || event_receiver_resp_data.completion_code)
110 {
111 std::cerr << "Response Message Error: "
112 << "return code " << rc << ", completion code "
113 << static_cast<int>(
114 event_receiver_resp_data.completion_code)
115 << std::endl;
116 return;
117 }
118 if (event_receiver_resp_data.transport_protocol_type !=
119 PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP)
120 {
121 std::cerr << "Unsupported response protocol type " << std::endl;
122 return;
123 }
124
125 ordered_json data;
126 data["completionCode"] = event_receiver_resp_data.completion_code;
127 data["transportProtocolType"] =
128 event_receiver_resp_data.transport_protocol_type;
129 data["eventReceiverAddressInfo"] =
130 event_receiver_resp_data.event_receiver_address.mctp_eid;
131 pldmtool::helper::DisplayInJson(data);
132 }
133};
134
George Liud6649362019-11-27 19:06:51 +0800135class GetPDR : public CommandInterface
136{
137 public:
138 ~GetPDR() = default;
139 GetPDR() = delete;
140 GetPDR(const GetPDR&) = delete;
141 GetPDR(GetPDR&&) = default;
142 GetPDR& operator=(const GetPDR&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500143 GetPDR& operator=(GetPDR&&) = delete;
George Liud6649362019-11-27 19:06:51 +0800144
145 using CommandInterface::CommandInterface;
146
George Liud6649362019-11-27 19:06:51 +0800147 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
Potin Lai3e52d582024-06-13 11:03:46 +0800148 CommandInterface(type, name, app), dataTransferHandle(0),
149 operationFlag(PLDM_GET_FIRSTPART), requestCount(UINT16_MAX),
150 recordChangeNumber(0), nextPartRequired(false)
George Liud6649362019-11-27 19:06:51 +0800151 {
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500152 auto pdrOptionGroup = app->add_option_group(
153 "Required Option",
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600154 "Retrieve individual PDR, all PDRs, PDRs of a requested type or retrieve all PDRs of the requested terminusID");
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500155 pdrOptionGroup->add_option(
156 "-d,--data", recordHandle,
157 "retrieve individual PDRs from a PDR Repository\n"
158 "eg: The recordHandle value for the PDR to be retrieved and 0 "
159 "means get first PDR in the repository.");
160 pdrRecType = "";
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400161 pdrOptionGroup->add_option(
162 "-t, --type", pdrRecType,
163 "retrieve all PDRs of the requested type\n"
164 "supported types:\n"
165 "[terminusLocator, stateSensor, "
166 "numericEffecter, stateEffecter, "
167 "compactNumericSensor, sensorauxname, "
168 "efffecterAuxName, numericsensor, "
169 "EntityAssociation, fruRecord, ... ]");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600170
171 getPDRGroupOption = pdrOptionGroup->add_option(
172 "-i, --terminusID", pdrTerminus,
173 "retrieve all PDRs of the requested terminusID\n"
174 "supported IDs:\n [1, 2, 208...]");
175
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500176 allPDRs = false;
177 pdrOptionGroup->add_flag("-a, --all", allPDRs,
178 "retrieve all PDRs from a PDR repository");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600179
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500180 pdrOptionGroup->require_option(1);
181 }
182
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600183 void parseGetPDROptions()
184 {
185 optTIDSet = false;
186 if (getPDRGroupOption->count() > 0)
187 {
188 optTIDSet = true;
189 getPDRs();
190 }
191 }
192
193 void getPDRs()
194 {
195 // start the array
196 std::cout << "[";
197
198 recordHandle = 0;
199 do
200 {
201 CommandInterface::exec();
202 } while (recordHandle != 0);
203
204 // close the array
205 std::cout << "]\n";
206
207 if (handleFound)
208 {
209 recordHandle = 0;
210 uint32_t prevRecordHandle = 0;
211 do
212 {
213 CommandInterface::exec();
214 if (recordHandle == prevRecordHandle)
215 {
216 return;
217 }
218 prevRecordHandle = recordHandle;
219 } while (recordHandle != 0);
220 }
221 }
222
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500223 void exec() override
224 {
225 if (allPDRs || !pdrRecType.empty())
226 {
227 if (!pdrRecType.empty())
228 {
229 std::transform(pdrRecType.begin(), pdrRecType.end(),
230 pdrRecType.begin(), tolower);
231 }
232
Brad Bishop16eff862021-10-14 19:44:32 -0400233 // start the array
234 std::cout << "[\n";
235
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500236 // Retrieve all PDR records starting from the first
237 recordHandle = 0;
238 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400239 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500240 do
241 {
242 CommandInterface::exec();
243 // recordHandle is updated to nextRecord when
244 // CommandInterface::exec() is successful.
245 // In case of any error, return.
Potin Lai3e52d582024-06-13 11:03:46 +0800246 if (recordHandle == prevRecordHandle && !nextPartRequired)
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500247 {
248 return;
249 }
Brad Bishop02d71142021-10-14 19:00:17 -0400250
251 // check for circular references.
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400252 auto result =
253 recordsSeen.emplace(recordHandle, prevRecordHandle);
Potin Lai3e52d582024-06-13 11:03:46 +0800254 if (!result.second && !nextPartRequired)
Brad Bishop02d71142021-10-14 19:00:17 -0400255 {
256 std::cerr
257 << "Record handle " << recordHandle
258 << " has multiple references: " << result.first->second
259 << ", " << prevRecordHandle << "\n";
260 return;
261 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500262 prevRecordHandle = recordHandle;
Brad Bishop16eff862021-10-14 19:44:32 -0400263
264 if (recordHandle != 0)
265 {
266 // close the array
267 std::cout << ",";
268 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500269 } while (recordHandle != 0);
Brad Bishop16eff862021-10-14 19:44:32 -0400270
271 // close the array
272 std::cout << "]\n";
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500273 }
274 else
275 {
Potin Lai3e52d582024-06-13 11:03:46 +0800276 do
277 {
278 CommandInterface::exec();
279 } while (nextPartRequired);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500280 }
George Liud6649362019-11-27 19:06:51 +0800281 }
282
283 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
284 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400285 std::vector<uint8_t> requestMsg(
286 sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530287 auto request = new (requestMsg.data()) pldm_msg;
George Liud6649362019-11-27 19:06:51 +0800288
Potin Lai3e52d582024-06-13 11:03:46 +0800289 auto rc = encode_get_pdr_req(
290 instanceId, recordHandle, dataTransferHandle, operationFlag,
291 requestCount, recordChangeNumber, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800292 return {rc, requestMsg};
293 }
294
295 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
296 {
297 uint8_t completionCode = 0;
Potin Lai3e52d582024-06-13 11:03:46 +0800298 uint8_t respRecordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800299 uint32_t nextRecordHndl = 0;
300 uint32_t nextDataTransferHndl = 0;
301 uint8_t transferFlag = 0;
302 uint16_t respCnt = 0;
303 uint8_t transferCRC = 0;
304
305 auto rc = decode_get_pdr_resp(
306 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
Potin Lai3e52d582024-06-13 11:03:46 +0800307 &nextDataTransferHndl, &transferFlag, &respCnt, respRecordData,
308 sizeof(respRecordData), &transferCRC);
George Liud6649362019-11-27 19:06:51 +0800309
310 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
311 {
312 std::cerr << "Response Message Error: "
313 << "rc=" << rc << ",cc=" << (int)completionCode
314 << std::endl;
Potin Lai3e52d582024-06-13 11:03:46 +0800315 nextPartRequired = false;
George Liud6649362019-11-27 19:06:51 +0800316 return;
317 }
318
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600319 if (optTIDSet && !handleFound)
320 {
Potin Lai3e52d582024-06-13 11:03:46 +0800321 terminusHandle = getTerminusHandle(respRecordData, pdrTerminus);
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600322 if (terminusHandle.has_value())
323 {
324 recordHandle = 0;
325 return;
326 }
327 else
328 {
329 recordHandle = nextRecordHndl;
330 return;
331 }
332 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600333 else
334 {
Potin Lai3e52d582024-06-13 11:03:46 +0800335 recordData.insert(recordData.end(), respRecordData,
336 respRecordData + respCnt);
337
338 // End or StartAndEnd
339 if (transferFlag == PLDM_PLATFORM_TRANSFER_END ||
340 transferFlag == PLDM_PLATFORM_TRANSFER_START_AND_END)
341 {
342 printPDRMsg(nextRecordHndl, respCnt, recordData.data(),
343 terminusHandle);
344 nextPartRequired = false;
345 recordHandle = nextRecordHndl;
346 dataTransferHandle = 0;
347 recordChangeNumber = 0;
348 operationFlag = PLDM_GET_FIRSTPART;
349 recordData.clear();
350 }
351 else
352 {
353 nextPartRequired = true;
354 dataTransferHandle = nextDataTransferHndl;
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530355 struct pldm_pdr_hdr* pdr_hdr = new (respRecordData)
356 pldm_pdr_hdr;
Potin Lai3e52d582024-06-13 11:03:46 +0800357 recordChangeNumber = pdr_hdr->record_change_num;
358 operationFlag = PLDM_GET_NEXTPART;
359 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600360 }
George Liud6649362019-11-27 19:06:51 +0800361 }
362
363 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530364 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530365 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
366 {PLDM_ENTITY_OTHER, "Other"},
367 {PLDM_ENTITY_NETWORK, "Network"},
368 {PLDM_ENTITY_GROUP, "Group"},
369 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
370 "Remote Management Communication Device"},
371 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
372 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
373 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
374 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
375 {PLDM_ENTITY_KEYPAD, "keypad"},
376 {PLDM_ENTITY_SWITCH, "Switch"},
377 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
378 {PLDM_ENTITY_DISPLAY, "Display"},
379 {PLDM_ENTITY_INDICATOR, "Indicator"},
380 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530381 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530382 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530383 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530384 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
385 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
386 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530387 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530388 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
389 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
390 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
391 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
392 {PLDM_ENTITY_DOOR, "Door"},
393 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
394 {PLDM_ENTITY_COVER, "Cover"},
395 {PLDM_ENTITY_BOARD, "Board"},
396 {PLDM_ENTITY_CARD, "Card"},
397 {PLDM_ENTITY_MODULE, "Module"},
398 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530399 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530400 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530401 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
402 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530403 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530404 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530405 "Chassis front panel board(control panel)"},
406 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
407 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
408 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
409 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
410 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
411 "System internal expansion board"},
412 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
413 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
414 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
415 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
416 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
417 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
418 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
419 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
420 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
421 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500422 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530423 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
424 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
425 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
426 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
427 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
428 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
429 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
430 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
431 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
432 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500433 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530434 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
435 {PLDM_ENTITY_BATTERY, "Battery"},
436 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
437 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
438 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
439 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
440 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
441 {PLDM_ENTITY_PROC, "Processor"},
442 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
443 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
444 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
445 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
446 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
447 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
448 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
449 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
450 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
451 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
452 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500453 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530454 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
455 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
456 {PLDM_ENTITY_SYS_BUS, "System Bus"},
457 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
458 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
459 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
460 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
461 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
462 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
463 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
464 {PLDM_ENTITY_USB_BUS, "USB Bus"},
465 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
466 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
467 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
468 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
469 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
470 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500471 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530472 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
473 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
474 {PLDM_ENTITY_PLUG, "Plug"},
475 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500476 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500477
Tom Josepha65c0412020-07-03 21:14:44 +0530478 const std::map<uint16_t, std::string> stateSet = {
479 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
480 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530481 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
482 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
483 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
484 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
485 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530486 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530487 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
488 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530489 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
490 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530491 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
492 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530493 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530494 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530495 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530496 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
497 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
498 {PLDM_STATE_SET_VERSION, "Version"},
499 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
500 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
501 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
502 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530503 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530504 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
505 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
506 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
507 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
508 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
509 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
510 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
511 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
512 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
513 "Physical Communication Connection"},
514 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
515 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
516 "Foreign Network Detection Status"},
517 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
518 "Password-Protected Access Security"},
519 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
520 "Security Access –PrivilegeLevel"},
521 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530522 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530523 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530524 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530525 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
526 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
527 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530528 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530529 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
530 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
531 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
532 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
533 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
534 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
535 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
536 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
537 "Diagnostic Interrupt Requested"},
538 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
539 "Diagnostic Interrupt Received"},
540 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
541 "I/O Channel Check NMI Requested"},
542 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
543 "I/O Channel Check NMI Received"},
544 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
545 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
546 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
547 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
548 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
549 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
550 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
551 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
552 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
553 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
554 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
555 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
556 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
557 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
558 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
559 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
560 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
561 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
562 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
563 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
564 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
565 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
566 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
567 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
568 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
569 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
570 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
571 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
572 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
573 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
574 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
575 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
576 "Redundant Memory Activity Status"},
577 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
578 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
579 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
580 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500581 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
582 };
Tom Josepha65c0412020-07-03 21:14:44 +0530583
584 const std::array<std::string_view, 4> sensorInit = {
585 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
586
Tom Joseph97a7a762020-07-06 10:37:18 +0530587 const std::array<std::string_view, 4> effecterInit = {
588 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
589
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500590 const std::map<uint8_t, std::string> pdrType = {
591 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
592 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
593 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
594 "Numeric Sensor Initialization PDR"},
595 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
596 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
597 "State Sensor Initialization PDR"},
598 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
599 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
600 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
601 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
602 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
603 "Numeric Effecter Initialization PDR"},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700604 {PLDM_COMPACT_NUMERIC_SENSOR_PDR, "Compact Numeric Sensor PDR"},
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500605 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
606 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
607 "State Effecter Initialization PDR"},
608 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
609 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
610 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
611 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
612 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
613 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
614 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
615 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
616 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
617 {PLDM_OEM_PDR, "OEM PDR"},
618 };
619
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500620 static inline const std::map<uint8_t, std::string> setThermalTrip{
621 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
622 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
623
624 static inline const std::map<uint8_t, std::string> setIdentifyState{
625 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
626 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
627
628 static inline const std::map<uint8_t, std::string> setBootProgressState{
629 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
630 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
631 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
632 "Memory Initialization"},
633 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
634 "Secondary Processor(s) Initialization"},
635 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
636 "PCI Resource Configuration"},
637 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
638 "Starting Operating System"},
639 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
640 "Baseboard Initialization"},
641 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
kamal00a076d2022-11-08 04:24:36 -0600642 "Primary Processor Initialization"},
643 {PLDM_STATE_SET_BOOT_PROG_STATE_OSSTART, "OSStart"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500644
645 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -0500646 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
647 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_ERROR, "Error"},
648 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NON_RECOVERABLE_ERROR,
649 "Non Recoverable Error"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500650
651 static inline const std::map<uint8_t, std::string> setSysPowerState{
652 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
653 "Off-Soft Graceful"}};
654
655 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
656 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
657 "Graceful Restart Requested"}};
658
659 static inline const std::map<uint8_t, std::string> setAvailability{
660 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
661
662 static inline const std::map<uint8_t, std::string> setHealthState{
663 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530664 {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"},
665 {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"},
666 {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"},
667 {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"},
668 {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500669 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530670 {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"},
671 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"},
672 {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}};
673
674 static inline const std::map<uint8_t, std::string>
675 setOperationalRunningState{
676 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"},
677 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"},
678 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"},
679 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE,
680 "In Service"},
681 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"},
682 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500683
Riya Dixit43e33d22024-02-07 09:53:49 -0600684 static inline const std::map<uint8_t, std::string> setPowerDeviceState{
685 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_UNKNOWN, "Unknown"},
686 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_FULLY_ON, "Fully-On"},
687 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_1,
688 "Intermediate State-1"},
689 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_2,
690 "Intermediate State-2"},
691 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_OFF, "Off"}};
692
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500693 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
694 populatePStateMaps{
695 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
696 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
697 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
698 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
699 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
700 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
701 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
702 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530703 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
704 setOperationalRunningState},
Riya Dixit43e33d22024-02-07 09:53:49 -0600705 {PLDM_STATE_SET_DEVICE_POWER_STATE, setPowerDeviceState},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500706 };
707
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500708 const std::map<std::string, uint8_t> strToPdrType = {
709 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
710 {"statesensor", PLDM_STATE_SENSOR_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700711 {"sensorauxname", PLDM_SENSOR_AUXILIARY_NAMES_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500712 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700713 {"efffecterauxname", PLDM_EFFECTER_AUXILIARY_NAMES_PDR},
nothingIIersonalcea52d92024-03-21 13:56:02 +0300714 {"numericsensor", PLDM_NUMERIC_SENSOR_PDR},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700715 {"compactnumericsensor", PLDM_COMPACT_NUMERIC_SENSOR_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500716 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
717 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
718 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
719 // Add other types
720 };
721
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530722 bool isLogicalBitSet(const uint16_t entity_type)
723 {
724 return entity_type & 0x8000;
725 }
726
727 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
728 {
729 return logical_entity_type & 0x7FFF;
730 }
731
Tom Josepha65c0412020-07-03 21:14:44 +0530732 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500733 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530734 uint16_t entityNumber = type;
735 std::string entityName = "[Physical] ";
736
737 if (isLogicalBitSet(type))
738 {
739 entityName = "[Logical] ";
740 entityNumber = getEntityTypeForLogicalEntity(type);
741 }
742
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500743 try
744 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530745 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500746 }
747 catch (const std::out_of_range& e)
748 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500749 auto OemString =
750 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530751 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
752 type <= PLDM_OEM_ENTITY_TYPE_END)
753 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500754#ifdef OEM_IBM
755 if (OemIBMEntityType.contains(entityNumber))
756 {
757 return entityName + OemIBMEntityType.at(entityNumber) +
758 "(OEM)";
759 }
760#endif
761 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530762 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500763 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500764 }
765 }
766
Tom Josepha65c0412020-07-03 21:14:44 +0530767 std::string getStateSetName(uint16_t id)
768 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500769 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530770 try
771 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500772 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530773 }
774 catch (const std::out_of_range& e)
775 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500776 return typeString;
777 }
778 }
779
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400780 std::vector<std::string> getStateSetPossibleStateNames(
781 uint16_t stateId, const std::vector<uint8_t>& value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500782 {
783 std::vector<std::string> data{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500784
Pavithra Barithaya15b94112024-04-10 02:42:12 -0500785 for (const auto& s : value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500786 {
787 std::map<uint8_t, std::string> stateNameMaps;
788 auto pstr = std::to_string(s);
789
790#ifdef OEM_IBM
Manojkiran Edabe1a8572022-01-06 11:20:36 +0530791 if (stateId >= PLDM_OEM_STATE_SET_ID_START &&
792 stateId < PLDM_OEM_STATE_SET_ID_END)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500793 {
794 if (populateOemIBMStateMaps.contains(stateId))
795 {
796 const std::map<uint8_t, std::string> stateNames =
797 populateOemIBMStateMaps.at(stateId);
798 stateNameMaps.insert(stateNames.begin(), stateNames.end());
799 }
800 }
801#endif
802 if (populatePStateMaps.contains(stateId))
803 {
804 const std::map<uint8_t, std::string> stateNames =
805 populatePStateMaps.at(stateId);
806 stateNameMaps.insert(stateNames.begin(), stateNames.end());
807 }
808 if (stateNameMaps.contains(s))
809 {
810 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
811 }
812 else
813 {
814 data.push_back(pstr);
815 }
816 }
817 return data;
818 }
819
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500820 std::string getPDRType(uint8_t type)
821 {
822 auto typeString = std::to_string(type);
823 try
824 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500825 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500826 }
827 catch (const std::out_of_range& e)
828 {
829 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530830 }
831 }
832
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500833 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530834 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500835 output["recordHandle"] = hdr->record_handle;
836 output["PDRHeaderVersion"] = unsigned(hdr->version);
837 output["PDRType"] = getPDRType(hdr->type);
838 output["recordChangeNumber"] = hdr->record_change_num;
839 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530840 }
841
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500842 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
843 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530844 {
845 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500846 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500847 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
848 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530849 for (int i = 0; i < CHAR_BIT; i++)
850 {
851 if (val.byte & (1 << i))
852 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500853 pstates << (possibleStatesPos * CHAR_BIT + i);
854 data.push_back(
855 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600856 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530857 }
858 }
859 possibleStatesPos++;
860 };
861 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500862 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530863 }
864
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500865 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530866 {
867 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500868 output["PLDMTerminusHandle"] = pdr->terminus_handle;
869 output["sensorID"] = pdr->sensor_id;
870 output["entityType"] = getEntityName(pdr->entity_type);
871 output["entityInstanceNumber"] = pdr->entity_instance;
872 output["containerID"] = pdr->container_id;
873 output["sensorInit"] = sensorInit[pdr->sensor_init];
874 output["sensorAuxiliaryNamesPDR"] =
875 (pdr->sensor_auxiliary_names_pdr ? true : false);
876 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530877
878 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600879 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530880
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600881 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530882 {
883 auto state = reinterpret_cast<const state_sensor_possible_states*>(
884 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600885 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
886 getStateSetName(state->state_set_id));
887 output.emplace(
888 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
889 state->possible_states_size);
890 output.emplace(
891 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500892 getStateSetPossibleStateNames(
893 state->state_set_id,
894 printPossibleStates(state->possible_states_size,
895 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530896
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600897 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530898 {
899 statesPtr += sizeof(state_sensor_possible_states) +
900 state->possible_states_size - 1;
901 }
902 }
903 }
904
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500905 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500906 {
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -0600907 if (data == nullptr)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500908 {
909 return;
910 }
911
912 data += sizeof(pldm_pdr_hdr);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530913 pldm_pdr_fru_record_set* pdr = new (data) pldm_pdr_fru_record_set;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530914 if (!pdr)
915 {
916 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
917 return;
918 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500919
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500920 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
921 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
922 output["entityType"] = getEntityName(pdr->entity_type);
Sagar Srinivasebf8bb52023-10-06 01:15:55 -0500923 output["entityInstanceNumber"] = unsigned(pdr->entity_instance);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500924 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500925 }
926
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500927 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500928 {
929 const std::map<uint8_t, const char*> assocationType = {
930 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
931 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
932 };
933
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -0600934 if (data == nullptr)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500935 {
936 return;
937 }
938
939 data += sizeof(pldm_pdr_hdr);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530940 pldm_pdr_entity_association* pdr = new (data)
941 pldm_pdr_entity_association;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530942 if (!pdr)
943 {
944 std::cerr << "Failed to get the PDR eneity association"
945 << std::endl;
946 return;
947 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500948
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500949 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800950 if (assocationType.contains(pdr->association_type))
951 {
952 output["associationType"] =
953 assocationType.at(pdr->association_type);
954 }
955 else
956 {
957 std::cout << "Get associationType failed.\n";
958 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500959 output["containerEntityType"] =
960 getEntityName(pdr->container.entity_type);
961 output["containerEntityInstanceNumber"] =
962 int(pdr->container.entity_instance_num);
963 output["containerEntityContainerID"] =
964 int(pdr->container.entity_container_id);
965 output["containedEntityCount"] =
966 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500967
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530968 pldm_entity* child = new (&pdr->children[0]) pldm_entity();
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500969 for (int i = 0; i < pdr->num_children; ++i)
970 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500971 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
972 getEntityName(child->entity_type));
973 output.emplace("containedEntityInstanceNumber[" +
974 std::to_string(i + 1) + "]",
975 unsigned(child->entity_instance_num));
976 output.emplace("containedEntityContainerID[" +
977 std::to_string(i + 1) + "]",
978 unsigned(child->entity_container_id));
979
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500980 ++child;
981 }
982 }
983
Thu Nguyen846d38f2022-03-26 08:57:21 +0700984 /** @brief Format the Sensor/Effecter Aux Name PDR types to json output
985 *
986 * @param[in] data - reference to the Sensor/Effecter Aux Name PDR
987 * @param[out] output - PDRs data fields in Json format
988 */
989 void printAuxNamePDR(uint8_t* data, ordered_json& output)
990 {
991 constexpr uint8_t nullTerminator = 0;
992 struct pldm_effecter_aux_name_pdr* auxNamePdr =
993 (struct pldm_effecter_aux_name_pdr*)data;
994
995 if (!auxNamePdr)
996 {
997 std::cerr << "Failed to get Aux Name PDR" << std::endl;
998 return;
999 }
1000
1001 std::string sPrefix = "effecter";
1002 if (auxNamePdr->hdr.type == PLDM_SENSOR_AUXILIARY_NAMES_PDR)
1003 {
1004 sPrefix = "sensor";
1005 }
1006 output["terminusHandle"] = int(auxNamePdr->terminus_handle);
1007 output[sPrefix + "Id"] = int(auxNamePdr->effecter_id);
1008 output[sPrefix + "Count"] = int(auxNamePdr->effecter_count);
1009
1010 const uint8_t* ptr = auxNamePdr->effecter_names;
1011 for (auto i : std::views::iota(0, (int)auxNamePdr->effecter_count))
1012 {
1013 const uint8_t nameStringCount = static_cast<uint8_t>(*ptr);
1014 ptr += sizeof(uint8_t);
1015 for (auto j : std::views::iota(0, (int)nameStringCount))
1016 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001017 std::string nameLanguageTagKey =
1018 sPrefix + std::to_string(j) + "_nameLanguageTag" +
1019 std::to_string(i);
1020 std::string entityAuxNameKey =
1021 sPrefix + std::to_string(j) + "_entityAuxName" +
1022 std::to_string(i);
Thu Nguyen846d38f2022-03-26 08:57:21 +07001023 std::string nameLanguageTag(reinterpret_cast<const char*>(ptr),
1024 0, PLDM_STR_UTF_8_MAX_LEN);
1025 ptr += nameLanguageTag.size() + sizeof(nullTerminator);
1026 std::u16string u16NameString(
1027 reinterpret_cast<const char16_t*>(ptr), 0,
1028 PLDM_STR_UTF_16_MAX_LEN);
1029 ptr += (u16NameString.size() + sizeof(nullTerminator)) *
1030 sizeof(uint16_t);
1031 std::transform(u16NameString.cbegin(), u16NameString.cend(),
1032 u16NameString.begin(),
1033 [](uint16_t utf16) { return be16toh(utf16); });
1034 std::string nameString =
1035 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
1036 char16_t>{}
1037 .to_bytes(u16NameString);
1038 output[nameLanguageTagKey] = nameLanguageTag;
1039 output[entityAuxNameKey] = nameString;
1040 }
1041 }
1042 }
1043
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001044 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +08001045 {
1046 struct pldm_numeric_effecter_value_pdr* pdr =
1047 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301048 if (!pdr)
1049 {
1050 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
1051 return;
1052 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001053
1054 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
1055 output["effecterID"] = int(pdr->effecter_id);
1056 output["entityType"] = int(pdr->entity_type);
1057 output["entityInstanceNumber"] = int(pdr->entity_instance);
1058 output["containerID"] = int(pdr->container_id);
1059 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
1060 output["effecterInit"] = unsigned(pdr->effecter_init);
1061 output["effecterAuxiliaryNames"] =
1062 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
1063 output["baseUnit"] = unsigned(pdr->base_unit);
1064 output["unitModifier"] = unsigned(pdr->unit_modifier);
1065 output["rateUnit"] = unsigned(pdr->rate_unit);
1066 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
1067 output["auxUnit"] = unsigned(pdr->aux_unit);
1068 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
1069 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
1070 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
1071 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
1072 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
1073 output["resolution"] = unsigned(pdr->resolution);
1074 output["offset"] = unsigned(pdr->offset);
1075 output["accuracy"] = unsigned(pdr->accuracy);
1076 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
1077 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
1078 output["stateTransitionInterval"] =
1079 unsigned(pdr->state_transition_interval);
1080 output["TransitionInterval"] = unsigned(pdr->transition_interval);
1081
George Liu62d12ec2020-02-05 16:27:08 +08001082 switch (pdr->effecter_data_size)
1083 {
1084 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301085 output["maxSettable"] = unsigned(pdr->max_settable.value_u8);
1086 output["minSettable"] = unsigned(pdr->min_settable.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001087 break;
1088 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301089 output["maxSettable"] = unsigned(pdr->max_settable.value_s8);
1090 output["minSettable"] = unsigned(pdr->min_settable.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001091 break;
1092 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301093 output["maxSettable"] = unsigned(pdr->max_settable.value_u16);
1094 output["minSettable"] = unsigned(pdr->min_settable.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001095 break;
1096 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301097 output["maxSettable"] = unsigned(pdr->max_settable.value_s16);
1098 output["minSettable"] = unsigned(pdr->min_settable.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001099 break;
1100 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301101 output["maxSettable"] = unsigned(pdr->max_settable.value_u32);
1102 output["minSettable"] = unsigned(pdr->min_settable.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001103 break;
1104 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301105 output["maxSettable"] = unsigned(pdr->max_settable.value_s32);
1106 output["minSettable"] = unsigned(pdr->min_settable.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001107 break;
1108 default:
1109 break;
1110 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001111
1112 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
1113 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1114
George Liu62d12ec2020-02-05 16:27:08 +08001115 switch (pdr->range_field_format)
1116 {
1117 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001118 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
1119 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
1120 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
1121 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
1122 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001123 break;
1124 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001125 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
1126 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
1127 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
1128 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
1129 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001130 break;
1131 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001132 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
1133 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
1134 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
1135 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
1136 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001137 break;
1138 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001139 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
1140 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
1141 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
1142 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
1143 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001144 break;
1145 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001146 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
1147 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
1148 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
1149 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
1150 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001151 break;
1152 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001153 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
1154 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
1155 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
1156 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
1157 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001158 break;
1159 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001160 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
1161 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
1162 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
1163 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
1164 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +08001165 break;
1166 default:
1167 break;
1168 }
1169 }
1170
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001171 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +08001172 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301173 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +08001174
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001175 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1176 output["effecterID"] = pdr->effecter_id;
1177 output["entityType"] = getEntityName(pdr->entity_type);
1178 output["entityInstanceNumber"] = pdr->entity_instance;
1179 output["containerID"] = pdr->container_id;
1180 output["effecterSemanticID"] = pdr->effecter_semantic_id;
1181 output["effecterInit"] = effecterInit[pdr->effecter_init];
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001182 output["effecterDescriptionPDR"] =
1183 (pdr->has_description_pdr ? true : false);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001184 output["compositeEffecterCount"] =
1185 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +08001186
Tom Joseph97a7a762020-07-06 10:37:18 +05301187 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001188 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +05301189
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001190 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +08001191 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301192 auto state =
1193 reinterpret_cast<const state_effecter_possible_states*>(
1194 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001195 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
1196 getStateSetName(state->state_set_id));
1197 output.emplace(
1198 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
1199 state->possible_states_size);
1200 output.emplace(
1201 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05001202 getStateSetPossibleStateNames(
1203 state->state_set_id,
1204 printPossibleStates(state->possible_states_size,
1205 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001206
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001207 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +05301208 {
1209 statesPtr += sizeof(state_effecter_possible_states) +
1210 state->possible_states_size - 1;
1211 }
George Liud6649362019-11-27 19:06:51 +08001212 }
1213 }
1214
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001215 bool checkTerminusHandle(const uint8_t* data,
1216 std::optional<uint16_t> terminusHandle)
1217 {
1218 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1219
1220 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1221 {
1222 auto tlpdr =
1223 reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1224
1225 if (tlpdr->terminus_handle != terminusHandle)
1226 {
1227 return true;
1228 }
1229 }
1230 else if (pdr->type == PLDM_STATE_SENSOR_PDR)
1231 {
1232 auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
1233
1234 if (sensor->terminus_handle != terminusHandle)
1235 {
1236 return true;
1237 }
1238 }
1239 else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR)
1240 {
1241 auto numericEffecter =
1242 reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data);
1243
1244 if (numericEffecter->terminus_handle != terminusHandle)
1245 {
1246 return true;
1247 }
1248 }
1249
1250 else if (pdr->type == PLDM_STATE_EFFECTER_PDR)
1251 {
1252 auto stateEffecter =
1253 reinterpret_cast<const pldm_state_effecter_pdr*>(data);
1254 if (stateEffecter->terminus_handle != terminusHandle)
1255 {
1256 return true;
1257 }
1258 }
1259 else if (pdr->type == PLDM_PDR_FRU_RECORD_SET)
1260 {
1261 data += sizeof(pldm_pdr_hdr);
1262 auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data);
1263
1264 if (fru->terminus_handle != terminusHandle)
1265 {
1266 return true;
1267 }
1268 }
1269 else
1270 {
1271 // Entity association PDRs does not have terminus handle
1272 return true;
1273 }
1274
1275 return false;
1276 }
1277
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001278 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -05001279 {
1280 const std::array<std::string_view, 4> terminusLocatorType = {
1281 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
1282
1283 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1284
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001285 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1286 output["validity"] = (pdr->validity ? "valid" : "notValid");
1287 output["TID"] = unsigned(pdr->tid);
1288 output["containerID"] = pdr->container_id;
1289 output["terminusLocatorType"] =
1290 terminusLocatorType[pdr->terminus_locator_type];
1291 output["terminusLocatorValueSize"] =
1292 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -05001293
1294 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
1295 {
1296 auto locatorValue =
1297 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
1298 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001299 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -05001300 }
1301 }
1302
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001303 std::optional<uint16_t> getTerminusHandle(uint8_t* data,
1304 std::optional<uint8_t> tid)
1305 {
1306 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1307 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1308 {
1309 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1310 if (pdr->tid == tid)
1311 {
1312 handleFound = true;
1313 return pdr->terminus_handle;
1314 }
1315 }
1316 return std::nullopt;
1317 }
1318
nothingIIersonalcea52d92024-03-21 13:56:02 +03001319 /** @brief Format the Numeric Sensor PDR types to json output
1320 *
1321 * @param[in] data - reference to the Numeric Sensor PDR
1322 * @param[in] data_length - number of PDR data bytes
1323 * @param[out] output - PDRs data fields in Json format
1324 */
1325 void printNumericSensorPDR(const uint8_t* data, const uint16_t data_length,
1326 ordered_json& output)
1327 {
1328 struct pldm_numeric_sensor_value_pdr pdr;
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001329 int rc =
1330 decode_numeric_sensor_pdr_data(data, (size_t)data_length, &pdr);
nothingIIersonalcea52d92024-03-21 13:56:02 +03001331 if (rc != PLDM_SUCCESS)
1332 {
1333 std::cerr << "Failed to get numeric sensor PDR" << std::endl;
1334 return;
1335 }
1336 output["PLDMTerminusHandle"] = pdr.terminus_handle;
1337 output["sensorID"] = pdr.sensor_id;
1338 output["entityType"] = getEntityName(pdr.entity_type);
1339 output["entityInstanceNumber"] = pdr.entity_instance_num;
1340 output["containerID"] = pdr.container_id;
1341 output["sensorInit"] = pdr.sensor_init;
1342 output["sensorAuxiliaryNamesPDR"] =
1343 (pdr.sensor_auxiliary_names_pdr) ? true : false;
1344 output["baseUnit"] = pdr.base_unit;
1345 output["unitModifier"] = pdr.unit_modifier;
1346 output["rateUnit"] = pdr.rate_unit;
1347 output["baseOEMUnitHandle"] = pdr.base_oem_unit_handle;
1348 output["auxUnit"] = pdr.aux_unit;
1349 output["auxUnitModifier"] = pdr.aux_unit_modifier;
1350 output["auxrateUnit"] = pdr.aux_rate_unit;
1351 output["rel"] = pdr.rel;
1352 output["auxOEMUnitHandle"] = pdr.aux_oem_unit_handle;
1353 output["isLinear"] = (pdr.is_linear) ? true : false;
1354 output["sensorDataSize"] = pdr.sensor_data_size;
1355 output["resolution"] = pdr.resolution;
1356 output["offset"] = pdr.offset;
1357 output["accuracy"] = pdr.accuracy;
1358 output["plusTolerance"] = pdr.plus_tolerance;
1359 output["minusTolerance"] = pdr.minus_tolerance;
1360
1361 switch (pdr.sensor_data_size)
1362 {
1363 case PLDM_SENSOR_DATA_SIZE_UINT8:
1364 output["hysteresis"] = pdr.hysteresis.value_u8;
1365 output["maxReadable"] = pdr.max_readable.value_u8;
1366 output["minReadable"] = pdr.min_readable.value_u8;
1367 break;
1368 case PLDM_SENSOR_DATA_SIZE_SINT8:
1369 output["hysteresis"] = pdr.hysteresis.value_s8;
1370 output["maxReadable"] = pdr.max_readable.value_s8;
1371 output["minReadable"] = pdr.min_readable.value_s8;
1372 break;
1373 case PLDM_SENSOR_DATA_SIZE_UINT16:
1374 output["hysteresis"] = pdr.hysteresis.value_u16;
1375 output["maxReadable"] = pdr.max_readable.value_u16;
1376 output["minReadable"] = pdr.min_readable.value_u16;
1377 break;
1378 case PLDM_SENSOR_DATA_SIZE_SINT16:
1379 output["hysteresis"] = pdr.hysteresis.value_s16;
1380 output["maxReadable"] = pdr.max_readable.value_s16;
1381 output["minReadable"] = pdr.min_readable.value_s16;
1382 break;
1383 case PLDM_SENSOR_DATA_SIZE_UINT32:
1384 output["hysteresis"] = pdr.hysteresis.value_u32;
1385 output["maxReadable"] = pdr.max_readable.value_u32;
1386 output["minReadable"] = pdr.min_readable.value_u32;
1387 break;
1388 case PLDM_SENSOR_DATA_SIZE_SINT32:
1389 output["hysteresis"] = pdr.hysteresis.value_s32;
1390 output["maxReadable"] = pdr.max_readable.value_s32;
1391 output["minReadable"] = pdr.min_readable.value_s32;
1392 break;
1393 default:
1394 break;
1395 }
1396
1397 output["supportedThresholds"] = pdr.supported_thresholds.byte;
1398 output["thresholAndHysteresisVolatility"] =
1399 pdr.threshold_and_hysteresis_volatility.byte;
1400 output["stateTransitionInterval"] = pdr.state_transition_interval;
1401 output["updateInterval"] = pdr.update_interval;
1402 output["rangeFieldFormat"] = pdr.range_field_format;
1403 output["rangeFieldSupport"] = pdr.range_field_support.byte;
1404
1405 switch (pdr.range_field_format)
1406 {
1407 case PLDM_RANGE_FIELD_FORMAT_UINT8:
1408 output["nominalValue"] = pdr.nominal_value.value_u8;
1409 output["normalMax"] = pdr.normal_max.value_u8;
1410 output["normalMin"] = pdr.normal_min.value_u8;
1411 output["warningHigh"] = pdr.warning_high.value_u8;
1412 output["warningLow"] = pdr.warning_low.value_u8;
1413 output["criticalHigh"] = pdr.critical_high.value_u8;
1414 output["criticalLow"] = pdr.critical_low.value_u8;
1415 output["fatalHigh"] = pdr.fatal_high.value_u8;
1416 output["fatalLeow"] = pdr.fatal_low.value_u8;
1417 break;
1418 case PLDM_RANGE_FIELD_FORMAT_SINT8:
1419 output["nominalValue"] = pdr.nominal_value.value_s8;
1420 output["normalMax"] = pdr.normal_max.value_s8;
1421 output["normalMin"] = pdr.normal_min.value_s8;
1422 output["warningHigh"] = pdr.warning_high.value_s8;
1423 output["warningLow"] = pdr.warning_low.value_s8;
1424 output["criticalHigh"] = pdr.critical_high.value_s8;
1425 output["criticalLow"] = pdr.critical_low.value_s8;
1426 output["fatalHigh"] = pdr.fatal_high.value_s8;
1427 output["fatalLeow"] = pdr.fatal_low.value_s8;
1428 break;
1429 case PLDM_RANGE_FIELD_FORMAT_UINT16:
1430 output["nominalValue"] = pdr.nominal_value.value_u16;
1431 output["normalMax"] = pdr.normal_max.value_u16;
1432 output["normalMin"] = pdr.normal_min.value_u16;
1433 output["warningHigh"] = pdr.warning_high.value_u16;
1434 output["warningLow"] = pdr.warning_low.value_u16;
1435 output["criticalHigh"] = pdr.critical_high.value_u16;
1436 output["criticalLow"] = pdr.critical_low.value_u16;
1437 output["fatalHigh"] = pdr.fatal_high.value_u16;
1438 output["fatalLeow"] = pdr.fatal_low.value_u16;
1439 break;
1440 case PLDM_RANGE_FIELD_FORMAT_SINT16:
1441 output["nominalValue"] = pdr.nominal_value.value_s16;
1442 output["normalMax"] = pdr.normal_max.value_s16;
1443 output["normalMin"] = pdr.normal_min.value_s16;
1444 output["warningHigh"] = pdr.warning_high.value_s16;
1445 output["warningLow"] = pdr.warning_low.value_s16;
1446 output["criticalHigh"] = pdr.critical_high.value_s16;
1447 output["criticalLow"] = pdr.critical_low.value_s16;
1448 output["fatalHigh"] = pdr.fatal_high.value_s16;
1449 output["fatalLeow"] = pdr.fatal_low.value_s16;
1450 break;
1451 case PLDM_RANGE_FIELD_FORMAT_UINT32:
1452 output["nominalValue"] = pdr.nominal_value.value_u32;
1453 output["normalMax"] = pdr.normal_max.value_u32;
1454 output["normalMin"] = pdr.normal_min.value_u32;
1455 output["warningHigh"] = pdr.warning_high.value_u32;
1456 output["warningLow"] = pdr.warning_low.value_u32;
1457 output["criticalHigh"] = pdr.critical_high.value_u32;
1458 output["criticalLow"] = pdr.critical_low.value_u32;
1459 output["fatalHigh"] = pdr.fatal_high.value_u32;
1460 output["fatalLeow"] = pdr.fatal_low.value_u32;
1461 break;
1462 case PLDM_RANGE_FIELD_FORMAT_SINT32:
1463 output["nominalValue"] = pdr.nominal_value.value_s32;
1464 output["normalMax"] = pdr.normal_max.value_s32;
1465 output["normalMin"] = pdr.normal_min.value_s32;
1466 output["warningHigh"] = pdr.warning_high.value_s32;
1467 output["warningLow"] = pdr.warning_low.value_s32;
1468 output["criticalHigh"] = pdr.critical_high.value_s32;
1469 output["criticalLow"] = pdr.critical_low.value_s32;
1470 output["fatalHigh"] = pdr.fatal_high.value_s32;
1471 output["fatalLeow"] = pdr.fatal_low.value_s32;
1472 break;
1473 case PLDM_RANGE_FIELD_FORMAT_REAL32:
1474 output["nominalValue"] = pdr.nominal_value.value_f32;
1475 output["normalMax"] = pdr.normal_max.value_f32;
1476 output["normalMin"] = pdr.normal_min.value_f32;
1477 output["warningHigh"] = pdr.warning_high.value_f32;
1478 output["warningLow"] = pdr.warning_low.value_f32;
1479 output["criticalHigh"] = pdr.critical_high.value_f32;
1480 output["criticalLow"] = pdr.critical_low.value_f32;
1481 output["fatalHigh"] = pdr.fatal_high.value_f32;
1482 output["fatalLeow"] = pdr.fatal_low.value_f32;
1483 break;
1484 default:
1485 break;
1486 }
1487 }
1488
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001489 /** @brief Format the Compact Numeric Sensor PDR types to json output
1490 *
1491 * @param[in] data - reference to the Compact Numeric Sensor PDR
1492 * @param[out] output - PDRs data fields in Json format
1493 */
1494 void printCompactNumericSensorPDR(const uint8_t* data, ordered_json& output)
1495 {
1496 struct pldm_compact_numeric_sensor_pdr* pdr =
1497 (struct pldm_compact_numeric_sensor_pdr*)data;
1498 if (!pdr)
1499 {
1500 std::cerr << "Failed to get compact numeric sensor PDR"
1501 << std::endl;
1502 return;
1503 }
1504 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
1505 output["sensorID"] = int(pdr->sensor_id);
1506 output["entityType"] = getEntityName(pdr->entity_type);
1507 output["entityInstanceNumber"] = int(pdr->entity_instance);
1508 output["containerID"] = int(pdr->container_id);
1509 output["sensorNameStringByteLength"] = int(pdr->sensor_name_length);
1510 if (pdr->sensor_name_length == 0)
1511 {
1512 output["Name"] = std::format("PLDM_Device_TID{}_SensorId{}",
1513 unsigned(pdr->terminus_handle),
1514 unsigned(pdr->sensor_id));
1515 }
1516 else
1517 {
1518 std::string sTemp(reinterpret_cast<const char*>(pdr->sensor_name),
1519 pdr->sensor_name_length);
1520 output["Name"] = sTemp;
1521 }
1522 output["baseUnit"] = unsigned(pdr->base_unit);
1523 output["unitModifier"] = signed(pdr->unit_modifier);
1524 output["occurrenceRate"] = unsigned(pdr->occurrence_rate);
1525 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1526 if (pdr->range_field_support.bits.bit0)
1527 {
1528 output["warningHigh"] = int(pdr->warning_high);
1529 }
1530 if (pdr->range_field_support.bits.bit1)
1531 {
1532 output["warningLow"] = int(pdr->warning_low);
1533 }
1534 if (pdr->range_field_support.bits.bit2)
1535 {
1536 output["criticalHigh"] = int(pdr->critical_high);
1537 }
1538 if (pdr->range_field_support.bits.bit3)
1539 {
1540 output["criticalLow"] = int(pdr->critical_low);
1541 }
1542 if (pdr->range_field_support.bits.bit4)
1543 {
1544 output["fatalHigh"] = int(pdr->fatal_high);
1545 }
1546 if (pdr->range_field_support.bits.bit5)
1547 {
1548 output["fatalLow"] = int(pdr->fatal_low);
1549 }
1550 }
1551
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001552 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001553 uint8_t* data, std::optional<uint16_t> terminusHandle)
George Liud6649362019-11-27 19:06:51 +08001554 {
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -06001555 if (data == nullptr)
George Liud6649362019-11-27 19:06:51 +08001556 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301557 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +08001558 return;
1559 }
1560
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001561 ordered_json output;
1562 output["nextRecordHandle"] = nextRecordHndl;
1563 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +08001564
1565 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301566 if (!pdr)
1567 {
1568 return;
1569 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001570
1571 if (!pdrRecType.empty())
1572 {
1573 // Need to return if the requested PDR type
1574 // is not supported
1575 if (!strToPdrType.contains(pdrRecType))
1576 {
1577 std::cerr << "PDR type '" << pdrRecType
1578 << "' is not supported or invalid\n";
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -05001579 // PDR type not supported, setting next record handle to
1580 // 0 to avoid looping through all PDR records
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001581 nextRecordHndl = 0;
1582 return;
1583 }
1584
1585 // Do not print PDR record if the current record
1586 // PDR type does not match with requested type
1587 if (pdr->type != strToPdrType.at(pdrRecType))
1588 {
1589 return;
1590 }
1591 }
1592
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001593 if (pdrTerminus.has_value())
1594 {
1595 if (checkTerminusHandle(data, terminusHandle))
1596 {
1597 std::cerr << "The Terminus handle doesn't match return"
1598 << std::endl;
1599 return;
1600 }
1601 }
1602
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001603 printCommonPDRHeader(pdr, output);
1604
George Liud6649362019-11-27 19:06:51 +08001605 switch (pdr->type)
1606 {
Sampa Misra12afe112020-05-25 11:40:44 -05001607 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001608 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001609 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301610 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001611 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301612 break;
George Liu62d12ec2020-02-05 16:27:08 +08001613 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001614 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001615 break;
nothingIIersonalcea52d92024-03-21 13:56:02 +03001616 case PLDM_NUMERIC_SENSOR_PDR:
1617 printNumericSensorPDR(data, respCnt, output);
1618 break;
Thu Nguyen846d38f2022-03-26 08:57:21 +07001619 case PLDM_SENSOR_AUXILIARY_NAMES_PDR:
Thu Nguyen846d38f2022-03-26 08:57:21 +07001620 case PLDM_EFFECTER_AUXILIARY_NAMES_PDR:
1621 printAuxNamePDR(data, output);
1622 break;
George Liud6649362019-11-27 19:06:51 +08001623 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001624 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001625 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001626 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001627 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001628 break;
1629 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001630 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001631 break;
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001632 case PLDM_COMPACT_NUMERIC_SENSOR_PDR:
1633 printCompactNumericSensorPDR(data, output);
1634 break;
George Liud6649362019-11-27 19:06:51 +08001635 default:
1636 break;
1637 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001638 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001639 }
1640
1641 private:
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001642 bool optTIDSet = false;
George Liud6649362019-11-27 19:06:51 +08001643 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001644 bool allPDRs;
1645 std::string pdrRecType;
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001646 std::optional<uint8_t> pdrTerminus;
1647 std::optional<uint16_t> terminusHandle;
1648 bool handleFound = false;
1649 CLI::Option* getPDRGroupOption = nullptr;
Potin Lai3e52d582024-06-13 11:03:46 +08001650 uint32_t dataTransferHandle;
1651 uint8_t operationFlag;
1652 uint16_t requestCount;
1653 uint16_t recordChangeNumber;
1654 std::vector<uint8_t> recordData;
1655 bool nextPartRequired;
George Liud6649362019-11-27 19:06:51 +08001656};
1657
1658class SetStateEffecter : public CommandInterface
1659{
1660 public:
1661 ~SetStateEffecter() = default;
1662 SetStateEffecter() = delete;
1663 SetStateEffecter(const SetStateEffecter&) = delete;
1664 SetStateEffecter(SetStateEffecter&&) = default;
1665 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001666 SetStateEffecter& operator=(SetStateEffecter&&) = delete;
George Liud6649362019-11-27 19:06:51 +08001667
George Liuba4c1fb2020-02-05 14:13:30 +08001668 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1669 static constexpr auto maxEffecterDataSize = 16;
1670
1671 // compositeEffecterCount(value: 0x01 to 0x08)
1672 static constexpr auto minEffecterCount = 1;
1673 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001674 explicit SetStateEffecter(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001675 CLI::App* app) : CommandInterface(type, name, app)
George Liud6649362019-11-27 19:06:51 +08001676 {
1677 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001678 "-i, --id", effecterId,
1679 "A handle that is used to identify and access the effecter")
1680 ->required();
1681 app->add_option("-c, --count", effecterCount,
1682 "The number of individual sets of effecter information")
1683 ->required();
1684 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001685 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001686 "Set effecter state data\n"
1687 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1688 ->required();
George Liud6649362019-11-27 19:06:51 +08001689 }
1690
1691 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1692 {
1693 std::vector<uint8_t> requestMsg(
1694 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301695 auto request = new (requestMsg.data()) pldm_msg;
George Liud6649362019-11-27 19:06:51 +08001696
George Liuba4c1fb2020-02-05 14:13:30 +08001697 if (effecterCount > maxEffecterCount ||
1698 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001699 {
George Liuba4c1fb2020-02-05 14:13:30 +08001700 std::cerr << "Request Message Error: effecterCount size "
1701 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001702 auto rc = PLDM_ERROR_INVALID_DATA;
1703 return {rc, requestMsg};
1704 }
1705
George Liuba4c1fb2020-02-05 14:13:30 +08001706 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001707 {
George Liuba4c1fb2020-02-05 14:13:30 +08001708 std::cerr << "Request Message Error: effecterData size "
1709 << effecterData.size() << "is invalid\n";
1710 auto rc = PLDM_ERROR_INVALID_DATA;
1711 return {rc, requestMsg};
1712 }
1713
1714 auto stateField = parseEffecterData(effecterData, effecterCount);
1715 if (!stateField)
1716 {
1717 std::cerr << "Failed to parse effecter data, effecterCount size "
1718 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001719 auto rc = PLDM_ERROR_INVALID_DATA;
1720 return {rc, requestMsg};
1721 }
1722
1723 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001724 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001725 return {rc, requestMsg};
1726 }
1727
1728 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1729 {
1730 uint8_t completionCode = 0;
1731 auto rc = decode_set_state_effecter_states_resp(
1732 responsePtr, payloadLength, &completionCode);
1733
1734 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1735 {
1736 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001737 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001738 return;
1739 }
1740
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001741 ordered_json data;
1742 data["Response"] = "SUCCESS";
1743 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001744 }
1745
1746 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001747 uint16_t effecterId;
1748 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001749 std::vector<uint8_t> effecterData;
1750};
1751
George Liucc9c20d2020-02-05 10:24:11 +08001752class SetNumericEffecterValue : public CommandInterface
1753{
1754 public:
1755 ~SetNumericEffecterValue() = default;
1756 SetNumericEffecterValue() = delete;
1757 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1758 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1759 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001760 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete;
George Liucc9c20d2020-02-05 10:24:11 +08001761
1762 explicit SetNumericEffecterValue(const char* type, const char* name,
1763 CLI::App* app) :
1764 CommandInterface(type, name, app)
1765 {
1766 app->add_option(
1767 "-i, --id", effecterId,
1768 "A handle that is used to identify and access the effecter")
1769 ->required();
1770 app->add_option("-s, --size", effecterDataSize,
1771 "The bit width and format of the setting value for the "
1772 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1773 "uint32, sint32}\n")
1774 ->required();
1775 app->add_option("-d,--data", maxEffecterValue,
1776 "The setting value of numeric effecter being "
1777 "requested\n")
1778 ->required();
1779 }
1780
1781 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1782 {
1783 std::vector<uint8_t> requestMsg(
1784 sizeof(pldm_msg_hdr) +
1785 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1786
1787 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1788
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301789 auto request = new (requestMsg.data()) pldm_msg;
1790
George Liucc9c20d2020-02-05 10:24:11 +08001791 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1792
1793 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1794 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1795 {
1796 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1797 }
1798 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1799 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1800 {
1801 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1802 }
1803 auto rc = encode_set_numeric_effecter_value_req(
1804 0, effecterId, effecterDataSize, effecterValue, request,
1805 payload_length);
1806
1807 return {rc, requestMsg};
1808 }
1809
1810 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1811 {
1812 uint8_t completionCode = 0;
1813 auto rc = decode_set_numeric_effecter_value_resp(
1814 responsePtr, payloadLength, &completionCode);
1815
1816 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1817 {
1818 std::cerr << "Response Message Error: "
1819 << "rc=" << rc << ",cc=" << (int)completionCode
1820 << std::endl;
1821 return;
1822 }
1823
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001824 ordered_json data;
1825 data["Response"] = "SUCCESS";
1826 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001827 }
1828
1829 private:
1830 uint16_t effecterId;
1831 uint8_t effecterDataSize;
1832 uint64_t maxEffecterValue;
1833};
1834
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001835class GetStateSensorReadings : public CommandInterface
1836{
1837 public:
1838 ~GetStateSensorReadings() = default;
1839 GetStateSensorReadings() = delete;
1840 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1841 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1842 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001843 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001844
1845 explicit GetStateSensorReadings(const char* type, const char* name,
1846 CLI::App* app) :
1847 CommandInterface(type, name, app)
1848 {
1849 app->add_option(
1850 "-i, --sensor_id", sensorId,
1851 "Sensor ID that is used to identify and access the sensor")
1852 ->required();
1853 app->add_option("-r, --rearm", sensorRearm,
1854 "Each bit location in this field corresponds to a "
1855 "particular sensor")
1856 ->required();
1857 }
1858
1859 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1860 {
1861 std::vector<uint8_t> requestMsg(
1862 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301863 auto request = new (requestMsg.data()) pldm_msg;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001864
1865 uint8_t reserved = 0;
1866 bitfield8_t bf;
1867 bf.byte = sensorRearm;
1868 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1869 reserved, request);
1870
1871 return {rc, requestMsg};
1872 }
1873
1874 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1875 {
1876 uint8_t completionCode = 0;
1877 uint8_t compSensorCount = 0;
1878 std::array<get_sensor_state_field, 8> stateField{};
1879 auto rc = decode_get_state_sensor_readings_resp(
1880 responsePtr, payloadLength, &completionCode, &compSensorCount,
1881 stateField.data());
1882
1883 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1884 {
1885 std::cerr << "Response Message Error: "
1886 << "rc=" << rc << ",cc=" << (int)completionCode
1887 << std::endl;
1888 return;
1889 }
1890 ordered_json output;
1891 output["compositeSensorCount"] = (int)compSensorCount;
1892
1893 for (size_t i = 0; i < compSensorCount; i++)
1894 {
George Liubd5e2ea2021-04-22 20:33:06 +08001895 if (sensorOpState.contains(stateField[i].sensor_op_state))
1896 {
1897 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1898 sensorOpState.at(stateField[i].sensor_op_state));
1899 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001900
George Liubd5e2ea2021-04-22 20:33:06 +08001901 if (sensorPresState.contains(stateField[i].present_state))
1902 {
1903 output.emplace(("presentState[" + std::to_string(i) + "]"),
1904 sensorPresState.at(stateField[i].present_state));
1905 }
1906
1907 if (sensorPresState.contains(stateField[i].previous_state))
1908 {
1909 output.emplace(
1910 ("previousState[" + std::to_string(i) + "]"),
1911 sensorPresState.at(stateField[i].previous_state));
1912 }
1913
1914 if (sensorPresState.contains(stateField[i].event_state))
1915 {
1916 output.emplace(("eventState[" + std::to_string(i) + "]"),
1917 sensorPresState.at(stateField[i].event_state));
1918 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001919 }
1920
1921 pldmtool::helper::DisplayInJson(output);
1922 }
1923
1924 private:
1925 uint16_t sensorId;
1926 uint8_t sensorRearm;
1927};
1928
nothingIIersonal83e068a2024-03-21 13:55:06 +03001929class GetSensorReading : public CommandInterface
1930{
1931 public:
1932 ~GetSensorReading() = default;
1933 GetSensorReading() = delete;
1934 GetSensorReading(const GetSensorReading&) = delete;
1935 GetSensorReading(GetSensorReading&&) = default;
1936 GetSensorReading& operator=(const GetSensorReading&) = delete;
1937 GetSensorReading& operator=(GetSensorReading&&) = delete;
1938
1939 explicit GetSensorReading(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001940 CLI::App* app) : CommandInterface(type, name, app)
nothingIIersonal83e068a2024-03-21 13:55:06 +03001941 {
1942 app->add_option(
1943 "-i, --sensor_id", sensorId,
1944 "Sensor ID that is used to identify and access the sensor")
1945 ->required();
1946 app->add_option("-r, --rearm", rearm,
1947 "Manually re-arm EventState after "
1948 "responding to this request")
1949 ->required();
1950 }
1951
1952 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1953 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001954 std::vector<uint8_t> requestMsg(
1955 sizeof(pldm_msg_hdr) + PLDM_GET_SENSOR_READING_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301956 auto request = new (requestMsg.data()) pldm_msg;
nothingIIersonal83e068a2024-03-21 13:55:06 +03001957
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001958 auto rc =
1959 encode_get_sensor_reading_req(instanceId, sensorId, rearm, request);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001960
1961 return {rc, requestMsg};
1962 }
1963
1964 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1965 {
1966 uint8_t completionCode = 0;
1967 uint8_t sensorDataSize = 0;
1968 uint8_t sensorOperationalState = 0;
1969 uint8_t sensorEventMessageEnable = 0;
1970 uint8_t presentState = 0;
1971 uint8_t previousState = 0;
1972 uint8_t eventState = 0;
1973 std::array<uint8_t, sizeof(uint32_t)>
1974 presentReading{}; // maximum size for the present Value is uint32
1975 // according to spec DSP0248
1976
1977 auto rc = decode_get_sensor_reading_resp(
1978 responsePtr, payloadLength, &completionCode, &sensorDataSize,
1979 &sensorOperationalState, &sensorEventMessageEnable, &presentState,
1980 &previousState, &eventState, presentReading.data());
1981
1982 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1983 {
1984 std::cerr << "Response Message Error: "
1985 << "rc=" << rc << ",cc=" << (int)completionCode
1986 << std::endl;
1987 return;
1988 }
1989
1990 ordered_json output;
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001991 output["sensorDataSize"] =
1992 getSensorState(sensorDataSize, &sensorDataSz);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001993 output["sensorOperationalState"] =
1994 getSensorState(sensorOperationalState, &sensorOpState);
1995 output["sensorEventMessageEnable"] =
1996 getSensorState(sensorEventMessageEnable, &sensorEventMsgEnable);
1997 output["presentState"] = getSensorState(presentState, &sensorPresState);
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001998 output["previousState"] =
1999 getSensorState(previousState, &sensorPresState);
nothingIIersonal83e068a2024-03-21 13:55:06 +03002000 output["eventState"] = getSensorState(eventState, &sensorPresState);
2001
2002 switch (sensorDataSize)
2003 {
2004 case PLDM_SENSOR_DATA_SIZE_UINT8:
2005 {
2006 output["presentReading"] =
2007 *(reinterpret_cast<uint8_t*>(presentReading.data()));
2008 break;
2009 }
2010 case PLDM_SENSOR_DATA_SIZE_SINT8:
2011 {
2012 output["presentReading"] =
2013 *(reinterpret_cast<int8_t*>(presentReading.data()));
2014 break;
2015 }
2016 case PLDM_SENSOR_DATA_SIZE_UINT16:
2017 {
2018 output["presentReading"] =
2019 *(reinterpret_cast<uint16_t*>(presentReading.data()));
2020 break;
2021 }
2022 case PLDM_SENSOR_DATA_SIZE_SINT16:
2023 {
2024 output["presentReading"] =
2025 *(reinterpret_cast<int16_t*>(presentReading.data()));
2026 break;
2027 }
2028 case PLDM_SENSOR_DATA_SIZE_UINT32:
2029 {
2030 output["presentReading"] =
2031 *(reinterpret_cast<uint32_t*>(presentReading.data()));
2032 break;
2033 }
2034 case PLDM_SENSOR_DATA_SIZE_SINT32:
2035 {
2036 output["presentReading"] =
2037 *(reinterpret_cast<int32_t*>(presentReading.data()));
2038 break;
2039 }
2040 default:
2041 {
2042 std::cerr << "Unknown Sensor Data Size : "
2043 << static_cast<int>(sensorDataSize) << std::endl;
2044 break;
2045 }
2046 }
2047
2048 pldmtool::helper::DisplayInJson(output);
2049 }
2050
2051 private:
2052 uint16_t sensorId;
2053 uint8_t rearm;
2054
2055 const std::map<uint8_t, std::string> sensorDataSz = {
2056 {PLDM_SENSOR_DATA_SIZE_UINT8, "uint8"},
2057 {PLDM_SENSOR_DATA_SIZE_SINT8, "uint8"},
2058 {PLDM_SENSOR_DATA_SIZE_UINT16, "uint16"},
2059 {PLDM_SENSOR_DATA_SIZE_SINT16, "uint16"},
2060 {PLDM_SENSOR_DATA_SIZE_UINT32, "uint32"},
2061 {PLDM_SENSOR_DATA_SIZE_SINT32, "uint32"}};
2062
2063 static inline const std::map<uint8_t, std::string> sensorEventMsgEnable{
2064 {PLDM_NO_EVENT_GENERATION, "Sensor No Event Generation"},
2065 {PLDM_EVENTS_DISABLED, "Sensor Events Disabled"},
2066 {PLDM_EVENTS_ENABLED, "Sensor Events Enabled"},
2067 {PLDM_OP_EVENTS_ONLY_ENABLED, "Sensor Op Events Only Enabled"},
2068 {PLDM_STATE_EVENTS_ONLY_ENABLED, "Sensor State Events Only Enabled"}};
2069
2070 std::string getSensorState(uint8_t state,
2071 const std::map<uint8_t, std::string>* cont)
2072 {
2073 auto typeString = std::to_string(state);
2074 try
2075 {
2076 return cont->at(state);
2077 }
2078 catch (const std::out_of_range& e)
2079 {
2080 return typeString;
2081 }
2082 }
2083};
2084
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002085class GetStateEffecterStates : public CommandInterface
2086{
2087 public:
2088 ~GetStateEffecterStates() = default;
2089 GetStateEffecterStates() = delete;
2090 GetStateEffecterStates(const GetStateEffecterStates&) = delete;
2091 GetStateEffecterStates(GetStateEffecterStates&&) = default;
2092 GetStateEffecterStates& operator=(const GetStateEffecterStates&) = delete;
2093 GetStateEffecterStates& operator=(GetStateEffecterStates&&) = delete;
2094
2095 explicit GetStateEffecterStates(const char* type, const char* name,
2096 CLI::App* app) :
2097 CommandInterface(type, name, app)
2098 {
2099 app->add_option(
2100 "-i, --effecter_id", effecter_id,
2101 "Effecter ID that is used to identify and access the effecter")
2102 ->required();
2103 }
2104
2105 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2106 {
2107 std::vector<uint8_t> requestMsg(
2108 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05302109 auto request = new (requestMsg.data()) pldm_msg;
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002110
2111 auto rc = encode_get_state_effecter_states_req(
2112 instanceId, effecter_id, request,
2113 PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
2114
2115 return {rc, requestMsg};
2116 }
2117
2118 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2119 {
2120 struct pldm_get_state_effecter_states_resp resp;
2121 auto rc = decode_get_state_effecter_states_resp(responsePtr,
2122 payloadLength, &resp);
2123
2124 if (rc || resp.completion_code != PLDM_SUCCESS)
2125 {
2126 std::cerr << "Response Message Error: "
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002127 << "rc=" << rc << ",cc="
2128 << static_cast<int>(resp.completion_code) << std::endl;
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002129 return;
2130 }
2131 ordered_json output;
2132 auto comp_effecter_count = static_cast<int>(resp.comp_effecter_count);
2133 output["compositeEffecterCount"] = comp_effecter_count;
2134
Tal Yacobi92af05e2024-07-28 14:18:07 +03002135 for (auto i : std::views::iota(0, comp_effecter_count))
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002136 {
2137 output[std::format("effecterOpState[{}])", i)] =
2138 getEffecterOpState(resp.field[i].effecter_op_state);
2139
2140 output[std::format("pendingState[{}]", i)] =
2141 resp.field[i].pending_state;
2142
2143 output[std::format("presentState[{}]", i)] =
2144 resp.field[i].present_state;
2145 }
2146
2147 pldmtool::helper::DisplayInJson(output);
2148 }
2149
2150 private:
2151 uint16_t effecter_id;
2152};
2153
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002154class GetNumericEffecterValue : public CommandInterface
2155{
2156 public:
2157 ~GetNumericEffecterValue() = default;
2158 GetNumericEffecterValue() = delete;
2159 GetNumericEffecterValue(const GetNumericEffecterValue&) = delete;
2160 GetNumericEffecterValue(GetNumericEffecterValue&&) = default;
2161 GetNumericEffecterValue& operator=(const GetNumericEffecterValue&) = delete;
Pavithra Barithayaae088dc2023-11-09 01:14:05 -06002162 GetNumericEffecterValue& operator=(GetNumericEffecterValue&&) = delete;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002163
2164 explicit GetNumericEffecterValue(const char* type, const char* name,
2165 CLI::App* app) :
2166 CommandInterface(type, name, app)
2167 {
2168 app->add_option(
2169 "-i, --effecter_id", effecterId,
2170 "A handle that is used to identify and access the effecter")
2171 ->required();
2172 }
2173
2174 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2175 {
2176 std::vector<uint8_t> requestMsg(
2177 sizeof(pldm_msg_hdr) + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05302178 auto request = new (requestMsg.data()) pldm_msg;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002179
2180 auto rc = encode_get_numeric_effecter_value_req(instanceId, effecterId,
2181 request);
2182
2183 return {rc, requestMsg};
2184 }
2185
2186 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2187 {
2188 uint8_t completionCode = 0;
2189 uint8_t effecterDataSize = 0;
2190 uint8_t effecterOperationalState = 0;
2191 std::array<uint8_t, sizeof(uint32_t)>
2192 pendingValue{}; // maximum size for the pending Value is uint32
2193 // according to spec DSP0248
2194 std::array<uint8_t, sizeof(uint32_t)>
2195 presentValue{}; // maximum size for the present Value is uint32
2196 // according to spec DSP0248
2197
2198 auto rc = decode_get_numeric_effecter_value_resp(
2199 responsePtr, payloadLength, &completionCode, &effecterDataSize,
2200 &effecterOperationalState, pendingValue.data(),
2201 presentValue.data());
2202
2203 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
2204 {
2205 std::cerr << "Response Message Error: "
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002206 << "rc=" << rc << ",cc="
2207 << static_cast<int>(completionCode) << std::endl;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002208 return;
2209 }
2210
2211 ordered_json output;
2212 output["effecterDataSize"] = static_cast<int>(effecterDataSize);
2213 output["effecterOperationalState"] =
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002214 getEffecterOpState(effecterOperationalState);
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002215
2216 switch (effecterDataSize)
2217 {
2218 case PLDM_EFFECTER_DATA_SIZE_UINT8:
2219 {
2220 output["pendingValue"] =
2221 *(reinterpret_cast<uint8_t*>(pendingValue.data()));
2222 output["presentValue"] =
2223 *(reinterpret_cast<uint8_t*>(presentValue.data()));
2224 break;
2225 }
2226 case PLDM_EFFECTER_DATA_SIZE_SINT8:
2227 {
2228 output["pendingValue"] =
2229 *(reinterpret_cast<int8_t*>(pendingValue.data()));
2230 output["presentValue"] =
2231 *(reinterpret_cast<int8_t*>(presentValue.data()));
2232 break;
2233 }
2234 case PLDM_EFFECTER_DATA_SIZE_UINT16:
2235 {
2236 output["pendingValue"] =
2237 *(reinterpret_cast<uint16_t*>(pendingValue.data()));
2238 output["presentValue"] =
2239 *(reinterpret_cast<uint16_t*>(presentValue.data()));
2240 break;
2241 }
2242 case PLDM_EFFECTER_DATA_SIZE_SINT16:
2243 {
2244 output["pendingValue"] =
2245 *(reinterpret_cast<int16_t*>(pendingValue.data()));
2246 output["presentValue"] =
2247 *(reinterpret_cast<int16_t*>(presentValue.data()));
2248 break;
2249 }
2250 case PLDM_EFFECTER_DATA_SIZE_UINT32:
2251 {
2252 output["pendingValue"] =
2253 *(reinterpret_cast<uint32_t*>(pendingValue.data()));
2254 output["presentValue"] =
2255 *(reinterpret_cast<uint32_t*>(presentValue.data()));
2256 break;
2257 }
2258 case PLDM_EFFECTER_DATA_SIZE_SINT32:
2259 {
2260 output["pendingValue"] =
2261 *(reinterpret_cast<int32_t*>(pendingValue.data()));
2262 output["presentValue"] =
2263 *(reinterpret_cast<int32_t*>(presentValue.data()));
2264 break;
2265 }
2266 default:
2267 {
2268 std::cerr << "Unknown Effecter Data Size : "
2269 << static_cast<int>(effecterDataSize) << std::endl;
2270 break;
2271 }
2272 }
2273
2274 pldmtool::helper::DisplayInJson(output);
2275 }
2276
2277 private:
2278 uint16_t effecterId;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002279};
2280
George Liud6649362019-11-27 19:06:51 +08002281void registerCommand(CLI::App& app)
2282{
2283 auto platform = app.add_subcommand("platform", "platform type command");
2284 platform->require_subcommand(1);
2285
Roger G. Coscojuela4aea4bd2025-03-18 15:51:55 +01002286 auto getEventReceiver = platform->add_subcommand(
2287 "GetEventReceiver",
2288 "Get the configured event receiver from a terminus");
2289 commands.push_back(std::make_unique<GetEventReceiver>(
2290 "platform", "getEventReceiver", getEventReceiver));
2291
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002292 auto getPDR =
2293 platform->add_subcommand("GetPDR", "get platform descriptor records");
George Liud6649362019-11-27 19:06:51 +08002294 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
2295
2296 auto setStateEffecterStates = platform->add_subcommand(
2297 "SetStateEffecterStates", "set effecter states");
2298 commands.push_back(std::make_unique<SetStateEffecter>(
2299 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08002300
2301 auto setNumericEffecterValue = platform->add_subcommand(
2302 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
2303 commands.push_back(std::make_unique<SetNumericEffecterValue>(
2304 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06002305
2306 auto getStateSensorReadings = platform->add_subcommand(
2307 "GetStateSensorReadings", "get the state sensor readings");
2308 commands.push_back(std::make_unique<GetStateSensorReadings>(
2309 "platform", "getStateSensorReadings", getStateSensorReadings));
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002310
2311 auto getNumericEffecterValue = platform->add_subcommand(
2312 "GetNumericEffecterValue", "get the numeric effecter value");
2313 commands.push_back(std::make_unique<GetNumericEffecterValue>(
2314 "platform", "getNumericEffecterValue", getNumericEffecterValue));
nothingIIersonal83e068a2024-03-21 13:55:06 +03002315
2316 auto getSensorReading = platform->add_subcommand(
2317 "GetSensorReading", "get the numeric sensor reading");
2318 commands.push_back(std::make_unique<GetSensorReading>(
2319 "platform", "getSensorReading", getSensorReading));
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002320
2321 auto getStateEffecterStates = platform->add_subcommand(
2322 "GetStateEffecterStates", "get the state effecter states");
2323 commands.push_back(std::make_unique<GetStateEffecterStates>(
2324 "platform", "getStateEffecterStates", getStateEffecterStates));
George Liud6649362019-11-27 19:06:51 +08002325}
2326
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06002327void parseGetPDROption()
2328{
2329 for (const auto& command : commands)
2330 {
2331 if (command.get()->getPLDMType() == "platform" &&
2332 command.get()->getCommandName() == "getPDR")
2333 {
2334 auto getPDR = dynamic_cast<GetPDR*>(command.get());
2335 getPDR->parseGetPDROptions();
2336 }
2337 }
2338}
2339
George Liud6649362019-11-27 19:06:51 +08002340} // namespace platform
2341} // namespace pldmtool