blob: 21d0c8ad64f4b505af07f9fdf858d7dec390d564 [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>
10#include <map>
Thu Nguyen846d38f2022-03-26 08:57:21 +070011#include <ranges>
Brad Bishop02d71142021-10-14 19:00:17 -040012
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -050013#ifdef OEM_IBM
14#include "oem/ibm/oem_ibm_state_set.hpp"
15#endif
16
Brad Bishop5079ac42021-08-19 18:35:06 -040017using namespace pldm::utils;
18
George Liud6649362019-11-27 19:06:51 +080019namespace pldmtool
20{
George Liud6649362019-11-27 19:06:51 +080021namespace platform
22{
George Liud6649362019-11-27 19:06:51 +080023namespace
24{
George Liud6649362019-11-27 19:06:51 +080025using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060026
27static const std::map<uint8_t, std::string> sensorPresState{
28 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
29 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
30 {PLDM_SENSOR_WARNING, "Sensor Warning"},
31 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
32 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
33 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
34 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
35 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
36 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
37 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
38 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
39
40static const std::map<uint8_t, std::string> sensorOpState{
41 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
42 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
43 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
44 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
45 {PLDM_SENSOR_FAILED, "Sensor Failed"},
Manojkiran Eda2576aec2024-06-17 12:05:17 +053046 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Initializing"},
Sridevi Rameshf31b5042021-01-22 05:42:07 -060047 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
48 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
49
George Liud6649362019-11-27 19:06:51 +080050std::vector<std::unique_ptr<CommandInterface>> commands;
51
52} // namespace
53
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050054using ordered_json = nlohmann::ordered_json;
55
George Liud6649362019-11-27 19:06:51 +080056class GetPDR : public CommandInterface
57{
58 public:
59 ~GetPDR() = default;
60 GetPDR() = delete;
61 GetPDR(const GetPDR&) = delete;
62 GetPDR(GetPDR&&) = default;
63 GetPDR& operator=(const GetPDR&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -050064 GetPDR& operator=(GetPDR&&) = delete;
George Liud6649362019-11-27 19:06:51 +080065
66 using CommandInterface::CommandInterface;
67
George Liud6649362019-11-27 19:06:51 +080068 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
Potin Lai3e52d582024-06-13 11:03:46 +080069 CommandInterface(type, name, app), dataTransferHandle(0),
70 operationFlag(PLDM_GET_FIRSTPART), requestCount(UINT16_MAX),
71 recordChangeNumber(0), nextPartRequired(false)
George Liud6649362019-11-27 19:06:51 +080072 {
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050073 auto pdrOptionGroup = app->add_option_group(
74 "Required Option",
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060075 "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 -050076 pdrOptionGroup->add_option(
77 "-d,--data", recordHandle,
78 "retrieve individual PDRs from a PDR Repository\n"
79 "eg: The recordHandle value for the PDR to be retrieved and 0 "
80 "means get first PDR in the repository.");
81 pdrRecType = "";
82 pdrOptionGroup->add_option("-t, --type", pdrRecType,
83 "retrieve all PDRs of the requested type\n"
84 "supported types:\n"
85 "[terminusLocator, stateSensor, "
86 "numericEffecter, stateEffecter, "
Thu Nguyen846d38f2022-03-26 08:57:21 +070087 "compactNumericSensor, sensorauxname, "
nothingIIersonalcea52d92024-03-21 13:56:02 +030088 "efffecterAuxName, numericsensor, "
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050089 "EntityAssociation, fruRecord, ... ]");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060090
91 getPDRGroupOption = pdrOptionGroup->add_option(
92 "-i, --terminusID", pdrTerminus,
93 "retrieve all PDRs of the requested terminusID\n"
94 "supported IDs:\n [1, 2, 208...]");
95
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050096 allPDRs = false;
97 pdrOptionGroup->add_flag("-a, --all", allPDRs,
98 "retrieve all PDRs from a PDR repository");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060099
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500100 pdrOptionGroup->require_option(1);
101 }
102
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600103 void parseGetPDROptions()
104 {
105 optTIDSet = false;
106 if (getPDRGroupOption->count() > 0)
107 {
108 optTIDSet = true;
109 getPDRs();
110 }
111 }
112
113 void getPDRs()
114 {
115 // start the array
116 std::cout << "[";
117
118 recordHandle = 0;
119 do
120 {
121 CommandInterface::exec();
122 } while (recordHandle != 0);
123
124 // close the array
125 std::cout << "]\n";
126
127 if (handleFound)
128 {
129 recordHandle = 0;
130 uint32_t prevRecordHandle = 0;
131 do
132 {
133 CommandInterface::exec();
134 if (recordHandle == prevRecordHandle)
135 {
136 return;
137 }
138 prevRecordHandle = recordHandle;
139 } while (recordHandle != 0);
140 }
141 }
142
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500143 void exec() override
144 {
145 if (allPDRs || !pdrRecType.empty())
146 {
147 if (!pdrRecType.empty())
148 {
149 std::transform(pdrRecType.begin(), pdrRecType.end(),
150 pdrRecType.begin(), tolower);
151 }
152
Brad Bishop16eff862021-10-14 19:44:32 -0400153 // start the array
154 std::cout << "[\n";
155
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500156 // Retrieve all PDR records starting from the first
157 recordHandle = 0;
158 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400159 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500160 do
161 {
162 CommandInterface::exec();
163 // recordHandle is updated to nextRecord when
164 // CommandInterface::exec() is successful.
165 // In case of any error, return.
Potin Lai3e52d582024-06-13 11:03:46 +0800166 if (recordHandle == prevRecordHandle && !nextPartRequired)
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500167 {
168 return;
169 }
Brad Bishop02d71142021-10-14 19:00:17 -0400170
171 // check for circular references.
Patrick Williams6da4f912023-05-10 07:50:53 -0500172 auto result = recordsSeen.emplace(recordHandle,
173 prevRecordHandle);
Potin Lai3e52d582024-06-13 11:03:46 +0800174 if (!result.second && !nextPartRequired)
Brad Bishop02d71142021-10-14 19:00:17 -0400175 {
176 std::cerr
177 << "Record handle " << recordHandle
178 << " has multiple references: " << result.first->second
179 << ", " << prevRecordHandle << "\n";
180 return;
181 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500182 prevRecordHandle = recordHandle;
Brad Bishop16eff862021-10-14 19:44:32 -0400183
184 if (recordHandle != 0)
185 {
186 // close the array
187 std::cout << ",";
188 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500189 } while (recordHandle != 0);
Brad Bishop16eff862021-10-14 19:44:32 -0400190
191 // close the array
192 std::cout << "]\n";
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500193 }
194 else
195 {
Potin Lai3e52d582024-06-13 11:03:46 +0800196 do
197 {
198 CommandInterface::exec();
199 } while (nextPartRequired);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500200 }
George Liud6649362019-11-27 19:06:51 +0800201 }
202
203 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
204 {
205 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
206 PLDM_GET_PDR_REQ_BYTES);
207 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
208
Potin Lai3e52d582024-06-13 11:03:46 +0800209 auto rc = encode_get_pdr_req(
210 instanceId, recordHandle, dataTransferHandle, operationFlag,
211 requestCount, recordChangeNumber, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800212 return {rc, requestMsg};
213 }
214
215 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
216 {
217 uint8_t completionCode = 0;
Potin Lai3e52d582024-06-13 11:03:46 +0800218 uint8_t respRecordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800219 uint32_t nextRecordHndl = 0;
220 uint32_t nextDataTransferHndl = 0;
221 uint8_t transferFlag = 0;
222 uint16_t respCnt = 0;
223 uint8_t transferCRC = 0;
224
225 auto rc = decode_get_pdr_resp(
226 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
Potin Lai3e52d582024-06-13 11:03:46 +0800227 &nextDataTransferHndl, &transferFlag, &respCnt, respRecordData,
228 sizeof(respRecordData), &transferCRC);
George Liud6649362019-11-27 19:06:51 +0800229
230 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
231 {
232 std::cerr << "Response Message Error: "
233 << "rc=" << rc << ",cc=" << (int)completionCode
234 << std::endl;
Potin Lai3e52d582024-06-13 11:03:46 +0800235 nextPartRequired = false;
George Liud6649362019-11-27 19:06:51 +0800236 return;
237 }
238
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600239 if (optTIDSet && !handleFound)
240 {
Potin Lai3e52d582024-06-13 11:03:46 +0800241 terminusHandle = getTerminusHandle(respRecordData, pdrTerminus);
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600242 if (terminusHandle.has_value())
243 {
244 recordHandle = 0;
245 return;
246 }
247 else
248 {
249 recordHandle = nextRecordHndl;
250 return;
251 }
252 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600253 else
254 {
Potin Lai3e52d582024-06-13 11:03:46 +0800255 recordData.insert(recordData.end(), respRecordData,
256 respRecordData + respCnt);
257
258 // End or StartAndEnd
259 if (transferFlag == PLDM_PLATFORM_TRANSFER_END ||
260 transferFlag == PLDM_PLATFORM_TRANSFER_START_AND_END)
261 {
262 printPDRMsg(nextRecordHndl, respCnt, recordData.data(),
263 terminusHandle);
264 nextPartRequired = false;
265 recordHandle = nextRecordHndl;
266 dataTransferHandle = 0;
267 recordChangeNumber = 0;
268 operationFlag = PLDM_GET_FIRSTPART;
269 recordData.clear();
270 }
271 else
272 {
273 nextPartRequired = true;
274 dataTransferHandle = nextDataTransferHndl;
275 struct pldm_pdr_hdr* pdr_hdr =
276 reinterpret_cast<struct pldm_pdr_hdr*>(respRecordData);
277 recordChangeNumber = pdr_hdr->record_change_num;
278 operationFlag = PLDM_GET_NEXTPART;
279 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600280 }
George Liud6649362019-11-27 19:06:51 +0800281 }
282
283 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530284 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530285 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
286 {PLDM_ENTITY_OTHER, "Other"},
287 {PLDM_ENTITY_NETWORK, "Network"},
288 {PLDM_ENTITY_GROUP, "Group"},
289 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
290 "Remote Management Communication Device"},
291 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
292 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
293 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
294 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
295 {PLDM_ENTITY_KEYPAD, "keypad"},
296 {PLDM_ENTITY_SWITCH, "Switch"},
297 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
298 {PLDM_ENTITY_DISPLAY, "Display"},
299 {PLDM_ENTITY_INDICATOR, "Indicator"},
300 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530301 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530302 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530303 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530304 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
305 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
306 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530307 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530308 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
309 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
310 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
311 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
312 {PLDM_ENTITY_DOOR, "Door"},
313 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
314 {PLDM_ENTITY_COVER, "Cover"},
315 {PLDM_ENTITY_BOARD, "Board"},
316 {PLDM_ENTITY_CARD, "Card"},
317 {PLDM_ENTITY_MODULE, "Module"},
318 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530319 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530320 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530321 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
322 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530323 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530324 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530325 "Chassis front panel board(control panel)"},
326 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
327 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
328 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
329 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
330 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
331 "System internal expansion board"},
332 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
333 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
334 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
335 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
336 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
337 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
338 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
339 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
340 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
341 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500342 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530343 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
344 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
345 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
346 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
347 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
348 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
349 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
350 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
351 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
352 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500353 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530354 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
355 {PLDM_ENTITY_BATTERY, "Battery"},
356 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
357 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
358 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
359 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
360 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
361 {PLDM_ENTITY_PROC, "Processor"},
362 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
363 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
364 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
365 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
366 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
367 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
368 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
369 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
370 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
371 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
372 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500373 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530374 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
375 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
376 {PLDM_ENTITY_SYS_BUS, "System Bus"},
377 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
378 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
379 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
380 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
381 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
382 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
383 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
384 {PLDM_ENTITY_USB_BUS, "USB Bus"},
385 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
386 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
387 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
388 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
389 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
390 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500391 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530392 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
393 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
394 {PLDM_ENTITY_PLUG, "Plug"},
395 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500396 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500397
Tom Josepha65c0412020-07-03 21:14:44 +0530398 const std::map<uint16_t, std::string> stateSet = {
399 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
400 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530401 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
402 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
403 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
404 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
405 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530406 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530407 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
408 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530409 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
410 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530411 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
412 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530413 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530414 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530415 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530416 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
417 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
418 {PLDM_STATE_SET_VERSION, "Version"},
419 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
420 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
421 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
422 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530423 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530424 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
425 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
426 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
427 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
428 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
429 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
430 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
431 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
432 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
433 "Physical Communication Connection"},
434 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
435 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
436 "Foreign Network Detection Status"},
437 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
438 "Password-Protected Access Security"},
439 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
440 "Security Access –PrivilegeLevel"},
441 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530442 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530443 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530444 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530445 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
446 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
447 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530448 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530449 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
450 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
451 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
452 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
453 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
454 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
455 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
456 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
457 "Diagnostic Interrupt Requested"},
458 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
459 "Diagnostic Interrupt Received"},
460 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
461 "I/O Channel Check NMI Requested"},
462 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
463 "I/O Channel Check NMI Received"},
464 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
465 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
466 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
467 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
468 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
469 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
470 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
471 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
472 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
473 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
474 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
475 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
476 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
477 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
478 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
479 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
480 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
481 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
482 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
483 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
484 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
485 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
486 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
487 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
488 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
489 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
490 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
491 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
492 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
493 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
494 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
495 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
496 "Redundant Memory Activity Status"},
497 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
498 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
499 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
500 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500501 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
502 };
Tom Josepha65c0412020-07-03 21:14:44 +0530503
504 const std::array<std::string_view, 4> sensorInit = {
505 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
506
Tom Joseph97a7a762020-07-06 10:37:18 +0530507 const std::array<std::string_view, 4> effecterInit = {
508 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
509
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500510 const std::map<uint8_t, std::string> pdrType = {
511 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
512 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
513 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
514 "Numeric Sensor Initialization PDR"},
515 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
516 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
517 "State Sensor Initialization PDR"},
518 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
519 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
520 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
521 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
522 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
523 "Numeric Effecter Initialization PDR"},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700524 {PLDM_COMPACT_NUMERIC_SENSOR_PDR, "Compact Numeric Sensor PDR"},
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500525 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
526 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
527 "State Effecter Initialization PDR"},
528 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
529 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
530 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
531 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
532 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
533 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
534 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
535 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
536 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
537 {PLDM_OEM_PDR, "OEM PDR"},
538 };
539
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500540 static inline const std::map<uint8_t, std::string> setThermalTrip{
541 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
542 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
543
544 static inline const std::map<uint8_t, std::string> setIdentifyState{
545 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
546 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
547
548 static inline const std::map<uint8_t, std::string> setBootProgressState{
549 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
550 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
551 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
552 "Memory Initialization"},
553 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
554 "Secondary Processor(s) Initialization"},
555 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
556 "PCI Resource Configuration"},
557 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
558 "Starting Operating System"},
559 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
560 "Baseboard Initialization"},
561 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
kamal00a076d2022-11-08 04:24:36 -0600562 "Primary Processor Initialization"},
563 {PLDM_STATE_SET_BOOT_PROG_STATE_OSSTART, "OSStart"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500564
565 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -0500566 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
567 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_ERROR, "Error"},
568 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NON_RECOVERABLE_ERROR,
569 "Non Recoverable Error"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500570
571 static inline const std::map<uint8_t, std::string> setSysPowerState{
572 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
573 "Off-Soft Graceful"}};
574
575 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
576 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
577 "Graceful Restart Requested"}};
578
579 static inline const std::map<uint8_t, std::string> setAvailability{
580 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
581
582 static inline const std::map<uint8_t, std::string> setHealthState{
583 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530584 {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"},
585 {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"},
586 {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"},
587 {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"},
588 {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500589 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530590 {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"},
591 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"},
592 {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}};
593
594 static inline const std::map<uint8_t, std::string>
595 setOperationalRunningState{
596 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"},
597 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"},
598 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"},
599 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE,
600 "In Service"},
601 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"},
602 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500603
Riya Dixit43e33d22024-02-07 09:53:49 -0600604 static inline const std::map<uint8_t, std::string> setPowerDeviceState{
605 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_UNKNOWN, "Unknown"},
606 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_FULLY_ON, "Fully-On"},
607 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_1,
608 "Intermediate State-1"},
609 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_2,
610 "Intermediate State-2"},
611 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_OFF, "Off"}};
612
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500613 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
614 populatePStateMaps{
615 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
616 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
617 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
618 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
619 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
620 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
621 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
622 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530623 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
624 setOperationalRunningState},
Riya Dixit43e33d22024-02-07 09:53:49 -0600625 {PLDM_STATE_SET_DEVICE_POWER_STATE, setPowerDeviceState},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500626 };
627
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500628 const std::map<std::string, uint8_t> strToPdrType = {
629 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
630 {"statesensor", PLDM_STATE_SENSOR_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700631 {"sensorauxname", PLDM_SENSOR_AUXILIARY_NAMES_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500632 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700633 {"efffecterauxname", PLDM_EFFECTER_AUXILIARY_NAMES_PDR},
nothingIIersonalcea52d92024-03-21 13:56:02 +0300634 {"numericsensor", PLDM_NUMERIC_SENSOR_PDR},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700635 {"compactnumericsensor", PLDM_COMPACT_NUMERIC_SENSOR_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500636 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
637 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
638 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
639 // Add other types
640 };
641
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530642 bool isLogicalBitSet(const uint16_t entity_type)
643 {
644 return entity_type & 0x8000;
645 }
646
647 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
648 {
649 return logical_entity_type & 0x7FFF;
650 }
651
Tom Josepha65c0412020-07-03 21:14:44 +0530652 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500653 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530654 uint16_t entityNumber = type;
655 std::string entityName = "[Physical] ";
656
657 if (isLogicalBitSet(type))
658 {
659 entityName = "[Logical] ";
660 entityNumber = getEntityTypeForLogicalEntity(type);
661 }
662
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500663 try
664 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530665 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500666 }
667 catch (const std::out_of_range& e)
668 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500669 auto OemString =
670 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530671 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
672 type <= PLDM_OEM_ENTITY_TYPE_END)
673 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500674#ifdef OEM_IBM
675 if (OemIBMEntityType.contains(entityNumber))
676 {
677 return entityName + OemIBMEntityType.at(entityNumber) +
678 "(OEM)";
679 }
680#endif
681 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530682 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500683 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500684 }
685 }
686
Tom Josepha65c0412020-07-03 21:14:44 +0530687 std::string getStateSetName(uint16_t id)
688 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500689 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530690 try
691 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500692 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530693 }
694 catch (const std::out_of_range& e)
695 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500696 return typeString;
697 }
698 }
699
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500700 std::vector<std::string>
701 getStateSetPossibleStateNames(uint16_t stateId,
702 const std::vector<uint8_t>& value)
703 {
704 std::vector<std::string> data{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500705
Pavithra Barithaya15b94112024-04-10 02:42:12 -0500706 for (const auto& s : value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500707 {
708 std::map<uint8_t, std::string> stateNameMaps;
709 auto pstr = std::to_string(s);
710
711#ifdef OEM_IBM
Manojkiran Edabe1a8572022-01-06 11:20:36 +0530712 if (stateId >= PLDM_OEM_STATE_SET_ID_START &&
713 stateId < PLDM_OEM_STATE_SET_ID_END)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500714 {
715 if (populateOemIBMStateMaps.contains(stateId))
716 {
717 const std::map<uint8_t, std::string> stateNames =
718 populateOemIBMStateMaps.at(stateId);
719 stateNameMaps.insert(stateNames.begin(), stateNames.end());
720 }
721 }
722#endif
723 if (populatePStateMaps.contains(stateId))
724 {
725 const std::map<uint8_t, std::string> stateNames =
726 populatePStateMaps.at(stateId);
727 stateNameMaps.insert(stateNames.begin(), stateNames.end());
728 }
729 if (stateNameMaps.contains(s))
730 {
731 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
732 }
733 else
734 {
735 data.push_back(pstr);
736 }
737 }
738 return data;
739 }
740
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500741 std::string getPDRType(uint8_t type)
742 {
743 auto typeString = std::to_string(type);
744 try
745 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500746 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500747 }
748 catch (const std::out_of_range& e)
749 {
750 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530751 }
752 }
753
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500754 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530755 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500756 output["recordHandle"] = hdr->record_handle;
757 output["PDRHeaderVersion"] = unsigned(hdr->version);
758 output["PDRType"] = getPDRType(hdr->type);
759 output["recordChangeNumber"] = hdr->record_change_num;
760 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530761 }
762
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500763 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
764 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530765 {
766 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500767 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500768 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
769 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530770 for (int i = 0; i < CHAR_BIT; i++)
771 {
772 if (val.byte & (1 << i))
773 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500774 pstates << (possibleStatesPos * CHAR_BIT + i);
775 data.push_back(
776 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600777 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530778 }
779 }
780 possibleStatesPos++;
781 };
782 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500783 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530784 }
785
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500786 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530787 {
788 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500789 output["PLDMTerminusHandle"] = pdr->terminus_handle;
790 output["sensorID"] = pdr->sensor_id;
791 output["entityType"] = getEntityName(pdr->entity_type);
792 output["entityInstanceNumber"] = pdr->entity_instance;
793 output["containerID"] = pdr->container_id;
794 output["sensorInit"] = sensorInit[pdr->sensor_init];
795 output["sensorAuxiliaryNamesPDR"] =
796 (pdr->sensor_auxiliary_names_pdr ? true : false);
797 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530798
799 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600800 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530801
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600802 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530803 {
804 auto state = reinterpret_cast<const state_sensor_possible_states*>(
805 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600806 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
807 getStateSetName(state->state_set_id));
808 output.emplace(
809 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
810 state->possible_states_size);
811 output.emplace(
812 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500813 getStateSetPossibleStateNames(
814 state->state_set_id,
815 printPossibleStates(state->possible_states_size,
816 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530817
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600818 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530819 {
820 statesPtr += sizeof(state_sensor_possible_states) +
821 state->possible_states_size - 1;
822 }
823 }
824 }
825
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500826 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500827 {
George Liu62d12ec2020-02-05 16:27:08 +0800828 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500829 {
830 return;
831 }
832
833 data += sizeof(pldm_pdr_hdr);
834 pldm_pdr_fru_record_set* pdr =
835 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530836 if (!pdr)
837 {
838 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
839 return;
840 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500841
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500842 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
843 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
844 output["entityType"] = getEntityName(pdr->entity_type);
Sagar Srinivasebf8bb52023-10-06 01:15:55 -0500845 output["entityInstanceNumber"] = unsigned(pdr->entity_instance);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500846 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500847 }
848
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500849 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500850 {
851 const std::map<uint8_t, const char*> assocationType = {
852 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
853 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
854 };
855
George Liu62d12ec2020-02-05 16:27:08 +0800856 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500857 {
858 return;
859 }
860
861 data += sizeof(pldm_pdr_hdr);
862 pldm_pdr_entity_association* pdr =
863 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530864 if (!pdr)
865 {
866 std::cerr << "Failed to get the PDR eneity association"
867 << std::endl;
868 return;
869 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500870
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500871 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800872 if (assocationType.contains(pdr->association_type))
873 {
874 output["associationType"] =
875 assocationType.at(pdr->association_type);
876 }
877 else
878 {
879 std::cout << "Get associationType failed.\n";
880 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500881 output["containerEntityType"] =
882 getEntityName(pdr->container.entity_type);
883 output["containerEntityInstanceNumber"] =
884 int(pdr->container.entity_instance_num);
885 output["containerEntityContainerID"] =
886 int(pdr->container.entity_container_id);
887 output["containedEntityCount"] =
888 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500889
890 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
891 for (int i = 0; i < pdr->num_children; ++i)
892 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500893 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
894 getEntityName(child->entity_type));
895 output.emplace("containedEntityInstanceNumber[" +
896 std::to_string(i + 1) + "]",
897 unsigned(child->entity_instance_num));
898 output.emplace("containedEntityContainerID[" +
899 std::to_string(i + 1) + "]",
900 unsigned(child->entity_container_id));
901
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500902 ++child;
903 }
904 }
905
Thu Nguyen846d38f2022-03-26 08:57:21 +0700906 /** @brief Format the Sensor/Effecter Aux Name PDR types to json output
907 *
908 * @param[in] data - reference to the Sensor/Effecter Aux Name PDR
909 * @param[out] output - PDRs data fields in Json format
910 */
911 void printAuxNamePDR(uint8_t* data, ordered_json& output)
912 {
913 constexpr uint8_t nullTerminator = 0;
914 struct pldm_effecter_aux_name_pdr* auxNamePdr =
915 (struct pldm_effecter_aux_name_pdr*)data;
916
917 if (!auxNamePdr)
918 {
919 std::cerr << "Failed to get Aux Name PDR" << std::endl;
920 return;
921 }
922
923 std::string sPrefix = "effecter";
924 if (auxNamePdr->hdr.type == PLDM_SENSOR_AUXILIARY_NAMES_PDR)
925 {
926 sPrefix = "sensor";
927 }
928 output["terminusHandle"] = int(auxNamePdr->terminus_handle);
929 output[sPrefix + "Id"] = int(auxNamePdr->effecter_id);
930 output[sPrefix + "Count"] = int(auxNamePdr->effecter_count);
931
932 const uint8_t* ptr = auxNamePdr->effecter_names;
933 for (auto i : std::views::iota(0, (int)auxNamePdr->effecter_count))
934 {
935 const uint8_t nameStringCount = static_cast<uint8_t>(*ptr);
936 ptr += sizeof(uint8_t);
937 for (auto j : std::views::iota(0, (int)nameStringCount))
938 {
939 std::string nameLanguageTagKey = sPrefix + std::to_string(j) +
940 "_nameLanguageTag" +
941 std::to_string(i);
942 std::string entityAuxNameKey = sPrefix + std::to_string(j) +
943 "_entityAuxName" +
944 std::to_string(i);
945 std::string nameLanguageTag(reinterpret_cast<const char*>(ptr),
946 0, PLDM_STR_UTF_8_MAX_LEN);
947 ptr += nameLanguageTag.size() + sizeof(nullTerminator);
948 std::u16string u16NameString(
949 reinterpret_cast<const char16_t*>(ptr), 0,
950 PLDM_STR_UTF_16_MAX_LEN);
951 ptr += (u16NameString.size() + sizeof(nullTerminator)) *
952 sizeof(uint16_t);
953 std::transform(u16NameString.cbegin(), u16NameString.cend(),
954 u16NameString.begin(),
955 [](uint16_t utf16) { return be16toh(utf16); });
956 std::string nameString =
957 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
958 char16_t>{}
959 .to_bytes(u16NameString);
960 output[nameLanguageTagKey] = nameLanguageTag;
961 output[entityAuxNameKey] = nameString;
962 }
963 }
964 }
965
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500966 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800967 {
968 struct pldm_numeric_effecter_value_pdr* pdr =
969 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530970 if (!pdr)
971 {
972 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
973 return;
974 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500975
976 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
977 output["effecterID"] = int(pdr->effecter_id);
978 output["entityType"] = int(pdr->entity_type);
979 output["entityInstanceNumber"] = int(pdr->entity_instance);
980 output["containerID"] = int(pdr->container_id);
981 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
982 output["effecterInit"] = unsigned(pdr->effecter_init);
983 output["effecterAuxiliaryNames"] =
984 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
985 output["baseUnit"] = unsigned(pdr->base_unit);
986 output["unitModifier"] = unsigned(pdr->unit_modifier);
987 output["rateUnit"] = unsigned(pdr->rate_unit);
988 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
989 output["auxUnit"] = unsigned(pdr->aux_unit);
990 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
991 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
992 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
993 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
994 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
995 output["resolution"] = unsigned(pdr->resolution);
996 output["offset"] = unsigned(pdr->offset);
997 output["accuracy"] = unsigned(pdr->accuracy);
998 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
999 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
1000 output["stateTransitionInterval"] =
1001 unsigned(pdr->state_transition_interval);
1002 output["TransitionInterval"] = unsigned(pdr->transition_interval);
1003
George Liu62d12ec2020-02-05 16:27:08 +08001004 switch (pdr->effecter_data_size)
1005 {
1006 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301007 output["maxSettable"] = unsigned(pdr->max_settable.value_u8);
1008 output["minSettable"] = unsigned(pdr->min_settable.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001009 break;
1010 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301011 output["maxSettable"] = unsigned(pdr->max_settable.value_s8);
1012 output["minSettable"] = unsigned(pdr->min_settable.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001013 break;
1014 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301015 output["maxSettable"] = unsigned(pdr->max_settable.value_u16);
1016 output["minSettable"] = unsigned(pdr->min_settable.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001017 break;
1018 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301019 output["maxSettable"] = unsigned(pdr->max_settable.value_s16);
1020 output["minSettable"] = unsigned(pdr->min_settable.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001021 break;
1022 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301023 output["maxSettable"] = unsigned(pdr->max_settable.value_u32);
1024 output["minSettable"] = unsigned(pdr->min_settable.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001025 break;
1026 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301027 output["maxSettable"] = unsigned(pdr->max_settable.value_s32);
1028 output["minSettable"] = unsigned(pdr->min_settable.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001029 break;
1030 default:
1031 break;
1032 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001033
1034 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
1035 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1036
George Liu62d12ec2020-02-05 16:27:08 +08001037 switch (pdr->range_field_format)
1038 {
1039 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001040 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
1041 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
1042 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
1043 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
1044 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001045 break;
1046 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001047 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
1048 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
1049 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
1050 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
1051 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001052 break;
1053 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001054 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
1055 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
1056 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
1057 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
1058 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001059 break;
1060 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001061 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
1062 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
1063 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
1064 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
1065 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001066 break;
1067 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001068 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
1069 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
1070 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
1071 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
1072 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001073 break;
1074 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001075 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
1076 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
1077 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
1078 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
1079 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001080 break;
1081 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001082 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
1083 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
1084 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
1085 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
1086 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +08001087 break;
1088 default:
1089 break;
1090 }
1091 }
1092
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001093 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +08001094 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301095 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +08001096
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001097 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1098 output["effecterID"] = pdr->effecter_id;
1099 output["entityType"] = getEntityName(pdr->entity_type);
1100 output["entityInstanceNumber"] = pdr->entity_instance;
1101 output["containerID"] = pdr->container_id;
1102 output["effecterSemanticID"] = pdr->effecter_semantic_id;
1103 output["effecterInit"] = effecterInit[pdr->effecter_init];
Patrick Williams6da4f912023-05-10 07:50:53 -05001104 output["effecterDescriptionPDR"] = (pdr->has_description_pdr ? true
1105 : false);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001106 output["compositeEffecterCount"] =
1107 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +08001108
Tom Joseph97a7a762020-07-06 10:37:18 +05301109 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001110 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +05301111
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001112 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +08001113 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301114 auto state =
1115 reinterpret_cast<const state_effecter_possible_states*>(
1116 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001117 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
1118 getStateSetName(state->state_set_id));
1119 output.emplace(
1120 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
1121 state->possible_states_size);
1122 output.emplace(
1123 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05001124 getStateSetPossibleStateNames(
1125 state->state_set_id,
1126 printPossibleStates(state->possible_states_size,
1127 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001128
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001129 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +05301130 {
1131 statesPtr += sizeof(state_effecter_possible_states) +
1132 state->possible_states_size - 1;
1133 }
George Liud6649362019-11-27 19:06:51 +08001134 }
1135 }
1136
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001137 bool checkTerminusHandle(const uint8_t* data,
1138 std::optional<uint16_t> terminusHandle)
1139 {
1140 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1141
1142 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1143 {
1144 auto tlpdr =
1145 reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1146
1147 if (tlpdr->terminus_handle != terminusHandle)
1148 {
1149 return true;
1150 }
1151 }
1152 else if (pdr->type == PLDM_STATE_SENSOR_PDR)
1153 {
1154 auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
1155
1156 if (sensor->terminus_handle != terminusHandle)
1157 {
1158 return true;
1159 }
1160 }
1161 else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR)
1162 {
1163 auto numericEffecter =
1164 reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data);
1165
1166 if (numericEffecter->terminus_handle != terminusHandle)
1167 {
1168 return true;
1169 }
1170 }
1171
1172 else if (pdr->type == PLDM_STATE_EFFECTER_PDR)
1173 {
1174 auto stateEffecter =
1175 reinterpret_cast<const pldm_state_effecter_pdr*>(data);
1176 if (stateEffecter->terminus_handle != terminusHandle)
1177 {
1178 return true;
1179 }
1180 }
1181 else if (pdr->type == PLDM_PDR_FRU_RECORD_SET)
1182 {
1183 data += sizeof(pldm_pdr_hdr);
1184 auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data);
1185
1186 if (fru->terminus_handle != terminusHandle)
1187 {
1188 return true;
1189 }
1190 }
1191 else
1192 {
1193 // Entity association PDRs does not have terminus handle
1194 return true;
1195 }
1196
1197 return false;
1198 }
1199
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001200 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -05001201 {
1202 const std::array<std::string_view, 4> terminusLocatorType = {
1203 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
1204
1205 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1206
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001207 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1208 output["validity"] = (pdr->validity ? "valid" : "notValid");
1209 output["TID"] = unsigned(pdr->tid);
1210 output["containerID"] = pdr->container_id;
1211 output["terminusLocatorType"] =
1212 terminusLocatorType[pdr->terminus_locator_type];
1213 output["terminusLocatorValueSize"] =
1214 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -05001215
1216 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
1217 {
1218 auto locatorValue =
1219 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
1220 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001221 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -05001222 }
1223 }
1224
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001225 std::optional<uint16_t> getTerminusHandle(uint8_t* data,
1226 std::optional<uint8_t> tid)
1227 {
1228 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1229 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1230 {
1231 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1232 if (pdr->tid == tid)
1233 {
1234 handleFound = true;
1235 return pdr->terminus_handle;
1236 }
1237 }
1238 return std::nullopt;
1239 }
1240
nothingIIersonalcea52d92024-03-21 13:56:02 +03001241 /** @brief Format the Numeric Sensor PDR types to json output
1242 *
1243 * @param[in] data - reference to the Numeric Sensor PDR
1244 * @param[in] data_length - number of PDR data bytes
1245 * @param[out] output - PDRs data fields in Json format
1246 */
1247 void printNumericSensorPDR(const uint8_t* data, const uint16_t data_length,
1248 ordered_json& output)
1249 {
1250 struct pldm_numeric_sensor_value_pdr pdr;
1251 int rc = decode_numeric_sensor_pdr_data(data, (size_t)data_length,
1252 &pdr);
1253 if (rc != PLDM_SUCCESS)
1254 {
1255 std::cerr << "Failed to get numeric sensor PDR" << std::endl;
1256 return;
1257 }
1258 output["PLDMTerminusHandle"] = pdr.terminus_handle;
1259 output["sensorID"] = pdr.sensor_id;
1260 output["entityType"] = getEntityName(pdr.entity_type);
1261 output["entityInstanceNumber"] = pdr.entity_instance_num;
1262 output["containerID"] = pdr.container_id;
1263 output["sensorInit"] = pdr.sensor_init;
1264 output["sensorAuxiliaryNamesPDR"] =
1265 (pdr.sensor_auxiliary_names_pdr) ? true : false;
1266 output["baseUnit"] = pdr.base_unit;
1267 output["unitModifier"] = pdr.unit_modifier;
1268 output["rateUnit"] = pdr.rate_unit;
1269 output["baseOEMUnitHandle"] = pdr.base_oem_unit_handle;
1270 output["auxUnit"] = pdr.aux_unit;
1271 output["auxUnitModifier"] = pdr.aux_unit_modifier;
1272 output["auxrateUnit"] = pdr.aux_rate_unit;
1273 output["rel"] = pdr.rel;
1274 output["auxOEMUnitHandle"] = pdr.aux_oem_unit_handle;
1275 output["isLinear"] = (pdr.is_linear) ? true : false;
1276 output["sensorDataSize"] = pdr.sensor_data_size;
1277 output["resolution"] = pdr.resolution;
1278 output["offset"] = pdr.offset;
1279 output["accuracy"] = pdr.accuracy;
1280 output["plusTolerance"] = pdr.plus_tolerance;
1281 output["minusTolerance"] = pdr.minus_tolerance;
1282
1283 switch (pdr.sensor_data_size)
1284 {
1285 case PLDM_SENSOR_DATA_SIZE_UINT8:
1286 output["hysteresis"] = pdr.hysteresis.value_u8;
1287 output["maxReadable"] = pdr.max_readable.value_u8;
1288 output["minReadable"] = pdr.min_readable.value_u8;
1289 break;
1290 case PLDM_SENSOR_DATA_SIZE_SINT8:
1291 output["hysteresis"] = pdr.hysteresis.value_s8;
1292 output["maxReadable"] = pdr.max_readable.value_s8;
1293 output["minReadable"] = pdr.min_readable.value_s8;
1294 break;
1295 case PLDM_SENSOR_DATA_SIZE_UINT16:
1296 output["hysteresis"] = pdr.hysteresis.value_u16;
1297 output["maxReadable"] = pdr.max_readable.value_u16;
1298 output["minReadable"] = pdr.min_readable.value_u16;
1299 break;
1300 case PLDM_SENSOR_DATA_SIZE_SINT16:
1301 output["hysteresis"] = pdr.hysteresis.value_s16;
1302 output["maxReadable"] = pdr.max_readable.value_s16;
1303 output["minReadable"] = pdr.min_readable.value_s16;
1304 break;
1305 case PLDM_SENSOR_DATA_SIZE_UINT32:
1306 output["hysteresis"] = pdr.hysteresis.value_u32;
1307 output["maxReadable"] = pdr.max_readable.value_u32;
1308 output["minReadable"] = pdr.min_readable.value_u32;
1309 break;
1310 case PLDM_SENSOR_DATA_SIZE_SINT32:
1311 output["hysteresis"] = pdr.hysteresis.value_s32;
1312 output["maxReadable"] = pdr.max_readable.value_s32;
1313 output["minReadable"] = pdr.min_readable.value_s32;
1314 break;
1315 default:
1316 break;
1317 }
1318
1319 output["supportedThresholds"] = pdr.supported_thresholds.byte;
1320 output["thresholAndHysteresisVolatility"] =
1321 pdr.threshold_and_hysteresis_volatility.byte;
1322 output["stateTransitionInterval"] = pdr.state_transition_interval;
1323 output["updateInterval"] = pdr.update_interval;
1324 output["rangeFieldFormat"] = pdr.range_field_format;
1325 output["rangeFieldSupport"] = pdr.range_field_support.byte;
1326
1327 switch (pdr.range_field_format)
1328 {
1329 case PLDM_RANGE_FIELD_FORMAT_UINT8:
1330 output["nominalValue"] = pdr.nominal_value.value_u8;
1331 output["normalMax"] = pdr.normal_max.value_u8;
1332 output["normalMin"] = pdr.normal_min.value_u8;
1333 output["warningHigh"] = pdr.warning_high.value_u8;
1334 output["warningLow"] = pdr.warning_low.value_u8;
1335 output["criticalHigh"] = pdr.critical_high.value_u8;
1336 output["criticalLow"] = pdr.critical_low.value_u8;
1337 output["fatalHigh"] = pdr.fatal_high.value_u8;
1338 output["fatalLeow"] = pdr.fatal_low.value_u8;
1339 break;
1340 case PLDM_RANGE_FIELD_FORMAT_SINT8:
1341 output["nominalValue"] = pdr.nominal_value.value_s8;
1342 output["normalMax"] = pdr.normal_max.value_s8;
1343 output["normalMin"] = pdr.normal_min.value_s8;
1344 output["warningHigh"] = pdr.warning_high.value_s8;
1345 output["warningLow"] = pdr.warning_low.value_s8;
1346 output["criticalHigh"] = pdr.critical_high.value_s8;
1347 output["criticalLow"] = pdr.critical_low.value_s8;
1348 output["fatalHigh"] = pdr.fatal_high.value_s8;
1349 output["fatalLeow"] = pdr.fatal_low.value_s8;
1350 break;
1351 case PLDM_RANGE_FIELD_FORMAT_UINT16:
1352 output["nominalValue"] = pdr.nominal_value.value_u16;
1353 output["normalMax"] = pdr.normal_max.value_u16;
1354 output["normalMin"] = pdr.normal_min.value_u16;
1355 output["warningHigh"] = pdr.warning_high.value_u16;
1356 output["warningLow"] = pdr.warning_low.value_u16;
1357 output["criticalHigh"] = pdr.critical_high.value_u16;
1358 output["criticalLow"] = pdr.critical_low.value_u16;
1359 output["fatalHigh"] = pdr.fatal_high.value_u16;
1360 output["fatalLeow"] = pdr.fatal_low.value_u16;
1361 break;
1362 case PLDM_RANGE_FIELD_FORMAT_SINT16:
1363 output["nominalValue"] = pdr.nominal_value.value_s16;
1364 output["normalMax"] = pdr.normal_max.value_s16;
1365 output["normalMin"] = pdr.normal_min.value_s16;
1366 output["warningHigh"] = pdr.warning_high.value_s16;
1367 output["warningLow"] = pdr.warning_low.value_s16;
1368 output["criticalHigh"] = pdr.critical_high.value_s16;
1369 output["criticalLow"] = pdr.critical_low.value_s16;
1370 output["fatalHigh"] = pdr.fatal_high.value_s16;
1371 output["fatalLeow"] = pdr.fatal_low.value_s16;
1372 break;
1373 case PLDM_RANGE_FIELD_FORMAT_UINT32:
1374 output["nominalValue"] = pdr.nominal_value.value_u32;
1375 output["normalMax"] = pdr.normal_max.value_u32;
1376 output["normalMin"] = pdr.normal_min.value_u32;
1377 output["warningHigh"] = pdr.warning_high.value_u32;
1378 output["warningLow"] = pdr.warning_low.value_u32;
1379 output["criticalHigh"] = pdr.critical_high.value_u32;
1380 output["criticalLow"] = pdr.critical_low.value_u32;
1381 output["fatalHigh"] = pdr.fatal_high.value_u32;
1382 output["fatalLeow"] = pdr.fatal_low.value_u32;
1383 break;
1384 case PLDM_RANGE_FIELD_FORMAT_SINT32:
1385 output["nominalValue"] = pdr.nominal_value.value_s32;
1386 output["normalMax"] = pdr.normal_max.value_s32;
1387 output["normalMin"] = pdr.normal_min.value_s32;
1388 output["warningHigh"] = pdr.warning_high.value_s32;
1389 output["warningLow"] = pdr.warning_low.value_s32;
1390 output["criticalHigh"] = pdr.critical_high.value_s32;
1391 output["criticalLow"] = pdr.critical_low.value_s32;
1392 output["fatalHigh"] = pdr.fatal_high.value_s32;
1393 output["fatalLeow"] = pdr.fatal_low.value_s32;
1394 break;
1395 case PLDM_RANGE_FIELD_FORMAT_REAL32:
1396 output["nominalValue"] = pdr.nominal_value.value_f32;
1397 output["normalMax"] = pdr.normal_max.value_f32;
1398 output["normalMin"] = pdr.normal_min.value_f32;
1399 output["warningHigh"] = pdr.warning_high.value_f32;
1400 output["warningLow"] = pdr.warning_low.value_f32;
1401 output["criticalHigh"] = pdr.critical_high.value_f32;
1402 output["criticalLow"] = pdr.critical_low.value_f32;
1403 output["fatalHigh"] = pdr.fatal_high.value_f32;
1404 output["fatalLeow"] = pdr.fatal_low.value_f32;
1405 break;
1406 default:
1407 break;
1408 }
1409 }
1410
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001411 /** @brief Format the Compact Numeric Sensor PDR types to json output
1412 *
1413 * @param[in] data - reference to the Compact Numeric Sensor PDR
1414 * @param[out] output - PDRs data fields in Json format
1415 */
1416 void printCompactNumericSensorPDR(const uint8_t* data, ordered_json& output)
1417 {
1418 struct pldm_compact_numeric_sensor_pdr* pdr =
1419 (struct pldm_compact_numeric_sensor_pdr*)data;
1420 if (!pdr)
1421 {
1422 std::cerr << "Failed to get compact numeric sensor PDR"
1423 << std::endl;
1424 return;
1425 }
1426 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
1427 output["sensorID"] = int(pdr->sensor_id);
1428 output["entityType"] = getEntityName(pdr->entity_type);
1429 output["entityInstanceNumber"] = int(pdr->entity_instance);
1430 output["containerID"] = int(pdr->container_id);
1431 output["sensorNameStringByteLength"] = int(pdr->sensor_name_length);
1432 if (pdr->sensor_name_length == 0)
1433 {
1434 output["Name"] = std::format("PLDM_Device_TID{}_SensorId{}",
1435 unsigned(pdr->terminus_handle),
1436 unsigned(pdr->sensor_id));
1437 }
1438 else
1439 {
1440 std::string sTemp(reinterpret_cast<const char*>(pdr->sensor_name),
1441 pdr->sensor_name_length);
1442 output["Name"] = sTemp;
1443 }
1444 output["baseUnit"] = unsigned(pdr->base_unit);
1445 output["unitModifier"] = signed(pdr->unit_modifier);
1446 output["occurrenceRate"] = unsigned(pdr->occurrence_rate);
1447 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1448 if (pdr->range_field_support.bits.bit0)
1449 {
1450 output["warningHigh"] = int(pdr->warning_high);
1451 }
1452 if (pdr->range_field_support.bits.bit1)
1453 {
1454 output["warningLow"] = int(pdr->warning_low);
1455 }
1456 if (pdr->range_field_support.bits.bit2)
1457 {
1458 output["criticalHigh"] = int(pdr->critical_high);
1459 }
1460 if (pdr->range_field_support.bits.bit3)
1461 {
1462 output["criticalLow"] = int(pdr->critical_low);
1463 }
1464 if (pdr->range_field_support.bits.bit4)
1465 {
1466 output["fatalHigh"] = int(pdr->fatal_high);
1467 }
1468 if (pdr->range_field_support.bits.bit5)
1469 {
1470 output["fatalLow"] = int(pdr->fatal_low);
1471 }
1472 }
1473
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001474 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001475 uint8_t* data, std::optional<uint16_t> terminusHandle)
George Liud6649362019-11-27 19:06:51 +08001476 {
George Liu62d12ec2020-02-05 16:27:08 +08001477 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +08001478 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301479 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +08001480 return;
1481 }
1482
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001483 ordered_json output;
1484 output["nextRecordHandle"] = nextRecordHndl;
1485 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +08001486
1487 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301488 if (!pdr)
1489 {
1490 return;
1491 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001492
1493 if (!pdrRecType.empty())
1494 {
1495 // Need to return if the requested PDR type
1496 // is not supported
1497 if (!strToPdrType.contains(pdrRecType))
1498 {
1499 std::cerr << "PDR type '" << pdrRecType
1500 << "' is not supported or invalid\n";
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -05001501 // PDR type not supported, setting next record handle to
1502 // 0 to avoid looping through all PDR records
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001503 nextRecordHndl = 0;
1504 return;
1505 }
1506
1507 // Do not print PDR record if the current record
1508 // PDR type does not match with requested type
1509 if (pdr->type != strToPdrType.at(pdrRecType))
1510 {
1511 return;
1512 }
1513 }
1514
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001515 if (pdrTerminus.has_value())
1516 {
1517 if (checkTerminusHandle(data, terminusHandle))
1518 {
1519 std::cerr << "The Terminus handle doesn't match return"
1520 << std::endl;
1521 return;
1522 }
1523 }
1524
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001525 printCommonPDRHeader(pdr, output);
1526
George Liud6649362019-11-27 19:06:51 +08001527 switch (pdr->type)
1528 {
Sampa Misra12afe112020-05-25 11:40:44 -05001529 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001530 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001531 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301532 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001533 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301534 break;
George Liu62d12ec2020-02-05 16:27:08 +08001535 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001536 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001537 break;
nothingIIersonalcea52d92024-03-21 13:56:02 +03001538 case PLDM_NUMERIC_SENSOR_PDR:
1539 printNumericSensorPDR(data, respCnt, output);
1540 break;
Thu Nguyen846d38f2022-03-26 08:57:21 +07001541 case PLDM_SENSOR_AUXILIARY_NAMES_PDR:
1542 printAuxNamePDR(data, output);
1543 break;
1544 case PLDM_EFFECTER_AUXILIARY_NAMES_PDR:
1545 printAuxNamePDR(data, output);
1546 break;
George Liud6649362019-11-27 19:06:51 +08001547 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001548 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001549 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001550 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001551 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001552 break;
1553 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001554 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001555 break;
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001556 case PLDM_COMPACT_NUMERIC_SENSOR_PDR:
1557 printCompactNumericSensorPDR(data, output);
1558 break;
George Liud6649362019-11-27 19:06:51 +08001559 default:
1560 break;
1561 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001562 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001563 }
1564
1565 private:
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001566 bool optTIDSet = false;
George Liud6649362019-11-27 19:06:51 +08001567 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001568 bool allPDRs;
1569 std::string pdrRecType;
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001570 std::optional<uint8_t> pdrTerminus;
1571 std::optional<uint16_t> terminusHandle;
1572 bool handleFound = false;
1573 CLI::Option* getPDRGroupOption = nullptr;
Potin Lai3e52d582024-06-13 11:03:46 +08001574 uint32_t dataTransferHandle;
1575 uint8_t operationFlag;
1576 uint16_t requestCount;
1577 uint16_t recordChangeNumber;
1578 std::vector<uint8_t> recordData;
1579 bool nextPartRequired;
George Liud6649362019-11-27 19:06:51 +08001580};
1581
1582class SetStateEffecter : public CommandInterface
1583{
1584 public:
1585 ~SetStateEffecter() = default;
1586 SetStateEffecter() = delete;
1587 SetStateEffecter(const SetStateEffecter&) = delete;
1588 SetStateEffecter(SetStateEffecter&&) = default;
1589 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001590 SetStateEffecter& operator=(SetStateEffecter&&) = delete;
George Liud6649362019-11-27 19:06:51 +08001591
George Liuba4c1fb2020-02-05 14:13:30 +08001592 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1593 static constexpr auto maxEffecterDataSize = 16;
1594
1595 // compositeEffecterCount(value: 0x01 to 0x08)
1596 static constexpr auto minEffecterCount = 1;
1597 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001598 explicit SetStateEffecter(const char* type, const char* name,
1599 CLI::App* app) :
1600 CommandInterface(type, name, app)
1601 {
1602 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001603 "-i, --id", effecterId,
1604 "A handle that is used to identify and access the effecter")
1605 ->required();
1606 app->add_option("-c, --count", effecterCount,
1607 "The number of individual sets of effecter information")
1608 ->required();
1609 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001610 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001611 "Set effecter state data\n"
1612 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1613 ->required();
George Liud6649362019-11-27 19:06:51 +08001614 }
1615
1616 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1617 {
1618 std::vector<uint8_t> requestMsg(
1619 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
1620 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1621
George Liuba4c1fb2020-02-05 14:13:30 +08001622 if (effecterCount > maxEffecterCount ||
1623 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001624 {
George Liuba4c1fb2020-02-05 14:13:30 +08001625 std::cerr << "Request Message Error: effecterCount size "
1626 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001627 auto rc = PLDM_ERROR_INVALID_DATA;
1628 return {rc, requestMsg};
1629 }
1630
George Liuba4c1fb2020-02-05 14:13:30 +08001631 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001632 {
George Liuba4c1fb2020-02-05 14:13:30 +08001633 std::cerr << "Request Message Error: effecterData size "
1634 << effecterData.size() << "is invalid\n";
1635 auto rc = PLDM_ERROR_INVALID_DATA;
1636 return {rc, requestMsg};
1637 }
1638
1639 auto stateField = parseEffecterData(effecterData, effecterCount);
1640 if (!stateField)
1641 {
1642 std::cerr << "Failed to parse effecter data, effecterCount size "
1643 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001644 auto rc = PLDM_ERROR_INVALID_DATA;
1645 return {rc, requestMsg};
1646 }
1647
1648 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001649 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001650 return {rc, requestMsg};
1651 }
1652
1653 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1654 {
1655 uint8_t completionCode = 0;
1656 auto rc = decode_set_state_effecter_states_resp(
1657 responsePtr, payloadLength, &completionCode);
1658
1659 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1660 {
1661 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001662 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001663 return;
1664 }
1665
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001666 ordered_json data;
1667 data["Response"] = "SUCCESS";
1668 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001669 }
1670
1671 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001672 uint16_t effecterId;
1673 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001674 std::vector<uint8_t> effecterData;
1675};
1676
George Liucc9c20d2020-02-05 10:24:11 +08001677class SetNumericEffecterValue : public CommandInterface
1678{
1679 public:
1680 ~SetNumericEffecterValue() = default;
1681 SetNumericEffecterValue() = delete;
1682 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1683 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1684 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001685 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete;
George Liucc9c20d2020-02-05 10:24:11 +08001686
1687 explicit SetNumericEffecterValue(const char* type, const char* name,
1688 CLI::App* app) :
1689 CommandInterface(type, name, app)
1690 {
1691 app->add_option(
1692 "-i, --id", effecterId,
1693 "A handle that is used to identify and access the effecter")
1694 ->required();
1695 app->add_option("-s, --size", effecterDataSize,
1696 "The bit width and format of the setting value for the "
1697 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1698 "uint32, sint32}\n")
1699 ->required();
1700 app->add_option("-d,--data", maxEffecterValue,
1701 "The setting value of numeric effecter being "
1702 "requested\n")
1703 ->required();
1704 }
1705
1706 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1707 {
1708 std::vector<uint8_t> requestMsg(
1709 sizeof(pldm_msg_hdr) +
1710 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1711
1712 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1713
1714 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1715 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1716
1717 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1718 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1719 {
1720 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1721 }
1722 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1723 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1724 {
1725 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1726 }
1727 auto rc = encode_set_numeric_effecter_value_req(
1728 0, effecterId, effecterDataSize, effecterValue, request,
1729 payload_length);
1730
1731 return {rc, requestMsg};
1732 }
1733
1734 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1735 {
1736 uint8_t completionCode = 0;
1737 auto rc = decode_set_numeric_effecter_value_resp(
1738 responsePtr, payloadLength, &completionCode);
1739
1740 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1741 {
1742 std::cerr << "Response Message Error: "
1743 << "rc=" << rc << ",cc=" << (int)completionCode
1744 << std::endl;
1745 return;
1746 }
1747
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001748 ordered_json data;
1749 data["Response"] = "SUCCESS";
1750 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001751 }
1752
1753 private:
1754 uint16_t effecterId;
1755 uint8_t effecterDataSize;
1756 uint64_t maxEffecterValue;
1757};
1758
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001759class GetStateSensorReadings : public CommandInterface
1760{
1761 public:
1762 ~GetStateSensorReadings() = default;
1763 GetStateSensorReadings() = delete;
1764 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1765 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1766 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001767 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001768
1769 explicit GetStateSensorReadings(const char* type, const char* name,
1770 CLI::App* app) :
1771 CommandInterface(type, name, app)
1772 {
1773 app->add_option(
1774 "-i, --sensor_id", sensorId,
1775 "Sensor ID that is used to identify and access the sensor")
1776 ->required();
1777 app->add_option("-r, --rearm", sensorRearm,
1778 "Each bit location in this field corresponds to a "
1779 "particular sensor")
1780 ->required();
1781 }
1782
1783 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1784 {
1785 std::vector<uint8_t> requestMsg(
1786 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
1787 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1788
1789 uint8_t reserved = 0;
1790 bitfield8_t bf;
1791 bf.byte = sensorRearm;
1792 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1793 reserved, request);
1794
1795 return {rc, requestMsg};
1796 }
1797
1798 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1799 {
1800 uint8_t completionCode = 0;
1801 uint8_t compSensorCount = 0;
1802 std::array<get_sensor_state_field, 8> stateField{};
1803 auto rc = decode_get_state_sensor_readings_resp(
1804 responsePtr, payloadLength, &completionCode, &compSensorCount,
1805 stateField.data());
1806
1807 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1808 {
1809 std::cerr << "Response Message Error: "
1810 << "rc=" << rc << ",cc=" << (int)completionCode
1811 << std::endl;
1812 return;
1813 }
1814 ordered_json output;
1815 output["compositeSensorCount"] = (int)compSensorCount;
1816
1817 for (size_t i = 0; i < compSensorCount; i++)
1818 {
George Liubd5e2ea2021-04-22 20:33:06 +08001819 if (sensorOpState.contains(stateField[i].sensor_op_state))
1820 {
1821 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1822 sensorOpState.at(stateField[i].sensor_op_state));
1823 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001824
George Liubd5e2ea2021-04-22 20:33:06 +08001825 if (sensorPresState.contains(stateField[i].present_state))
1826 {
1827 output.emplace(("presentState[" + std::to_string(i) + "]"),
1828 sensorPresState.at(stateField[i].present_state));
1829 }
1830
1831 if (sensorPresState.contains(stateField[i].previous_state))
1832 {
1833 output.emplace(
1834 ("previousState[" + std::to_string(i) + "]"),
1835 sensorPresState.at(stateField[i].previous_state));
1836 }
1837
1838 if (sensorPresState.contains(stateField[i].event_state))
1839 {
1840 output.emplace(("eventState[" + std::to_string(i) + "]"),
1841 sensorPresState.at(stateField[i].event_state));
1842 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001843 }
1844
1845 pldmtool::helper::DisplayInJson(output);
1846 }
1847
1848 private:
1849 uint16_t sensorId;
1850 uint8_t sensorRearm;
1851};
1852
nothingIIersonal83e068a2024-03-21 13:55:06 +03001853class GetSensorReading : public CommandInterface
1854{
1855 public:
1856 ~GetSensorReading() = default;
1857 GetSensorReading() = delete;
1858 GetSensorReading(const GetSensorReading&) = delete;
1859 GetSensorReading(GetSensorReading&&) = default;
1860 GetSensorReading& operator=(const GetSensorReading&) = delete;
1861 GetSensorReading& operator=(GetSensorReading&&) = delete;
1862
1863 explicit GetSensorReading(const char* type, const char* name,
1864 CLI::App* app) :
1865 CommandInterface(type, name, app)
1866 {
1867 app->add_option(
1868 "-i, --sensor_id", sensorId,
1869 "Sensor ID that is used to identify and access the sensor")
1870 ->required();
1871 app->add_option("-r, --rearm", rearm,
1872 "Manually re-arm EventState after "
1873 "responding to this request")
1874 ->required();
1875 }
1876
1877 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1878 {
1879 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
1880 PLDM_GET_SENSOR_READING_REQ_BYTES);
1881 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1882
1883 auto rc = encode_get_sensor_reading_req(instanceId, sensorId, rearm,
1884 request);
1885
1886 return {rc, requestMsg};
1887 }
1888
1889 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1890 {
1891 uint8_t completionCode = 0;
1892 uint8_t sensorDataSize = 0;
1893 uint8_t sensorOperationalState = 0;
1894 uint8_t sensorEventMessageEnable = 0;
1895 uint8_t presentState = 0;
1896 uint8_t previousState = 0;
1897 uint8_t eventState = 0;
1898 std::array<uint8_t, sizeof(uint32_t)>
1899 presentReading{}; // maximum size for the present Value is uint32
1900 // according to spec DSP0248
1901
1902 auto rc = decode_get_sensor_reading_resp(
1903 responsePtr, payloadLength, &completionCode, &sensorDataSize,
1904 &sensorOperationalState, &sensorEventMessageEnable, &presentState,
1905 &previousState, &eventState, presentReading.data());
1906
1907 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1908 {
1909 std::cerr << "Response Message Error: "
1910 << "rc=" << rc << ",cc=" << (int)completionCode
1911 << std::endl;
1912 return;
1913 }
1914
1915 ordered_json output;
1916 output["sensorDataSize"] = getSensorState(sensorDataSize,
1917 &sensorDataSz);
1918 output["sensorOperationalState"] =
1919 getSensorState(sensorOperationalState, &sensorOpState);
1920 output["sensorEventMessageEnable"] =
1921 getSensorState(sensorEventMessageEnable, &sensorEventMsgEnable);
1922 output["presentState"] = getSensorState(presentState, &sensorPresState);
1923 output["previousState"] = getSensorState(previousState,
1924 &sensorPresState);
1925 output["eventState"] = getSensorState(eventState, &sensorPresState);
1926
1927 switch (sensorDataSize)
1928 {
1929 case PLDM_SENSOR_DATA_SIZE_UINT8:
1930 {
1931 output["presentReading"] =
1932 *(reinterpret_cast<uint8_t*>(presentReading.data()));
1933 break;
1934 }
1935 case PLDM_SENSOR_DATA_SIZE_SINT8:
1936 {
1937 output["presentReading"] =
1938 *(reinterpret_cast<int8_t*>(presentReading.data()));
1939 break;
1940 }
1941 case PLDM_SENSOR_DATA_SIZE_UINT16:
1942 {
1943 output["presentReading"] =
1944 *(reinterpret_cast<uint16_t*>(presentReading.data()));
1945 break;
1946 }
1947 case PLDM_SENSOR_DATA_SIZE_SINT16:
1948 {
1949 output["presentReading"] =
1950 *(reinterpret_cast<int16_t*>(presentReading.data()));
1951 break;
1952 }
1953 case PLDM_SENSOR_DATA_SIZE_UINT32:
1954 {
1955 output["presentReading"] =
1956 *(reinterpret_cast<uint32_t*>(presentReading.data()));
1957 break;
1958 }
1959 case PLDM_SENSOR_DATA_SIZE_SINT32:
1960 {
1961 output["presentReading"] =
1962 *(reinterpret_cast<int32_t*>(presentReading.data()));
1963 break;
1964 }
1965 default:
1966 {
1967 std::cerr << "Unknown Sensor Data Size : "
1968 << static_cast<int>(sensorDataSize) << std::endl;
1969 break;
1970 }
1971 }
1972
1973 pldmtool::helper::DisplayInJson(output);
1974 }
1975
1976 private:
1977 uint16_t sensorId;
1978 uint8_t rearm;
1979
1980 const std::map<uint8_t, std::string> sensorDataSz = {
1981 {PLDM_SENSOR_DATA_SIZE_UINT8, "uint8"},
1982 {PLDM_SENSOR_DATA_SIZE_SINT8, "uint8"},
1983 {PLDM_SENSOR_DATA_SIZE_UINT16, "uint16"},
1984 {PLDM_SENSOR_DATA_SIZE_SINT16, "uint16"},
1985 {PLDM_SENSOR_DATA_SIZE_UINT32, "uint32"},
1986 {PLDM_SENSOR_DATA_SIZE_SINT32, "uint32"}};
1987
1988 static inline const std::map<uint8_t, std::string> sensorEventMsgEnable{
1989 {PLDM_NO_EVENT_GENERATION, "Sensor No Event Generation"},
1990 {PLDM_EVENTS_DISABLED, "Sensor Events Disabled"},
1991 {PLDM_EVENTS_ENABLED, "Sensor Events Enabled"},
1992 {PLDM_OP_EVENTS_ONLY_ENABLED, "Sensor Op Events Only Enabled"},
1993 {PLDM_STATE_EVENTS_ONLY_ENABLED, "Sensor State Events Only Enabled"}};
1994
1995 std::string getSensorState(uint8_t state,
1996 const std::map<uint8_t, std::string>* cont)
1997 {
1998 auto typeString = std::to_string(state);
1999 try
2000 {
2001 return cont->at(state);
2002 }
2003 catch (const std::out_of_range& e)
2004 {
2005 return typeString;
2006 }
2007 }
2008};
2009
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002010class GetNumericEffecterValue : public CommandInterface
2011{
2012 public:
2013 ~GetNumericEffecterValue() = default;
2014 GetNumericEffecterValue() = delete;
2015 GetNumericEffecterValue(const GetNumericEffecterValue&) = delete;
2016 GetNumericEffecterValue(GetNumericEffecterValue&&) = default;
2017 GetNumericEffecterValue& operator=(const GetNumericEffecterValue&) = delete;
Pavithra Barithayaae088dc2023-11-09 01:14:05 -06002018 GetNumericEffecterValue& operator=(GetNumericEffecterValue&&) = delete;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002019
2020 explicit GetNumericEffecterValue(const char* type, const char* name,
2021 CLI::App* app) :
2022 CommandInterface(type, name, app)
2023 {
2024 app->add_option(
2025 "-i, --effecter_id", effecterId,
2026 "A handle that is used to identify and access the effecter")
2027 ->required();
2028 }
2029
2030 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2031 {
2032 std::vector<uint8_t> requestMsg(
2033 sizeof(pldm_msg_hdr) + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
2034 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
2035
2036 auto rc = encode_get_numeric_effecter_value_req(instanceId, effecterId,
2037 request);
2038
2039 return {rc, requestMsg};
2040 }
2041
2042 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2043 {
2044 uint8_t completionCode = 0;
2045 uint8_t effecterDataSize = 0;
2046 uint8_t effecterOperationalState = 0;
2047 std::array<uint8_t, sizeof(uint32_t)>
2048 pendingValue{}; // maximum size for the pending Value is uint32
2049 // according to spec DSP0248
2050 std::array<uint8_t, sizeof(uint32_t)>
2051 presentValue{}; // maximum size for the present Value is uint32
2052 // according to spec DSP0248
2053
2054 auto rc = decode_get_numeric_effecter_value_resp(
2055 responsePtr, payloadLength, &completionCode, &effecterDataSize,
2056 &effecterOperationalState, pendingValue.data(),
2057 presentValue.data());
2058
2059 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
2060 {
2061 std::cerr << "Response Message Error: "
2062 << "rc=" << rc
2063 << ",cc=" << static_cast<int>(completionCode)
2064 << std::endl;
2065 return;
2066 }
2067
2068 ordered_json output;
2069 output["effecterDataSize"] = static_cast<int>(effecterDataSize);
2070 output["effecterOperationalState"] =
2071 getOpState(effecterOperationalState);
2072
2073 switch (effecterDataSize)
2074 {
2075 case PLDM_EFFECTER_DATA_SIZE_UINT8:
2076 {
2077 output["pendingValue"] =
2078 *(reinterpret_cast<uint8_t*>(pendingValue.data()));
2079 output["presentValue"] =
2080 *(reinterpret_cast<uint8_t*>(presentValue.data()));
2081 break;
2082 }
2083 case PLDM_EFFECTER_DATA_SIZE_SINT8:
2084 {
2085 output["pendingValue"] =
2086 *(reinterpret_cast<int8_t*>(pendingValue.data()));
2087 output["presentValue"] =
2088 *(reinterpret_cast<int8_t*>(presentValue.data()));
2089 break;
2090 }
2091 case PLDM_EFFECTER_DATA_SIZE_UINT16:
2092 {
2093 output["pendingValue"] =
2094 *(reinterpret_cast<uint16_t*>(pendingValue.data()));
2095 output["presentValue"] =
2096 *(reinterpret_cast<uint16_t*>(presentValue.data()));
2097 break;
2098 }
2099 case PLDM_EFFECTER_DATA_SIZE_SINT16:
2100 {
2101 output["pendingValue"] =
2102 *(reinterpret_cast<int16_t*>(pendingValue.data()));
2103 output["presentValue"] =
2104 *(reinterpret_cast<int16_t*>(presentValue.data()));
2105 break;
2106 }
2107 case PLDM_EFFECTER_DATA_SIZE_UINT32:
2108 {
2109 output["pendingValue"] =
2110 *(reinterpret_cast<uint32_t*>(pendingValue.data()));
2111 output["presentValue"] =
2112 *(reinterpret_cast<uint32_t*>(presentValue.data()));
2113 break;
2114 }
2115 case PLDM_EFFECTER_DATA_SIZE_SINT32:
2116 {
2117 output["pendingValue"] =
2118 *(reinterpret_cast<int32_t*>(pendingValue.data()));
2119 output["presentValue"] =
2120 *(reinterpret_cast<int32_t*>(presentValue.data()));
2121 break;
2122 }
2123 default:
2124 {
2125 std::cerr << "Unknown Effecter Data Size : "
2126 << static_cast<int>(effecterDataSize) << std::endl;
2127 break;
2128 }
2129 }
2130
2131 pldmtool::helper::DisplayInJson(output);
2132 }
2133
2134 private:
2135 uint16_t effecterId;
2136
2137 static inline const std::map<uint8_t, std::string> numericEffecterOpState{
2138 {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING,
2139 "Effecter Enabled Update Pending"},
2140 {EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING,
2141 "Effecter Enabled No Update Pending"},
2142 {EFFECTER_OPER_STATE_DISABLED, "Effecter Disabled"},
2143 {EFFECTER_OPER_STATE_UNAVAILABLE, "Effecter Unavailable"},
2144 {EFFECTER_OPER_STATE_STATUSUNKNOWN, "Effecter Status Unknown"},
2145 {EFFECTER_OPER_STATE_FAILED, "Effecter Failed"},
2146 {EFFECTER_OPER_STATE_INITIALIZING, "Effecter Initializing"},
2147 {EFFECTER_OPER_STATE_SHUTTINGDOWN, "Effecter Shutting Down"},
2148 {EFFECTER_OPER_STATE_INTEST, "Effecter In Test"}};
2149
2150 std::string getOpState(uint8_t state)
2151 {
2152 auto typeString = std::to_string(state);
2153 try
2154 {
2155 return numericEffecterOpState.at(state);
2156 }
2157 catch (const std::out_of_range& e)
2158 {
2159 return typeString;
2160 }
2161 }
2162};
2163
George Liud6649362019-11-27 19:06:51 +08002164void registerCommand(CLI::App& app)
2165{
2166 auto platform = app.add_subcommand("platform", "platform type command");
2167 platform->require_subcommand(1);
2168
Patrick Williams6da4f912023-05-10 07:50:53 -05002169 auto getPDR = platform->add_subcommand("GetPDR",
2170 "get platform descriptor records");
George Liud6649362019-11-27 19:06:51 +08002171 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
2172
2173 auto setStateEffecterStates = platform->add_subcommand(
2174 "SetStateEffecterStates", "set effecter states");
2175 commands.push_back(std::make_unique<SetStateEffecter>(
2176 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08002177
2178 auto setNumericEffecterValue = platform->add_subcommand(
2179 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
2180 commands.push_back(std::make_unique<SetNumericEffecterValue>(
2181 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06002182
2183 auto getStateSensorReadings = platform->add_subcommand(
2184 "GetStateSensorReadings", "get the state sensor readings");
2185 commands.push_back(std::make_unique<GetStateSensorReadings>(
2186 "platform", "getStateSensorReadings", getStateSensorReadings));
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002187
2188 auto getNumericEffecterValue = platform->add_subcommand(
2189 "GetNumericEffecterValue", "get the numeric effecter value");
2190 commands.push_back(std::make_unique<GetNumericEffecterValue>(
2191 "platform", "getNumericEffecterValue", getNumericEffecterValue));
nothingIIersonal83e068a2024-03-21 13:55:06 +03002192
2193 auto getSensorReading = platform->add_subcommand(
2194 "GetSensorReading", "get the numeric sensor reading");
2195 commands.push_back(std::make_unique<GetSensorReading>(
2196 "platform", "getSensorReading", getSensorReading));
George Liud6649362019-11-27 19:06:51 +08002197}
2198
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06002199void parseGetPDROption()
2200{
2201 for (const auto& command : commands)
2202 {
2203 if (command.get()->getPLDMType() == "platform" &&
2204 command.get()->getCommandName() == "getPDR")
2205 {
2206 auto getPDR = dynamic_cast<GetPDR*>(command.get());
2207 getPDR->parseGetPDROptions();
2208 }
2209 }
2210}
2211
George Liud6649362019-11-27 19:06:51 +08002212} // namespace platform
2213} // namespace pldmtool