blob: 4f1dbeef3ed86b483914d7ab22c76fede526754b [file] [log] [blame]
Tom Josepha65c0412020-07-03 21:14:44 +05301#include "common/types.hpp"
George Liud6649362019-11-27 19:06:51 +08002#include "pldm_cmd_helper.hpp"
3
George Liuc453e162022-12-21 17:16:23 +08004#include <libpldm/entity.h>
Thu Nguyen846d38f2022-03-26 08:57:21 +07005#include <libpldm/platform.h>
George Liuc453e162022-12-21 17:16:23 +08006#include <libpldm/state_set.h>
7
Thu Nguyen846d38f2022-03-26 08:57:21 +07008#include <algorithm>
Brad Bishop02d71142021-10-14 19:00:17 -04009#include <cstddef>
Tal Yacobi8570fcc2024-05-28 11:11:23 +030010#include <format>
Brad Bishop02d71142021-10-14 19:00:17 -040011#include <map>
Tal Yacobi8570fcc2024-05-28 11:11:23 +030012#include <memory>
Thu Nguyen846d38f2022-03-26 08:57:21 +070013#include <ranges>
Brad Bishop02d71142021-10-14 19:00:17 -040014
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -050015#ifdef OEM_IBM
16#include "oem/ibm/oem_ibm_state_set.hpp"
17#endif
18
Brad Bishop5079ac42021-08-19 18:35:06 -040019using namespace pldm::utils;
20
George Liud6649362019-11-27 19:06:51 +080021namespace pldmtool
22{
George Liud6649362019-11-27 19:06:51 +080023namespace platform
24{
George Liud6649362019-11-27 19:06:51 +080025namespace
26{
George Liud6649362019-11-27 19:06:51 +080027using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060028
29static const std::map<uint8_t, std::string> sensorPresState{
30 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
31 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
32 {PLDM_SENSOR_WARNING, "Sensor Warning"},
33 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
34 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
35 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
36 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
37 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
38 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
39 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
40 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
41
42static const std::map<uint8_t, std::string> sensorOpState{
43 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
44 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
45 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
46 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
47 {PLDM_SENSOR_FAILED, "Sensor Failed"},
Manojkiran Eda2576aec2024-06-17 12:05:17 +053048 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Initializing"},
Sridevi Rameshf31b5042021-01-22 05:42:07 -060049 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
50 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
51
Tal Yacobi8570fcc2024-05-28 11:11:23 +030052const std::map<uint8_t, std::string> effecterOpState{
53 {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING,
54 "Effecter Enabled Update Pending"},
55 {EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING,
56 "Effecter Enabled No Update Pending"},
57 {EFFECTER_OPER_STATE_DISABLED, "Effecter Disabled"},
58 {EFFECTER_OPER_STATE_UNAVAILABLE, "Effecter Unavailable"},
59 {EFFECTER_OPER_STATE_STATUSUNKNOWN, "Effecter Status Unknown"},
60 {EFFECTER_OPER_STATE_FAILED, "Effecter Failed"},
61 {EFFECTER_OPER_STATE_INITIALIZING, "Effecter Initializing"},
62 {EFFECTER_OPER_STATE_SHUTTINGDOWN, "Effecter Shutting Down"},
63 {EFFECTER_OPER_STATE_INTEST, "Effecter In Test"}};
64
65std::string getEffecterOpState(uint8_t state)
66{
67 return effecterOpState.contains(state) ? effecterOpState.at(state)
68 : std::to_string(state);
69}
70
George Liud6649362019-11-27 19:06:51 +080071std::vector<std::unique_ptr<CommandInterface>> commands;
72
73} // namespace
74
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050075using ordered_json = nlohmann::ordered_json;
76
George Liud6649362019-11-27 19:06:51 +080077class GetPDR : public CommandInterface
78{
79 public:
80 ~GetPDR() = default;
81 GetPDR() = delete;
82 GetPDR(const GetPDR&) = delete;
83 GetPDR(GetPDR&&) = default;
84 GetPDR& operator=(const GetPDR&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -050085 GetPDR& operator=(GetPDR&&) = delete;
George Liud6649362019-11-27 19:06:51 +080086
87 using CommandInterface::CommandInterface;
88
George Liud6649362019-11-27 19:06:51 +080089 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
Potin Lai3e52d582024-06-13 11:03:46 +080090 CommandInterface(type, name, app), dataTransferHandle(0),
91 operationFlag(PLDM_GET_FIRSTPART), requestCount(UINT16_MAX),
92 recordChangeNumber(0), nextPartRequired(false)
George Liud6649362019-11-27 19:06:51 +080093 {
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050094 auto pdrOptionGroup = app->add_option_group(
95 "Required Option",
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060096 "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 -050097 pdrOptionGroup->add_option(
98 "-d,--data", recordHandle,
99 "retrieve individual PDRs from a PDR Repository\n"
100 "eg: The recordHandle value for the PDR to be retrieved and 0 "
101 "means get first PDR in the repository.");
102 pdrRecType = "";
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400103 pdrOptionGroup->add_option(
104 "-t, --type", pdrRecType,
105 "retrieve all PDRs of the requested type\n"
106 "supported types:\n"
107 "[terminusLocator, stateSensor, "
108 "numericEffecter, stateEffecter, "
109 "compactNumericSensor, sensorauxname, "
110 "efffecterAuxName, numericsensor, "
111 "EntityAssociation, fruRecord, ... ]");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600112
113 getPDRGroupOption = pdrOptionGroup->add_option(
114 "-i, --terminusID", pdrTerminus,
115 "retrieve all PDRs of the requested terminusID\n"
116 "supported IDs:\n [1, 2, 208...]");
117
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500118 allPDRs = false;
119 pdrOptionGroup->add_flag("-a, --all", allPDRs,
120 "retrieve all PDRs from a PDR repository");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600121
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500122 pdrOptionGroup->require_option(1);
123 }
124
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600125 void parseGetPDROptions()
126 {
127 optTIDSet = false;
128 if (getPDRGroupOption->count() > 0)
129 {
130 optTIDSet = true;
131 getPDRs();
132 }
133 }
134
135 void getPDRs()
136 {
137 // start the array
138 std::cout << "[";
139
140 recordHandle = 0;
141 do
142 {
143 CommandInterface::exec();
144 } while (recordHandle != 0);
145
146 // close the array
147 std::cout << "]\n";
148
149 if (handleFound)
150 {
151 recordHandle = 0;
152 uint32_t prevRecordHandle = 0;
153 do
154 {
155 CommandInterface::exec();
156 if (recordHandle == prevRecordHandle)
157 {
158 return;
159 }
160 prevRecordHandle = recordHandle;
161 } while (recordHandle != 0);
162 }
163 }
164
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500165 void exec() override
166 {
167 if (allPDRs || !pdrRecType.empty())
168 {
169 if (!pdrRecType.empty())
170 {
171 std::transform(pdrRecType.begin(), pdrRecType.end(),
172 pdrRecType.begin(), tolower);
173 }
174
Brad Bishop16eff862021-10-14 19:44:32 -0400175 // start the array
176 std::cout << "[\n";
177
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500178 // Retrieve all PDR records starting from the first
179 recordHandle = 0;
180 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400181 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500182 do
183 {
184 CommandInterface::exec();
185 // recordHandle is updated to nextRecord when
186 // CommandInterface::exec() is successful.
187 // In case of any error, return.
Potin Lai3e52d582024-06-13 11:03:46 +0800188 if (recordHandle == prevRecordHandle && !nextPartRequired)
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500189 {
190 return;
191 }
Brad Bishop02d71142021-10-14 19:00:17 -0400192
193 // check for circular references.
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400194 auto result =
195 recordsSeen.emplace(recordHandle, prevRecordHandle);
Potin Lai3e52d582024-06-13 11:03:46 +0800196 if (!result.second && !nextPartRequired)
Brad Bishop02d71142021-10-14 19:00:17 -0400197 {
198 std::cerr
199 << "Record handle " << recordHandle
200 << " has multiple references: " << result.first->second
201 << ", " << prevRecordHandle << "\n";
202 return;
203 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500204 prevRecordHandle = recordHandle;
Brad Bishop16eff862021-10-14 19:44:32 -0400205
206 if (recordHandle != 0)
207 {
208 // close the array
209 std::cout << ",";
210 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500211 } while (recordHandle != 0);
Brad Bishop16eff862021-10-14 19:44:32 -0400212
213 // close the array
214 std::cout << "]\n";
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500215 }
216 else
217 {
Potin Lai3e52d582024-06-13 11:03:46 +0800218 do
219 {
220 CommandInterface::exec();
221 } while (nextPartRequired);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500222 }
George Liud6649362019-11-27 19:06:51 +0800223 }
224
225 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
226 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400227 std::vector<uint8_t> requestMsg(
228 sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530229 auto request = new (requestMsg.data()) pldm_msg;
George Liud6649362019-11-27 19:06:51 +0800230
Potin Lai3e52d582024-06-13 11:03:46 +0800231 auto rc = encode_get_pdr_req(
232 instanceId, recordHandle, dataTransferHandle, operationFlag,
233 requestCount, recordChangeNumber, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800234 return {rc, requestMsg};
235 }
236
237 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
238 {
239 uint8_t completionCode = 0;
Potin Lai3e52d582024-06-13 11:03:46 +0800240 uint8_t respRecordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800241 uint32_t nextRecordHndl = 0;
242 uint32_t nextDataTransferHndl = 0;
243 uint8_t transferFlag = 0;
244 uint16_t respCnt = 0;
245 uint8_t transferCRC = 0;
246
247 auto rc = decode_get_pdr_resp(
248 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
Potin Lai3e52d582024-06-13 11:03:46 +0800249 &nextDataTransferHndl, &transferFlag, &respCnt, respRecordData,
250 sizeof(respRecordData), &transferCRC);
George Liud6649362019-11-27 19:06:51 +0800251
252 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
253 {
254 std::cerr << "Response Message Error: "
255 << "rc=" << rc << ",cc=" << (int)completionCode
256 << std::endl;
Potin Lai3e52d582024-06-13 11:03:46 +0800257 nextPartRequired = false;
George Liud6649362019-11-27 19:06:51 +0800258 return;
259 }
260
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600261 if (optTIDSet && !handleFound)
262 {
Potin Lai3e52d582024-06-13 11:03:46 +0800263 terminusHandle = getTerminusHandle(respRecordData, pdrTerminus);
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600264 if (terminusHandle.has_value())
265 {
266 recordHandle = 0;
267 return;
268 }
269 else
270 {
271 recordHandle = nextRecordHndl;
272 return;
273 }
274 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600275 else
276 {
Potin Lai3e52d582024-06-13 11:03:46 +0800277 recordData.insert(recordData.end(), respRecordData,
278 respRecordData + respCnt);
279
280 // End or StartAndEnd
281 if (transferFlag == PLDM_PLATFORM_TRANSFER_END ||
282 transferFlag == PLDM_PLATFORM_TRANSFER_START_AND_END)
283 {
284 printPDRMsg(nextRecordHndl, respCnt, recordData.data(),
285 terminusHandle);
286 nextPartRequired = false;
287 recordHandle = nextRecordHndl;
288 dataTransferHandle = 0;
289 recordChangeNumber = 0;
290 operationFlag = PLDM_GET_FIRSTPART;
291 recordData.clear();
292 }
293 else
294 {
295 nextPartRequired = true;
296 dataTransferHandle = nextDataTransferHndl;
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530297 struct pldm_pdr_hdr* pdr_hdr = new (respRecordData)
298 pldm_pdr_hdr;
Potin Lai3e52d582024-06-13 11:03:46 +0800299 recordChangeNumber = pdr_hdr->record_change_num;
300 operationFlag = PLDM_GET_NEXTPART;
301 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600302 }
George Liud6649362019-11-27 19:06:51 +0800303 }
304
305 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530306 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530307 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
308 {PLDM_ENTITY_OTHER, "Other"},
309 {PLDM_ENTITY_NETWORK, "Network"},
310 {PLDM_ENTITY_GROUP, "Group"},
311 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
312 "Remote Management Communication Device"},
313 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
314 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
315 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
316 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
317 {PLDM_ENTITY_KEYPAD, "keypad"},
318 {PLDM_ENTITY_SWITCH, "Switch"},
319 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
320 {PLDM_ENTITY_DISPLAY, "Display"},
321 {PLDM_ENTITY_INDICATOR, "Indicator"},
322 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530323 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530324 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530325 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530326 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
327 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
328 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530329 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530330 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
331 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
332 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
333 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
334 {PLDM_ENTITY_DOOR, "Door"},
335 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
336 {PLDM_ENTITY_COVER, "Cover"},
337 {PLDM_ENTITY_BOARD, "Board"},
338 {PLDM_ENTITY_CARD, "Card"},
339 {PLDM_ENTITY_MODULE, "Module"},
340 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530341 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530342 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530343 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
344 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530345 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530346 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530347 "Chassis front panel board(control panel)"},
348 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
349 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
350 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
351 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
352 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
353 "System internal expansion board"},
354 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
355 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
356 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
357 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
358 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
359 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
360 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
361 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
362 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
363 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500364 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530365 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
366 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
367 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
368 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
369 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
370 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
371 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
372 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
373 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
374 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500375 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530376 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
377 {PLDM_ENTITY_BATTERY, "Battery"},
378 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
379 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
380 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
381 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
382 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
383 {PLDM_ENTITY_PROC, "Processor"},
384 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
385 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
386 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
387 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
388 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
389 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
390 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
391 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
392 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
393 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
394 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500395 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530396 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
397 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
398 {PLDM_ENTITY_SYS_BUS, "System Bus"},
399 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
400 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
401 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
402 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
403 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
404 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
405 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
406 {PLDM_ENTITY_USB_BUS, "USB Bus"},
407 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
408 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
409 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
410 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
411 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
412 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500413 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530414 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
415 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
416 {PLDM_ENTITY_PLUG, "Plug"},
417 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500418 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500419
Tom Josepha65c0412020-07-03 21:14:44 +0530420 const std::map<uint16_t, std::string> stateSet = {
421 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
422 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530423 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
424 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
425 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
426 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
427 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530428 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530429 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
430 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530431 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
432 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530433 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
434 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530435 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530436 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530437 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530438 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
439 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
440 {PLDM_STATE_SET_VERSION, "Version"},
441 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
442 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
443 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
444 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530445 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530446 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
447 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
448 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
449 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
450 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
451 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
452 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
453 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
454 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
455 "Physical Communication Connection"},
456 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
457 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
458 "Foreign Network Detection Status"},
459 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
460 "Password-Protected Access Security"},
461 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
462 "Security Access –PrivilegeLevel"},
463 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530464 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530465 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530466 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530467 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
468 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
469 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530470 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530471 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
472 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
473 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
474 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
475 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
476 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
477 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
478 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
479 "Diagnostic Interrupt Requested"},
480 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
481 "Diagnostic Interrupt Received"},
482 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
483 "I/O Channel Check NMI Requested"},
484 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
485 "I/O Channel Check NMI Received"},
486 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
487 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
488 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
489 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
490 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
491 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
492 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
493 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
494 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
495 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
496 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
497 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
498 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
499 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
500 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
501 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
502 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
503 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
504 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
505 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
506 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
507 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
508 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
509 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
510 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
511 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
512 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
513 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
514 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
515 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
516 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
517 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
518 "Redundant Memory Activity Status"},
519 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
520 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
521 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
522 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500523 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
524 };
Tom Josepha65c0412020-07-03 21:14:44 +0530525
526 const std::array<std::string_view, 4> sensorInit = {
527 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
528
Tom Joseph97a7a762020-07-06 10:37:18 +0530529 const std::array<std::string_view, 4> effecterInit = {
530 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
531
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500532 const std::map<uint8_t, std::string> pdrType = {
533 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
534 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
535 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
536 "Numeric Sensor Initialization PDR"},
537 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
538 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
539 "State Sensor Initialization PDR"},
540 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
541 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
542 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
543 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
544 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
545 "Numeric Effecter Initialization PDR"},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700546 {PLDM_COMPACT_NUMERIC_SENSOR_PDR, "Compact Numeric Sensor PDR"},
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500547 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
548 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
549 "State Effecter Initialization PDR"},
550 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
551 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
552 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
553 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
554 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
555 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
556 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
557 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
558 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
559 {PLDM_OEM_PDR, "OEM PDR"},
560 };
561
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500562 static inline const std::map<uint8_t, std::string> setThermalTrip{
563 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
564 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
565
566 static inline const std::map<uint8_t, std::string> setIdentifyState{
567 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
568 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
569
570 static inline const std::map<uint8_t, std::string> setBootProgressState{
571 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
572 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
573 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
574 "Memory Initialization"},
575 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
576 "Secondary Processor(s) Initialization"},
577 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
578 "PCI Resource Configuration"},
579 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
580 "Starting Operating System"},
581 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
582 "Baseboard Initialization"},
583 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
kamal00a076d2022-11-08 04:24:36 -0600584 "Primary Processor Initialization"},
585 {PLDM_STATE_SET_BOOT_PROG_STATE_OSSTART, "OSStart"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500586
587 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -0500588 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
589 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_ERROR, "Error"},
590 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NON_RECOVERABLE_ERROR,
591 "Non Recoverable Error"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500592
593 static inline const std::map<uint8_t, std::string> setSysPowerState{
594 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
595 "Off-Soft Graceful"}};
596
597 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
598 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
599 "Graceful Restart Requested"}};
600
601 static inline const std::map<uint8_t, std::string> setAvailability{
602 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
603
604 static inline const std::map<uint8_t, std::string> setHealthState{
605 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530606 {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"},
607 {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"},
608 {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"},
609 {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"},
610 {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500611 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530612 {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"},
613 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"},
614 {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}};
615
616 static inline const std::map<uint8_t, std::string>
617 setOperationalRunningState{
618 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"},
619 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"},
620 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"},
621 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE,
622 "In Service"},
623 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"},
624 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500625
Riya Dixit43e33d22024-02-07 09:53:49 -0600626 static inline const std::map<uint8_t, std::string> setPowerDeviceState{
627 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_UNKNOWN, "Unknown"},
628 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_FULLY_ON, "Fully-On"},
629 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_1,
630 "Intermediate State-1"},
631 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_2,
632 "Intermediate State-2"},
633 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_OFF, "Off"}};
634
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500635 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
636 populatePStateMaps{
637 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
638 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
639 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
640 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
641 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
642 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
643 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
644 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530645 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
646 setOperationalRunningState},
Riya Dixit43e33d22024-02-07 09:53:49 -0600647 {PLDM_STATE_SET_DEVICE_POWER_STATE, setPowerDeviceState},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500648 };
649
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500650 const std::map<std::string, uint8_t> strToPdrType = {
651 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
652 {"statesensor", PLDM_STATE_SENSOR_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700653 {"sensorauxname", PLDM_SENSOR_AUXILIARY_NAMES_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500654 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700655 {"efffecterauxname", PLDM_EFFECTER_AUXILIARY_NAMES_PDR},
nothingIIersonalcea52d92024-03-21 13:56:02 +0300656 {"numericsensor", PLDM_NUMERIC_SENSOR_PDR},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700657 {"compactnumericsensor", PLDM_COMPACT_NUMERIC_SENSOR_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500658 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
659 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
660 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
661 // Add other types
662 };
663
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530664 bool isLogicalBitSet(const uint16_t entity_type)
665 {
666 return entity_type & 0x8000;
667 }
668
669 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
670 {
671 return logical_entity_type & 0x7FFF;
672 }
673
Tom Josepha65c0412020-07-03 21:14:44 +0530674 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500675 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530676 uint16_t entityNumber = type;
677 std::string entityName = "[Physical] ";
678
679 if (isLogicalBitSet(type))
680 {
681 entityName = "[Logical] ";
682 entityNumber = getEntityTypeForLogicalEntity(type);
683 }
684
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500685 try
686 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530687 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500688 }
689 catch (const std::out_of_range& e)
690 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500691 auto OemString =
692 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530693 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
694 type <= PLDM_OEM_ENTITY_TYPE_END)
695 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500696#ifdef OEM_IBM
697 if (OemIBMEntityType.contains(entityNumber))
698 {
699 return entityName + OemIBMEntityType.at(entityNumber) +
700 "(OEM)";
701 }
702#endif
703 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530704 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500705 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500706 }
707 }
708
Tom Josepha65c0412020-07-03 21:14:44 +0530709 std::string getStateSetName(uint16_t id)
710 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500711 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530712 try
713 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500714 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530715 }
716 catch (const std::out_of_range& e)
717 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500718 return typeString;
719 }
720 }
721
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400722 std::vector<std::string> getStateSetPossibleStateNames(
723 uint16_t stateId, const std::vector<uint8_t>& value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500724 {
725 std::vector<std::string> data{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500726
Pavithra Barithaya15b94112024-04-10 02:42:12 -0500727 for (const auto& s : value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500728 {
729 std::map<uint8_t, std::string> stateNameMaps;
730 auto pstr = std::to_string(s);
731
732#ifdef OEM_IBM
Manojkiran Edabe1a8572022-01-06 11:20:36 +0530733 if (stateId >= PLDM_OEM_STATE_SET_ID_START &&
734 stateId < PLDM_OEM_STATE_SET_ID_END)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500735 {
736 if (populateOemIBMStateMaps.contains(stateId))
737 {
738 const std::map<uint8_t, std::string> stateNames =
739 populateOemIBMStateMaps.at(stateId);
740 stateNameMaps.insert(stateNames.begin(), stateNames.end());
741 }
742 }
743#endif
744 if (populatePStateMaps.contains(stateId))
745 {
746 const std::map<uint8_t, std::string> stateNames =
747 populatePStateMaps.at(stateId);
748 stateNameMaps.insert(stateNames.begin(), stateNames.end());
749 }
750 if (stateNameMaps.contains(s))
751 {
752 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
753 }
754 else
755 {
756 data.push_back(pstr);
757 }
758 }
759 return data;
760 }
761
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500762 std::string getPDRType(uint8_t type)
763 {
764 auto typeString = std::to_string(type);
765 try
766 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500767 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500768 }
769 catch (const std::out_of_range& e)
770 {
771 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530772 }
773 }
774
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500775 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530776 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500777 output["recordHandle"] = hdr->record_handle;
778 output["PDRHeaderVersion"] = unsigned(hdr->version);
779 output["PDRType"] = getPDRType(hdr->type);
780 output["recordChangeNumber"] = hdr->record_change_num;
781 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530782 }
783
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500784 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
785 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530786 {
787 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500788 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500789 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
790 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530791 for (int i = 0; i < CHAR_BIT; i++)
792 {
793 if (val.byte & (1 << i))
794 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500795 pstates << (possibleStatesPos * CHAR_BIT + i);
796 data.push_back(
797 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600798 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530799 }
800 }
801 possibleStatesPos++;
802 };
803 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500804 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530805 }
806
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500807 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530808 {
809 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500810 output["PLDMTerminusHandle"] = pdr->terminus_handle;
811 output["sensorID"] = pdr->sensor_id;
812 output["entityType"] = getEntityName(pdr->entity_type);
813 output["entityInstanceNumber"] = pdr->entity_instance;
814 output["containerID"] = pdr->container_id;
815 output["sensorInit"] = sensorInit[pdr->sensor_init];
816 output["sensorAuxiliaryNamesPDR"] =
817 (pdr->sensor_auxiliary_names_pdr ? true : false);
818 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530819
820 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600821 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530822
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600823 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530824 {
825 auto state = reinterpret_cast<const state_sensor_possible_states*>(
826 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600827 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
828 getStateSetName(state->state_set_id));
829 output.emplace(
830 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
831 state->possible_states_size);
832 output.emplace(
833 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500834 getStateSetPossibleStateNames(
835 state->state_set_id,
836 printPossibleStates(state->possible_states_size,
837 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530838
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600839 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530840 {
841 statesPtr += sizeof(state_sensor_possible_states) +
842 state->possible_states_size - 1;
843 }
844 }
845 }
846
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500847 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500848 {
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -0600849 if (data == nullptr)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500850 {
851 return;
852 }
853
854 data += sizeof(pldm_pdr_hdr);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530855 pldm_pdr_fru_record_set* pdr = new (data) pldm_pdr_fru_record_set;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530856 if (!pdr)
857 {
858 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
859 return;
860 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500861
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500862 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
863 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
864 output["entityType"] = getEntityName(pdr->entity_type);
Sagar Srinivasebf8bb52023-10-06 01:15:55 -0500865 output["entityInstanceNumber"] = unsigned(pdr->entity_instance);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500866 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500867 }
868
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500869 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500870 {
871 const std::map<uint8_t, const char*> assocationType = {
872 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
873 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
874 };
875
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -0600876 if (data == nullptr)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500877 {
878 return;
879 }
880
881 data += sizeof(pldm_pdr_hdr);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530882 pldm_pdr_entity_association* pdr = new (data)
883 pldm_pdr_entity_association;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530884 if (!pdr)
885 {
886 std::cerr << "Failed to get the PDR eneity association"
887 << std::endl;
888 return;
889 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500890
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500891 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800892 if (assocationType.contains(pdr->association_type))
893 {
894 output["associationType"] =
895 assocationType.at(pdr->association_type);
896 }
897 else
898 {
899 std::cout << "Get associationType failed.\n";
900 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500901 output["containerEntityType"] =
902 getEntityName(pdr->container.entity_type);
903 output["containerEntityInstanceNumber"] =
904 int(pdr->container.entity_instance_num);
905 output["containerEntityContainerID"] =
906 int(pdr->container.entity_container_id);
907 output["containedEntityCount"] =
908 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500909
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530910 pldm_entity* child = new (&pdr->children[0]) pldm_entity();
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500911 for (int i = 0; i < pdr->num_children; ++i)
912 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500913 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
914 getEntityName(child->entity_type));
915 output.emplace("containedEntityInstanceNumber[" +
916 std::to_string(i + 1) + "]",
917 unsigned(child->entity_instance_num));
918 output.emplace("containedEntityContainerID[" +
919 std::to_string(i + 1) + "]",
920 unsigned(child->entity_container_id));
921
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500922 ++child;
923 }
924 }
925
Thu Nguyen846d38f2022-03-26 08:57:21 +0700926 /** @brief Format the Sensor/Effecter Aux Name PDR types to json output
927 *
928 * @param[in] data - reference to the Sensor/Effecter Aux Name PDR
929 * @param[out] output - PDRs data fields in Json format
930 */
931 void printAuxNamePDR(uint8_t* data, ordered_json& output)
932 {
933 constexpr uint8_t nullTerminator = 0;
934 struct pldm_effecter_aux_name_pdr* auxNamePdr =
935 (struct pldm_effecter_aux_name_pdr*)data;
936
937 if (!auxNamePdr)
938 {
939 std::cerr << "Failed to get Aux Name PDR" << std::endl;
940 return;
941 }
942
943 std::string sPrefix = "effecter";
944 if (auxNamePdr->hdr.type == PLDM_SENSOR_AUXILIARY_NAMES_PDR)
945 {
946 sPrefix = "sensor";
947 }
948 output["terminusHandle"] = int(auxNamePdr->terminus_handle);
949 output[sPrefix + "Id"] = int(auxNamePdr->effecter_id);
950 output[sPrefix + "Count"] = int(auxNamePdr->effecter_count);
951
952 const uint8_t* ptr = auxNamePdr->effecter_names;
953 for (auto i : std::views::iota(0, (int)auxNamePdr->effecter_count))
954 {
955 const uint8_t nameStringCount = static_cast<uint8_t>(*ptr);
956 ptr += sizeof(uint8_t);
957 for (auto j : std::views::iota(0, (int)nameStringCount))
958 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400959 std::string nameLanguageTagKey =
960 sPrefix + std::to_string(j) + "_nameLanguageTag" +
961 std::to_string(i);
962 std::string entityAuxNameKey =
963 sPrefix + std::to_string(j) + "_entityAuxName" +
964 std::to_string(i);
Thu Nguyen846d38f2022-03-26 08:57:21 +0700965 std::string nameLanguageTag(reinterpret_cast<const char*>(ptr),
966 0, PLDM_STR_UTF_8_MAX_LEN);
967 ptr += nameLanguageTag.size() + sizeof(nullTerminator);
968 std::u16string u16NameString(
969 reinterpret_cast<const char16_t*>(ptr), 0,
970 PLDM_STR_UTF_16_MAX_LEN);
971 ptr += (u16NameString.size() + sizeof(nullTerminator)) *
972 sizeof(uint16_t);
973 std::transform(u16NameString.cbegin(), u16NameString.cend(),
974 u16NameString.begin(),
975 [](uint16_t utf16) { return be16toh(utf16); });
976 std::string nameString =
977 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
978 char16_t>{}
979 .to_bytes(u16NameString);
980 output[nameLanguageTagKey] = nameLanguageTag;
981 output[entityAuxNameKey] = nameString;
982 }
983 }
984 }
985
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500986 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800987 {
988 struct pldm_numeric_effecter_value_pdr* pdr =
989 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530990 if (!pdr)
991 {
992 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
993 return;
994 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500995
996 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
997 output["effecterID"] = int(pdr->effecter_id);
998 output["entityType"] = int(pdr->entity_type);
999 output["entityInstanceNumber"] = int(pdr->entity_instance);
1000 output["containerID"] = int(pdr->container_id);
1001 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
1002 output["effecterInit"] = unsigned(pdr->effecter_init);
1003 output["effecterAuxiliaryNames"] =
1004 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
1005 output["baseUnit"] = unsigned(pdr->base_unit);
1006 output["unitModifier"] = unsigned(pdr->unit_modifier);
1007 output["rateUnit"] = unsigned(pdr->rate_unit);
1008 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
1009 output["auxUnit"] = unsigned(pdr->aux_unit);
1010 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
1011 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
1012 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
1013 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
1014 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
1015 output["resolution"] = unsigned(pdr->resolution);
1016 output["offset"] = unsigned(pdr->offset);
1017 output["accuracy"] = unsigned(pdr->accuracy);
1018 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
1019 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
1020 output["stateTransitionInterval"] =
1021 unsigned(pdr->state_transition_interval);
1022 output["TransitionInterval"] = unsigned(pdr->transition_interval);
1023
George Liu62d12ec2020-02-05 16:27:08 +08001024 switch (pdr->effecter_data_size)
1025 {
1026 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301027 output["maxSettable"] = unsigned(pdr->max_settable.value_u8);
1028 output["minSettable"] = unsigned(pdr->min_settable.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001029 break;
1030 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301031 output["maxSettable"] = unsigned(pdr->max_settable.value_s8);
1032 output["minSettable"] = unsigned(pdr->min_settable.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001033 break;
1034 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301035 output["maxSettable"] = unsigned(pdr->max_settable.value_u16);
1036 output["minSettable"] = unsigned(pdr->min_settable.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001037 break;
1038 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301039 output["maxSettable"] = unsigned(pdr->max_settable.value_s16);
1040 output["minSettable"] = unsigned(pdr->min_settable.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001041 break;
1042 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301043 output["maxSettable"] = unsigned(pdr->max_settable.value_u32);
1044 output["minSettable"] = unsigned(pdr->min_settable.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001045 break;
1046 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301047 output["maxSettable"] = unsigned(pdr->max_settable.value_s32);
1048 output["minSettable"] = unsigned(pdr->min_settable.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001049 break;
1050 default:
1051 break;
1052 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001053
1054 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
1055 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1056
George Liu62d12ec2020-02-05 16:27:08 +08001057 switch (pdr->range_field_format)
1058 {
1059 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001060 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
1061 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
1062 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
1063 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
1064 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001065 break;
1066 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001067 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
1068 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
1069 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
1070 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
1071 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001072 break;
1073 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001074 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
1075 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
1076 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
1077 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
1078 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001079 break;
1080 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001081 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
1082 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
1083 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
1084 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
1085 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001086 break;
1087 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001088 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
1089 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
1090 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
1091 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
1092 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001093 break;
1094 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001095 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
1096 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
1097 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
1098 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
1099 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001100 break;
1101 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001102 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
1103 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
1104 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
1105 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
1106 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +08001107 break;
1108 default:
1109 break;
1110 }
1111 }
1112
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001113 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +08001114 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301115 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +08001116
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001117 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1118 output["effecterID"] = pdr->effecter_id;
1119 output["entityType"] = getEntityName(pdr->entity_type);
1120 output["entityInstanceNumber"] = pdr->entity_instance;
1121 output["containerID"] = pdr->container_id;
1122 output["effecterSemanticID"] = pdr->effecter_semantic_id;
1123 output["effecterInit"] = effecterInit[pdr->effecter_init];
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001124 output["effecterDescriptionPDR"] =
1125 (pdr->has_description_pdr ? true : false);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001126 output["compositeEffecterCount"] =
1127 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +08001128
Tom Joseph97a7a762020-07-06 10:37:18 +05301129 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001130 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +05301131
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001132 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +08001133 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301134 auto state =
1135 reinterpret_cast<const state_effecter_possible_states*>(
1136 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001137 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
1138 getStateSetName(state->state_set_id));
1139 output.emplace(
1140 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
1141 state->possible_states_size);
1142 output.emplace(
1143 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05001144 getStateSetPossibleStateNames(
1145 state->state_set_id,
1146 printPossibleStates(state->possible_states_size,
1147 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001148
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001149 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +05301150 {
1151 statesPtr += sizeof(state_effecter_possible_states) +
1152 state->possible_states_size - 1;
1153 }
George Liud6649362019-11-27 19:06:51 +08001154 }
1155 }
1156
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001157 bool checkTerminusHandle(const uint8_t* data,
1158 std::optional<uint16_t> terminusHandle)
1159 {
1160 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1161
1162 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1163 {
1164 auto tlpdr =
1165 reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1166
1167 if (tlpdr->terminus_handle != terminusHandle)
1168 {
1169 return true;
1170 }
1171 }
1172 else if (pdr->type == PLDM_STATE_SENSOR_PDR)
1173 {
1174 auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
1175
1176 if (sensor->terminus_handle != terminusHandle)
1177 {
1178 return true;
1179 }
1180 }
1181 else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR)
1182 {
1183 auto numericEffecter =
1184 reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data);
1185
1186 if (numericEffecter->terminus_handle != terminusHandle)
1187 {
1188 return true;
1189 }
1190 }
1191
1192 else if (pdr->type == PLDM_STATE_EFFECTER_PDR)
1193 {
1194 auto stateEffecter =
1195 reinterpret_cast<const pldm_state_effecter_pdr*>(data);
1196 if (stateEffecter->terminus_handle != terminusHandle)
1197 {
1198 return true;
1199 }
1200 }
1201 else if (pdr->type == PLDM_PDR_FRU_RECORD_SET)
1202 {
1203 data += sizeof(pldm_pdr_hdr);
1204 auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data);
1205
1206 if (fru->terminus_handle != terminusHandle)
1207 {
1208 return true;
1209 }
1210 }
1211 else
1212 {
1213 // Entity association PDRs does not have terminus handle
1214 return true;
1215 }
1216
1217 return false;
1218 }
1219
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001220 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -05001221 {
1222 const std::array<std::string_view, 4> terminusLocatorType = {
1223 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
1224
1225 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1226
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001227 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1228 output["validity"] = (pdr->validity ? "valid" : "notValid");
1229 output["TID"] = unsigned(pdr->tid);
1230 output["containerID"] = pdr->container_id;
1231 output["terminusLocatorType"] =
1232 terminusLocatorType[pdr->terminus_locator_type];
1233 output["terminusLocatorValueSize"] =
1234 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -05001235
1236 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
1237 {
1238 auto locatorValue =
1239 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
1240 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001241 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -05001242 }
1243 }
1244
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001245 std::optional<uint16_t> getTerminusHandle(uint8_t* data,
1246 std::optional<uint8_t> tid)
1247 {
1248 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1249 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1250 {
1251 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1252 if (pdr->tid == tid)
1253 {
1254 handleFound = true;
1255 return pdr->terminus_handle;
1256 }
1257 }
1258 return std::nullopt;
1259 }
1260
nothingIIersonalcea52d92024-03-21 13:56:02 +03001261 /** @brief Format the Numeric Sensor PDR types to json output
1262 *
1263 * @param[in] data - reference to the Numeric Sensor PDR
1264 * @param[in] data_length - number of PDR data bytes
1265 * @param[out] output - PDRs data fields in Json format
1266 */
1267 void printNumericSensorPDR(const uint8_t* data, const uint16_t data_length,
1268 ordered_json& output)
1269 {
1270 struct pldm_numeric_sensor_value_pdr pdr;
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001271 int rc =
1272 decode_numeric_sensor_pdr_data(data, (size_t)data_length, &pdr);
nothingIIersonalcea52d92024-03-21 13:56:02 +03001273 if (rc != PLDM_SUCCESS)
1274 {
1275 std::cerr << "Failed to get numeric sensor PDR" << std::endl;
1276 return;
1277 }
1278 output["PLDMTerminusHandle"] = pdr.terminus_handle;
1279 output["sensorID"] = pdr.sensor_id;
1280 output["entityType"] = getEntityName(pdr.entity_type);
1281 output["entityInstanceNumber"] = pdr.entity_instance_num;
1282 output["containerID"] = pdr.container_id;
1283 output["sensorInit"] = pdr.sensor_init;
1284 output["sensorAuxiliaryNamesPDR"] =
1285 (pdr.sensor_auxiliary_names_pdr) ? true : false;
1286 output["baseUnit"] = pdr.base_unit;
1287 output["unitModifier"] = pdr.unit_modifier;
1288 output["rateUnit"] = pdr.rate_unit;
1289 output["baseOEMUnitHandle"] = pdr.base_oem_unit_handle;
1290 output["auxUnit"] = pdr.aux_unit;
1291 output["auxUnitModifier"] = pdr.aux_unit_modifier;
1292 output["auxrateUnit"] = pdr.aux_rate_unit;
1293 output["rel"] = pdr.rel;
1294 output["auxOEMUnitHandle"] = pdr.aux_oem_unit_handle;
1295 output["isLinear"] = (pdr.is_linear) ? true : false;
1296 output["sensorDataSize"] = pdr.sensor_data_size;
1297 output["resolution"] = pdr.resolution;
1298 output["offset"] = pdr.offset;
1299 output["accuracy"] = pdr.accuracy;
1300 output["plusTolerance"] = pdr.plus_tolerance;
1301 output["minusTolerance"] = pdr.minus_tolerance;
1302
1303 switch (pdr.sensor_data_size)
1304 {
1305 case PLDM_SENSOR_DATA_SIZE_UINT8:
1306 output["hysteresis"] = pdr.hysteresis.value_u8;
1307 output["maxReadable"] = pdr.max_readable.value_u8;
1308 output["minReadable"] = pdr.min_readable.value_u8;
1309 break;
1310 case PLDM_SENSOR_DATA_SIZE_SINT8:
1311 output["hysteresis"] = pdr.hysteresis.value_s8;
1312 output["maxReadable"] = pdr.max_readable.value_s8;
1313 output["minReadable"] = pdr.min_readable.value_s8;
1314 break;
1315 case PLDM_SENSOR_DATA_SIZE_UINT16:
1316 output["hysteresis"] = pdr.hysteresis.value_u16;
1317 output["maxReadable"] = pdr.max_readable.value_u16;
1318 output["minReadable"] = pdr.min_readable.value_u16;
1319 break;
1320 case PLDM_SENSOR_DATA_SIZE_SINT16:
1321 output["hysteresis"] = pdr.hysteresis.value_s16;
1322 output["maxReadable"] = pdr.max_readable.value_s16;
1323 output["minReadable"] = pdr.min_readable.value_s16;
1324 break;
1325 case PLDM_SENSOR_DATA_SIZE_UINT32:
1326 output["hysteresis"] = pdr.hysteresis.value_u32;
1327 output["maxReadable"] = pdr.max_readable.value_u32;
1328 output["minReadable"] = pdr.min_readable.value_u32;
1329 break;
1330 case PLDM_SENSOR_DATA_SIZE_SINT32:
1331 output["hysteresis"] = pdr.hysteresis.value_s32;
1332 output["maxReadable"] = pdr.max_readable.value_s32;
1333 output["minReadable"] = pdr.min_readable.value_s32;
1334 break;
1335 default:
1336 break;
1337 }
1338
1339 output["supportedThresholds"] = pdr.supported_thresholds.byte;
1340 output["thresholAndHysteresisVolatility"] =
1341 pdr.threshold_and_hysteresis_volatility.byte;
1342 output["stateTransitionInterval"] = pdr.state_transition_interval;
1343 output["updateInterval"] = pdr.update_interval;
1344 output["rangeFieldFormat"] = pdr.range_field_format;
1345 output["rangeFieldSupport"] = pdr.range_field_support.byte;
1346
1347 switch (pdr.range_field_format)
1348 {
1349 case PLDM_RANGE_FIELD_FORMAT_UINT8:
1350 output["nominalValue"] = pdr.nominal_value.value_u8;
1351 output["normalMax"] = pdr.normal_max.value_u8;
1352 output["normalMin"] = pdr.normal_min.value_u8;
1353 output["warningHigh"] = pdr.warning_high.value_u8;
1354 output["warningLow"] = pdr.warning_low.value_u8;
1355 output["criticalHigh"] = pdr.critical_high.value_u8;
1356 output["criticalLow"] = pdr.critical_low.value_u8;
1357 output["fatalHigh"] = pdr.fatal_high.value_u8;
1358 output["fatalLeow"] = pdr.fatal_low.value_u8;
1359 break;
1360 case PLDM_RANGE_FIELD_FORMAT_SINT8:
1361 output["nominalValue"] = pdr.nominal_value.value_s8;
1362 output["normalMax"] = pdr.normal_max.value_s8;
1363 output["normalMin"] = pdr.normal_min.value_s8;
1364 output["warningHigh"] = pdr.warning_high.value_s8;
1365 output["warningLow"] = pdr.warning_low.value_s8;
1366 output["criticalHigh"] = pdr.critical_high.value_s8;
1367 output["criticalLow"] = pdr.critical_low.value_s8;
1368 output["fatalHigh"] = pdr.fatal_high.value_s8;
1369 output["fatalLeow"] = pdr.fatal_low.value_s8;
1370 break;
1371 case PLDM_RANGE_FIELD_FORMAT_UINT16:
1372 output["nominalValue"] = pdr.nominal_value.value_u16;
1373 output["normalMax"] = pdr.normal_max.value_u16;
1374 output["normalMin"] = pdr.normal_min.value_u16;
1375 output["warningHigh"] = pdr.warning_high.value_u16;
1376 output["warningLow"] = pdr.warning_low.value_u16;
1377 output["criticalHigh"] = pdr.critical_high.value_u16;
1378 output["criticalLow"] = pdr.critical_low.value_u16;
1379 output["fatalHigh"] = pdr.fatal_high.value_u16;
1380 output["fatalLeow"] = pdr.fatal_low.value_u16;
1381 break;
1382 case PLDM_RANGE_FIELD_FORMAT_SINT16:
1383 output["nominalValue"] = pdr.nominal_value.value_s16;
1384 output["normalMax"] = pdr.normal_max.value_s16;
1385 output["normalMin"] = pdr.normal_min.value_s16;
1386 output["warningHigh"] = pdr.warning_high.value_s16;
1387 output["warningLow"] = pdr.warning_low.value_s16;
1388 output["criticalHigh"] = pdr.critical_high.value_s16;
1389 output["criticalLow"] = pdr.critical_low.value_s16;
1390 output["fatalHigh"] = pdr.fatal_high.value_s16;
1391 output["fatalLeow"] = pdr.fatal_low.value_s16;
1392 break;
1393 case PLDM_RANGE_FIELD_FORMAT_UINT32:
1394 output["nominalValue"] = pdr.nominal_value.value_u32;
1395 output["normalMax"] = pdr.normal_max.value_u32;
1396 output["normalMin"] = pdr.normal_min.value_u32;
1397 output["warningHigh"] = pdr.warning_high.value_u32;
1398 output["warningLow"] = pdr.warning_low.value_u32;
1399 output["criticalHigh"] = pdr.critical_high.value_u32;
1400 output["criticalLow"] = pdr.critical_low.value_u32;
1401 output["fatalHigh"] = pdr.fatal_high.value_u32;
1402 output["fatalLeow"] = pdr.fatal_low.value_u32;
1403 break;
1404 case PLDM_RANGE_FIELD_FORMAT_SINT32:
1405 output["nominalValue"] = pdr.nominal_value.value_s32;
1406 output["normalMax"] = pdr.normal_max.value_s32;
1407 output["normalMin"] = pdr.normal_min.value_s32;
1408 output["warningHigh"] = pdr.warning_high.value_s32;
1409 output["warningLow"] = pdr.warning_low.value_s32;
1410 output["criticalHigh"] = pdr.critical_high.value_s32;
1411 output["criticalLow"] = pdr.critical_low.value_s32;
1412 output["fatalHigh"] = pdr.fatal_high.value_s32;
1413 output["fatalLeow"] = pdr.fatal_low.value_s32;
1414 break;
1415 case PLDM_RANGE_FIELD_FORMAT_REAL32:
1416 output["nominalValue"] = pdr.nominal_value.value_f32;
1417 output["normalMax"] = pdr.normal_max.value_f32;
1418 output["normalMin"] = pdr.normal_min.value_f32;
1419 output["warningHigh"] = pdr.warning_high.value_f32;
1420 output["warningLow"] = pdr.warning_low.value_f32;
1421 output["criticalHigh"] = pdr.critical_high.value_f32;
1422 output["criticalLow"] = pdr.critical_low.value_f32;
1423 output["fatalHigh"] = pdr.fatal_high.value_f32;
1424 output["fatalLeow"] = pdr.fatal_low.value_f32;
1425 break;
1426 default:
1427 break;
1428 }
1429 }
1430
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001431 /** @brief Format the Compact Numeric Sensor PDR types to json output
1432 *
1433 * @param[in] data - reference to the Compact Numeric Sensor PDR
1434 * @param[out] output - PDRs data fields in Json format
1435 */
1436 void printCompactNumericSensorPDR(const uint8_t* data, ordered_json& output)
1437 {
1438 struct pldm_compact_numeric_sensor_pdr* pdr =
1439 (struct pldm_compact_numeric_sensor_pdr*)data;
1440 if (!pdr)
1441 {
1442 std::cerr << "Failed to get compact numeric sensor PDR"
1443 << std::endl;
1444 return;
1445 }
1446 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
1447 output["sensorID"] = int(pdr->sensor_id);
1448 output["entityType"] = getEntityName(pdr->entity_type);
1449 output["entityInstanceNumber"] = int(pdr->entity_instance);
1450 output["containerID"] = int(pdr->container_id);
1451 output["sensorNameStringByteLength"] = int(pdr->sensor_name_length);
1452 if (pdr->sensor_name_length == 0)
1453 {
1454 output["Name"] = std::format("PLDM_Device_TID{}_SensorId{}",
1455 unsigned(pdr->terminus_handle),
1456 unsigned(pdr->sensor_id));
1457 }
1458 else
1459 {
1460 std::string sTemp(reinterpret_cast<const char*>(pdr->sensor_name),
1461 pdr->sensor_name_length);
1462 output["Name"] = sTemp;
1463 }
1464 output["baseUnit"] = unsigned(pdr->base_unit);
1465 output["unitModifier"] = signed(pdr->unit_modifier);
1466 output["occurrenceRate"] = unsigned(pdr->occurrence_rate);
1467 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1468 if (pdr->range_field_support.bits.bit0)
1469 {
1470 output["warningHigh"] = int(pdr->warning_high);
1471 }
1472 if (pdr->range_field_support.bits.bit1)
1473 {
1474 output["warningLow"] = int(pdr->warning_low);
1475 }
1476 if (pdr->range_field_support.bits.bit2)
1477 {
1478 output["criticalHigh"] = int(pdr->critical_high);
1479 }
1480 if (pdr->range_field_support.bits.bit3)
1481 {
1482 output["criticalLow"] = int(pdr->critical_low);
1483 }
1484 if (pdr->range_field_support.bits.bit4)
1485 {
1486 output["fatalHigh"] = int(pdr->fatal_high);
1487 }
1488 if (pdr->range_field_support.bits.bit5)
1489 {
1490 output["fatalLow"] = int(pdr->fatal_low);
1491 }
1492 }
1493
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001494 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001495 uint8_t* data, std::optional<uint16_t> terminusHandle)
George Liud6649362019-11-27 19:06:51 +08001496 {
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -06001497 if (data == nullptr)
George Liud6649362019-11-27 19:06:51 +08001498 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301499 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +08001500 return;
1501 }
1502
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001503 ordered_json output;
1504 output["nextRecordHandle"] = nextRecordHndl;
1505 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +08001506
1507 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301508 if (!pdr)
1509 {
1510 return;
1511 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001512
1513 if (!pdrRecType.empty())
1514 {
1515 // Need to return if the requested PDR type
1516 // is not supported
1517 if (!strToPdrType.contains(pdrRecType))
1518 {
1519 std::cerr << "PDR type '" << pdrRecType
1520 << "' is not supported or invalid\n";
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -05001521 // PDR type not supported, setting next record handle to
1522 // 0 to avoid looping through all PDR records
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001523 nextRecordHndl = 0;
1524 return;
1525 }
1526
1527 // Do not print PDR record if the current record
1528 // PDR type does not match with requested type
1529 if (pdr->type != strToPdrType.at(pdrRecType))
1530 {
1531 return;
1532 }
1533 }
1534
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001535 if (pdrTerminus.has_value())
1536 {
1537 if (checkTerminusHandle(data, terminusHandle))
1538 {
1539 std::cerr << "The Terminus handle doesn't match return"
1540 << std::endl;
1541 return;
1542 }
1543 }
1544
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001545 printCommonPDRHeader(pdr, output);
1546
George Liud6649362019-11-27 19:06:51 +08001547 switch (pdr->type)
1548 {
Sampa Misra12afe112020-05-25 11:40:44 -05001549 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001550 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001551 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301552 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001553 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301554 break;
George Liu62d12ec2020-02-05 16:27:08 +08001555 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001556 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001557 break;
nothingIIersonalcea52d92024-03-21 13:56:02 +03001558 case PLDM_NUMERIC_SENSOR_PDR:
1559 printNumericSensorPDR(data, respCnt, output);
1560 break;
Thu Nguyen846d38f2022-03-26 08:57:21 +07001561 case PLDM_SENSOR_AUXILIARY_NAMES_PDR:
Thu Nguyen846d38f2022-03-26 08:57:21 +07001562 case PLDM_EFFECTER_AUXILIARY_NAMES_PDR:
1563 printAuxNamePDR(data, output);
1564 break;
George Liud6649362019-11-27 19:06:51 +08001565 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001566 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001567 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001568 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001569 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001570 break;
1571 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001572 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001573 break;
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001574 case PLDM_COMPACT_NUMERIC_SENSOR_PDR:
1575 printCompactNumericSensorPDR(data, output);
1576 break;
George Liud6649362019-11-27 19:06:51 +08001577 default:
1578 break;
1579 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001580 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001581 }
1582
1583 private:
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001584 bool optTIDSet = false;
George Liud6649362019-11-27 19:06:51 +08001585 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001586 bool allPDRs;
1587 std::string pdrRecType;
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001588 std::optional<uint8_t> pdrTerminus;
1589 std::optional<uint16_t> terminusHandle;
1590 bool handleFound = false;
1591 CLI::Option* getPDRGroupOption = nullptr;
Potin Lai3e52d582024-06-13 11:03:46 +08001592 uint32_t dataTransferHandle;
1593 uint8_t operationFlag;
1594 uint16_t requestCount;
1595 uint16_t recordChangeNumber;
1596 std::vector<uint8_t> recordData;
1597 bool nextPartRequired;
George Liud6649362019-11-27 19:06:51 +08001598};
1599
1600class SetStateEffecter : public CommandInterface
1601{
1602 public:
1603 ~SetStateEffecter() = default;
1604 SetStateEffecter() = delete;
1605 SetStateEffecter(const SetStateEffecter&) = delete;
1606 SetStateEffecter(SetStateEffecter&&) = default;
1607 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001608 SetStateEffecter& operator=(SetStateEffecter&&) = delete;
George Liud6649362019-11-27 19:06:51 +08001609
George Liuba4c1fb2020-02-05 14:13:30 +08001610 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1611 static constexpr auto maxEffecterDataSize = 16;
1612
1613 // compositeEffecterCount(value: 0x01 to 0x08)
1614 static constexpr auto minEffecterCount = 1;
1615 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001616 explicit SetStateEffecter(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001617 CLI::App* app) : CommandInterface(type, name, app)
George Liud6649362019-11-27 19:06:51 +08001618 {
1619 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001620 "-i, --id", effecterId,
1621 "A handle that is used to identify and access the effecter")
1622 ->required();
1623 app->add_option("-c, --count", effecterCount,
1624 "The number of individual sets of effecter information")
1625 ->required();
1626 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001627 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001628 "Set effecter state data\n"
1629 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1630 ->required();
George Liud6649362019-11-27 19:06:51 +08001631 }
1632
1633 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1634 {
1635 std::vector<uint8_t> requestMsg(
1636 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301637 auto request = new (requestMsg.data()) pldm_msg;
George Liud6649362019-11-27 19:06:51 +08001638
George Liuba4c1fb2020-02-05 14:13:30 +08001639 if (effecterCount > maxEffecterCount ||
1640 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001641 {
George Liuba4c1fb2020-02-05 14:13:30 +08001642 std::cerr << "Request Message Error: effecterCount size "
1643 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001644 auto rc = PLDM_ERROR_INVALID_DATA;
1645 return {rc, requestMsg};
1646 }
1647
George Liuba4c1fb2020-02-05 14:13:30 +08001648 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001649 {
George Liuba4c1fb2020-02-05 14:13:30 +08001650 std::cerr << "Request Message Error: effecterData size "
1651 << effecterData.size() << "is invalid\n";
1652 auto rc = PLDM_ERROR_INVALID_DATA;
1653 return {rc, requestMsg};
1654 }
1655
1656 auto stateField = parseEffecterData(effecterData, effecterCount);
1657 if (!stateField)
1658 {
1659 std::cerr << "Failed to parse effecter data, effecterCount size "
1660 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001661 auto rc = PLDM_ERROR_INVALID_DATA;
1662 return {rc, requestMsg};
1663 }
1664
1665 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001666 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001667 return {rc, requestMsg};
1668 }
1669
1670 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1671 {
1672 uint8_t completionCode = 0;
1673 auto rc = decode_set_state_effecter_states_resp(
1674 responsePtr, payloadLength, &completionCode);
1675
1676 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1677 {
1678 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001679 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001680 return;
1681 }
1682
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001683 ordered_json data;
1684 data["Response"] = "SUCCESS";
1685 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001686 }
1687
1688 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001689 uint16_t effecterId;
1690 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001691 std::vector<uint8_t> effecterData;
1692};
1693
George Liucc9c20d2020-02-05 10:24:11 +08001694class SetNumericEffecterValue : public CommandInterface
1695{
1696 public:
1697 ~SetNumericEffecterValue() = default;
1698 SetNumericEffecterValue() = delete;
1699 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1700 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1701 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001702 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete;
George Liucc9c20d2020-02-05 10:24:11 +08001703
1704 explicit SetNumericEffecterValue(const char* type, const char* name,
1705 CLI::App* app) :
1706 CommandInterface(type, name, app)
1707 {
1708 app->add_option(
1709 "-i, --id", effecterId,
1710 "A handle that is used to identify and access the effecter")
1711 ->required();
1712 app->add_option("-s, --size", effecterDataSize,
1713 "The bit width and format of the setting value for the "
1714 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1715 "uint32, sint32}\n")
1716 ->required();
1717 app->add_option("-d,--data", maxEffecterValue,
1718 "The setting value of numeric effecter being "
1719 "requested\n")
1720 ->required();
1721 }
1722
1723 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1724 {
1725 std::vector<uint8_t> requestMsg(
1726 sizeof(pldm_msg_hdr) +
1727 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1728
1729 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1730
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301731 auto request = new (requestMsg.data()) pldm_msg;
1732
George Liucc9c20d2020-02-05 10:24:11 +08001733 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1734
1735 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1736 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1737 {
1738 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1739 }
1740 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1741 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1742 {
1743 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1744 }
1745 auto rc = encode_set_numeric_effecter_value_req(
1746 0, effecterId, effecterDataSize, effecterValue, request,
1747 payload_length);
1748
1749 return {rc, requestMsg};
1750 }
1751
1752 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1753 {
1754 uint8_t completionCode = 0;
1755 auto rc = decode_set_numeric_effecter_value_resp(
1756 responsePtr, payloadLength, &completionCode);
1757
1758 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1759 {
1760 std::cerr << "Response Message Error: "
1761 << "rc=" << rc << ",cc=" << (int)completionCode
1762 << std::endl;
1763 return;
1764 }
1765
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001766 ordered_json data;
1767 data["Response"] = "SUCCESS";
1768 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001769 }
1770
1771 private:
1772 uint16_t effecterId;
1773 uint8_t effecterDataSize;
1774 uint64_t maxEffecterValue;
1775};
1776
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001777class GetStateSensorReadings : public CommandInterface
1778{
1779 public:
1780 ~GetStateSensorReadings() = default;
1781 GetStateSensorReadings() = delete;
1782 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1783 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1784 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001785 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001786
1787 explicit GetStateSensorReadings(const char* type, const char* name,
1788 CLI::App* app) :
1789 CommandInterface(type, name, app)
1790 {
1791 app->add_option(
1792 "-i, --sensor_id", sensorId,
1793 "Sensor ID that is used to identify and access the sensor")
1794 ->required();
1795 app->add_option("-r, --rearm", sensorRearm,
1796 "Each bit location in this field corresponds to a "
1797 "particular sensor")
1798 ->required();
1799 }
1800
1801 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1802 {
1803 std::vector<uint8_t> requestMsg(
1804 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301805 auto request = new (requestMsg.data()) pldm_msg;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001806
1807 uint8_t reserved = 0;
1808 bitfield8_t bf;
1809 bf.byte = sensorRearm;
1810 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1811 reserved, request);
1812
1813 return {rc, requestMsg};
1814 }
1815
1816 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1817 {
1818 uint8_t completionCode = 0;
1819 uint8_t compSensorCount = 0;
1820 std::array<get_sensor_state_field, 8> stateField{};
1821 auto rc = decode_get_state_sensor_readings_resp(
1822 responsePtr, payloadLength, &completionCode, &compSensorCount,
1823 stateField.data());
1824
1825 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1826 {
1827 std::cerr << "Response Message Error: "
1828 << "rc=" << rc << ",cc=" << (int)completionCode
1829 << std::endl;
1830 return;
1831 }
1832 ordered_json output;
1833 output["compositeSensorCount"] = (int)compSensorCount;
1834
1835 for (size_t i = 0; i < compSensorCount; i++)
1836 {
George Liubd5e2ea2021-04-22 20:33:06 +08001837 if (sensorOpState.contains(stateField[i].sensor_op_state))
1838 {
1839 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1840 sensorOpState.at(stateField[i].sensor_op_state));
1841 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001842
George Liubd5e2ea2021-04-22 20:33:06 +08001843 if (sensorPresState.contains(stateField[i].present_state))
1844 {
1845 output.emplace(("presentState[" + std::to_string(i) + "]"),
1846 sensorPresState.at(stateField[i].present_state));
1847 }
1848
1849 if (sensorPresState.contains(stateField[i].previous_state))
1850 {
1851 output.emplace(
1852 ("previousState[" + std::to_string(i) + "]"),
1853 sensorPresState.at(stateField[i].previous_state));
1854 }
1855
1856 if (sensorPresState.contains(stateField[i].event_state))
1857 {
1858 output.emplace(("eventState[" + std::to_string(i) + "]"),
1859 sensorPresState.at(stateField[i].event_state));
1860 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001861 }
1862
1863 pldmtool::helper::DisplayInJson(output);
1864 }
1865
1866 private:
1867 uint16_t sensorId;
1868 uint8_t sensorRearm;
1869};
1870
nothingIIersonal83e068a2024-03-21 13:55:06 +03001871class GetSensorReading : public CommandInterface
1872{
1873 public:
1874 ~GetSensorReading() = default;
1875 GetSensorReading() = delete;
1876 GetSensorReading(const GetSensorReading&) = delete;
1877 GetSensorReading(GetSensorReading&&) = default;
1878 GetSensorReading& operator=(const GetSensorReading&) = delete;
1879 GetSensorReading& operator=(GetSensorReading&&) = delete;
1880
1881 explicit GetSensorReading(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001882 CLI::App* app) : CommandInterface(type, name, app)
nothingIIersonal83e068a2024-03-21 13:55:06 +03001883 {
1884 app->add_option(
1885 "-i, --sensor_id", sensorId,
1886 "Sensor ID that is used to identify and access the sensor")
1887 ->required();
1888 app->add_option("-r, --rearm", rearm,
1889 "Manually re-arm EventState after "
1890 "responding to this request")
1891 ->required();
1892 }
1893
1894 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1895 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001896 std::vector<uint8_t> requestMsg(
1897 sizeof(pldm_msg_hdr) + PLDM_GET_SENSOR_READING_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301898 auto request = new (requestMsg.data()) pldm_msg;
nothingIIersonal83e068a2024-03-21 13:55:06 +03001899
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001900 auto rc =
1901 encode_get_sensor_reading_req(instanceId, sensorId, rearm, request);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001902
1903 return {rc, requestMsg};
1904 }
1905
1906 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1907 {
1908 uint8_t completionCode = 0;
1909 uint8_t sensorDataSize = 0;
1910 uint8_t sensorOperationalState = 0;
1911 uint8_t sensorEventMessageEnable = 0;
1912 uint8_t presentState = 0;
1913 uint8_t previousState = 0;
1914 uint8_t eventState = 0;
1915 std::array<uint8_t, sizeof(uint32_t)>
1916 presentReading{}; // maximum size for the present Value is uint32
1917 // according to spec DSP0248
1918
1919 auto rc = decode_get_sensor_reading_resp(
1920 responsePtr, payloadLength, &completionCode, &sensorDataSize,
1921 &sensorOperationalState, &sensorEventMessageEnable, &presentState,
1922 &previousState, &eventState, presentReading.data());
1923
1924 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1925 {
1926 std::cerr << "Response Message Error: "
1927 << "rc=" << rc << ",cc=" << (int)completionCode
1928 << std::endl;
1929 return;
1930 }
1931
1932 ordered_json output;
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001933 output["sensorDataSize"] =
1934 getSensorState(sensorDataSize, &sensorDataSz);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001935 output["sensorOperationalState"] =
1936 getSensorState(sensorOperationalState, &sensorOpState);
1937 output["sensorEventMessageEnable"] =
1938 getSensorState(sensorEventMessageEnable, &sensorEventMsgEnable);
1939 output["presentState"] = getSensorState(presentState, &sensorPresState);
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001940 output["previousState"] =
1941 getSensorState(previousState, &sensorPresState);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001942 output["eventState"] = getSensorState(eventState, &sensorPresState);
1943
1944 switch (sensorDataSize)
1945 {
1946 case PLDM_SENSOR_DATA_SIZE_UINT8:
1947 {
1948 output["presentReading"] =
1949 *(reinterpret_cast<uint8_t*>(presentReading.data()));
1950 break;
1951 }
1952 case PLDM_SENSOR_DATA_SIZE_SINT8:
1953 {
1954 output["presentReading"] =
1955 *(reinterpret_cast<int8_t*>(presentReading.data()));
1956 break;
1957 }
1958 case PLDM_SENSOR_DATA_SIZE_UINT16:
1959 {
1960 output["presentReading"] =
1961 *(reinterpret_cast<uint16_t*>(presentReading.data()));
1962 break;
1963 }
1964 case PLDM_SENSOR_DATA_SIZE_SINT16:
1965 {
1966 output["presentReading"] =
1967 *(reinterpret_cast<int16_t*>(presentReading.data()));
1968 break;
1969 }
1970 case PLDM_SENSOR_DATA_SIZE_UINT32:
1971 {
1972 output["presentReading"] =
1973 *(reinterpret_cast<uint32_t*>(presentReading.data()));
1974 break;
1975 }
1976 case PLDM_SENSOR_DATA_SIZE_SINT32:
1977 {
1978 output["presentReading"] =
1979 *(reinterpret_cast<int32_t*>(presentReading.data()));
1980 break;
1981 }
1982 default:
1983 {
1984 std::cerr << "Unknown Sensor Data Size : "
1985 << static_cast<int>(sensorDataSize) << std::endl;
1986 break;
1987 }
1988 }
1989
1990 pldmtool::helper::DisplayInJson(output);
1991 }
1992
1993 private:
1994 uint16_t sensorId;
1995 uint8_t rearm;
1996
1997 const std::map<uint8_t, std::string> sensorDataSz = {
1998 {PLDM_SENSOR_DATA_SIZE_UINT8, "uint8"},
1999 {PLDM_SENSOR_DATA_SIZE_SINT8, "uint8"},
2000 {PLDM_SENSOR_DATA_SIZE_UINT16, "uint16"},
2001 {PLDM_SENSOR_DATA_SIZE_SINT16, "uint16"},
2002 {PLDM_SENSOR_DATA_SIZE_UINT32, "uint32"},
2003 {PLDM_SENSOR_DATA_SIZE_SINT32, "uint32"}};
2004
2005 static inline const std::map<uint8_t, std::string> sensorEventMsgEnable{
2006 {PLDM_NO_EVENT_GENERATION, "Sensor No Event Generation"},
2007 {PLDM_EVENTS_DISABLED, "Sensor Events Disabled"},
2008 {PLDM_EVENTS_ENABLED, "Sensor Events Enabled"},
2009 {PLDM_OP_EVENTS_ONLY_ENABLED, "Sensor Op Events Only Enabled"},
2010 {PLDM_STATE_EVENTS_ONLY_ENABLED, "Sensor State Events Only Enabled"}};
2011
2012 std::string getSensorState(uint8_t state,
2013 const std::map<uint8_t, std::string>* cont)
2014 {
2015 auto typeString = std::to_string(state);
2016 try
2017 {
2018 return cont->at(state);
2019 }
2020 catch (const std::out_of_range& e)
2021 {
2022 return typeString;
2023 }
2024 }
2025};
2026
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002027class GetStateEffecterStates : public CommandInterface
2028{
2029 public:
2030 ~GetStateEffecterStates() = default;
2031 GetStateEffecterStates() = delete;
2032 GetStateEffecterStates(const GetStateEffecterStates&) = delete;
2033 GetStateEffecterStates(GetStateEffecterStates&&) = default;
2034 GetStateEffecterStates& operator=(const GetStateEffecterStates&) = delete;
2035 GetStateEffecterStates& operator=(GetStateEffecterStates&&) = delete;
2036
2037 explicit GetStateEffecterStates(const char* type, const char* name,
2038 CLI::App* app) :
2039 CommandInterface(type, name, app)
2040 {
2041 app->add_option(
2042 "-i, --effecter_id", effecter_id,
2043 "Effecter ID that is used to identify and access the effecter")
2044 ->required();
2045 }
2046
2047 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2048 {
2049 std::vector<uint8_t> requestMsg(
2050 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05302051 auto request = new (requestMsg.data()) pldm_msg;
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002052
2053 auto rc = encode_get_state_effecter_states_req(
2054 instanceId, effecter_id, request,
2055 PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
2056
2057 return {rc, requestMsg};
2058 }
2059
2060 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2061 {
2062 struct pldm_get_state_effecter_states_resp resp;
2063 auto rc = decode_get_state_effecter_states_resp(responsePtr,
2064 payloadLength, &resp);
2065
2066 if (rc || resp.completion_code != PLDM_SUCCESS)
2067 {
2068 std::cerr << "Response Message Error: "
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002069 << "rc=" << rc << ",cc="
2070 << static_cast<int>(resp.completion_code) << std::endl;
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002071 return;
2072 }
2073 ordered_json output;
2074 auto comp_effecter_count = static_cast<int>(resp.comp_effecter_count);
2075 output["compositeEffecterCount"] = comp_effecter_count;
2076
Tal Yacobi92af05e2024-07-28 14:18:07 +03002077 for (auto i : std::views::iota(0, comp_effecter_count))
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002078 {
2079 output[std::format("effecterOpState[{}])", i)] =
2080 getEffecterOpState(resp.field[i].effecter_op_state);
2081
2082 output[std::format("pendingState[{}]", i)] =
2083 resp.field[i].pending_state;
2084
2085 output[std::format("presentState[{}]", i)] =
2086 resp.field[i].present_state;
2087 }
2088
2089 pldmtool::helper::DisplayInJson(output);
2090 }
2091
2092 private:
2093 uint16_t effecter_id;
2094};
2095
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002096class GetNumericEffecterValue : public CommandInterface
2097{
2098 public:
2099 ~GetNumericEffecterValue() = default;
2100 GetNumericEffecterValue() = delete;
2101 GetNumericEffecterValue(const GetNumericEffecterValue&) = delete;
2102 GetNumericEffecterValue(GetNumericEffecterValue&&) = default;
2103 GetNumericEffecterValue& operator=(const GetNumericEffecterValue&) = delete;
Pavithra Barithayaae088dc2023-11-09 01:14:05 -06002104 GetNumericEffecterValue& operator=(GetNumericEffecterValue&&) = delete;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002105
2106 explicit GetNumericEffecterValue(const char* type, const char* name,
2107 CLI::App* app) :
2108 CommandInterface(type, name, app)
2109 {
2110 app->add_option(
2111 "-i, --effecter_id", effecterId,
2112 "A handle that is used to identify and access the effecter")
2113 ->required();
2114 }
2115
2116 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2117 {
2118 std::vector<uint8_t> requestMsg(
2119 sizeof(pldm_msg_hdr) + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05302120 auto request = new (requestMsg.data()) pldm_msg;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002121
2122 auto rc = encode_get_numeric_effecter_value_req(instanceId, effecterId,
2123 request);
2124
2125 return {rc, requestMsg};
2126 }
2127
2128 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2129 {
2130 uint8_t completionCode = 0;
2131 uint8_t effecterDataSize = 0;
2132 uint8_t effecterOperationalState = 0;
2133 std::array<uint8_t, sizeof(uint32_t)>
2134 pendingValue{}; // maximum size for the pending Value is uint32
2135 // according to spec DSP0248
2136 std::array<uint8_t, sizeof(uint32_t)>
2137 presentValue{}; // maximum size for the present Value is uint32
2138 // according to spec DSP0248
2139
2140 auto rc = decode_get_numeric_effecter_value_resp(
2141 responsePtr, payloadLength, &completionCode, &effecterDataSize,
2142 &effecterOperationalState, pendingValue.data(),
2143 presentValue.data());
2144
2145 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
2146 {
2147 std::cerr << "Response Message Error: "
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002148 << "rc=" << rc << ",cc="
2149 << static_cast<int>(completionCode) << std::endl;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002150 return;
2151 }
2152
2153 ordered_json output;
2154 output["effecterDataSize"] = static_cast<int>(effecterDataSize);
2155 output["effecterOperationalState"] =
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002156 getEffecterOpState(effecterOperationalState);
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002157
2158 switch (effecterDataSize)
2159 {
2160 case PLDM_EFFECTER_DATA_SIZE_UINT8:
2161 {
2162 output["pendingValue"] =
2163 *(reinterpret_cast<uint8_t*>(pendingValue.data()));
2164 output["presentValue"] =
2165 *(reinterpret_cast<uint8_t*>(presentValue.data()));
2166 break;
2167 }
2168 case PLDM_EFFECTER_DATA_SIZE_SINT8:
2169 {
2170 output["pendingValue"] =
2171 *(reinterpret_cast<int8_t*>(pendingValue.data()));
2172 output["presentValue"] =
2173 *(reinterpret_cast<int8_t*>(presentValue.data()));
2174 break;
2175 }
2176 case PLDM_EFFECTER_DATA_SIZE_UINT16:
2177 {
2178 output["pendingValue"] =
2179 *(reinterpret_cast<uint16_t*>(pendingValue.data()));
2180 output["presentValue"] =
2181 *(reinterpret_cast<uint16_t*>(presentValue.data()));
2182 break;
2183 }
2184 case PLDM_EFFECTER_DATA_SIZE_SINT16:
2185 {
2186 output["pendingValue"] =
2187 *(reinterpret_cast<int16_t*>(pendingValue.data()));
2188 output["presentValue"] =
2189 *(reinterpret_cast<int16_t*>(presentValue.data()));
2190 break;
2191 }
2192 case PLDM_EFFECTER_DATA_SIZE_UINT32:
2193 {
2194 output["pendingValue"] =
2195 *(reinterpret_cast<uint32_t*>(pendingValue.data()));
2196 output["presentValue"] =
2197 *(reinterpret_cast<uint32_t*>(presentValue.data()));
2198 break;
2199 }
2200 case PLDM_EFFECTER_DATA_SIZE_SINT32:
2201 {
2202 output["pendingValue"] =
2203 *(reinterpret_cast<int32_t*>(pendingValue.data()));
2204 output["presentValue"] =
2205 *(reinterpret_cast<int32_t*>(presentValue.data()));
2206 break;
2207 }
2208 default:
2209 {
2210 std::cerr << "Unknown Effecter Data Size : "
2211 << static_cast<int>(effecterDataSize) << std::endl;
2212 break;
2213 }
2214 }
2215
2216 pldmtool::helper::DisplayInJson(output);
2217 }
2218
2219 private:
2220 uint16_t effecterId;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002221};
2222
George Liud6649362019-11-27 19:06:51 +08002223void registerCommand(CLI::App& app)
2224{
2225 auto platform = app.add_subcommand("platform", "platform type command");
2226 platform->require_subcommand(1);
2227
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002228 auto getPDR =
2229 platform->add_subcommand("GetPDR", "get platform descriptor records");
George Liud6649362019-11-27 19:06:51 +08002230 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
2231
2232 auto setStateEffecterStates = platform->add_subcommand(
2233 "SetStateEffecterStates", "set effecter states");
2234 commands.push_back(std::make_unique<SetStateEffecter>(
2235 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08002236
2237 auto setNumericEffecterValue = platform->add_subcommand(
2238 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
2239 commands.push_back(std::make_unique<SetNumericEffecterValue>(
2240 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06002241
2242 auto getStateSensorReadings = platform->add_subcommand(
2243 "GetStateSensorReadings", "get the state sensor readings");
2244 commands.push_back(std::make_unique<GetStateSensorReadings>(
2245 "platform", "getStateSensorReadings", getStateSensorReadings));
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002246
2247 auto getNumericEffecterValue = platform->add_subcommand(
2248 "GetNumericEffecterValue", "get the numeric effecter value");
2249 commands.push_back(std::make_unique<GetNumericEffecterValue>(
2250 "platform", "getNumericEffecterValue", getNumericEffecterValue));
nothingIIersonal83e068a2024-03-21 13:55:06 +03002251
2252 auto getSensorReading = platform->add_subcommand(
2253 "GetSensorReading", "get the numeric sensor reading");
2254 commands.push_back(std::make_unique<GetSensorReading>(
2255 "platform", "getSensorReading", getSensorReading));
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002256
2257 auto getStateEffecterStates = platform->add_subcommand(
2258 "GetStateEffecterStates", "get the state effecter states");
2259 commands.push_back(std::make_unique<GetStateEffecterStates>(
2260 "platform", "getStateEffecterStates", getStateEffecterStates));
George Liud6649362019-11-27 19:06:51 +08002261}
2262
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06002263void parseGetPDROption()
2264{
2265 for (const auto& command : commands)
2266 {
2267 if (command.get()->getPLDMType() == "platform" &&
2268 command.get()->getCommandName() == "getPDR")
2269 {
2270 auto getPDR = dynamic_cast<GetPDR*>(command.get());
2271 getPDR->parseGetPDROptions();
2272 }
2273 }
2274}
2275
George Liud6649362019-11-27 19:06:51 +08002276} // namespace platform
2277} // namespace pldmtool