blob: 9d7266e65cd2a453d4dcca1a7a2b2526c24ad5cd [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>
5#include <libpldm/state_set.h>
6
Brad Bishop02d71142021-10-14 19:00:17 -04007#include <cstddef>
8#include <map>
9
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -050010#ifdef OEM_IBM
11#include "oem/ibm/oem_ibm_state_set.hpp"
12#endif
13
Brad Bishop5079ac42021-08-19 18:35:06 -040014using namespace pldm::utils;
15
George Liud6649362019-11-27 19:06:51 +080016namespace pldmtool
17{
George Liud6649362019-11-27 19:06:51 +080018namespace platform
19{
George Liud6649362019-11-27 19:06:51 +080020namespace
21{
George Liud6649362019-11-27 19:06:51 +080022using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060023
24static const std::map<uint8_t, std::string> sensorPresState{
25 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
26 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
27 {PLDM_SENSOR_WARNING, "Sensor Warning"},
28 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
29 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
30 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
31 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
32 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
33 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
34 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
35 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
36
37static const std::map<uint8_t, std::string> sensorOpState{
38 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
39 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
40 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
41 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
42 {PLDM_SENSOR_FAILED, "Sensor Failed"},
43 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Intializing"},
44 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
45 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
46
George Liud6649362019-11-27 19:06:51 +080047std::vector<std::unique_ptr<CommandInterface>> commands;
48
49} // namespace
50
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050051using ordered_json = nlohmann::ordered_json;
52
George Liud6649362019-11-27 19:06:51 +080053class GetPDR : public CommandInterface
54{
55 public:
56 ~GetPDR() = default;
57 GetPDR() = delete;
58 GetPDR(const GetPDR&) = delete;
59 GetPDR(GetPDR&&) = default;
60 GetPDR& operator=(const GetPDR&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -050061 GetPDR& operator=(GetPDR&&) = delete;
George Liud6649362019-11-27 19:06:51 +080062
63 using CommandInterface::CommandInterface;
64
George Liud6649362019-11-27 19:06:51 +080065 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
66 CommandInterface(type, name, app)
67 {
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050068 auto pdrOptionGroup = app->add_option_group(
69 "Required Option",
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060070 "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 -050071 pdrOptionGroup->add_option(
72 "-d,--data", recordHandle,
73 "retrieve individual PDRs from a PDR Repository\n"
74 "eg: The recordHandle value for the PDR to be retrieved and 0 "
75 "means get first PDR in the repository.");
76 pdrRecType = "";
77 pdrOptionGroup->add_option("-t, --type", pdrRecType,
78 "retrieve all PDRs of the requested type\n"
79 "supported types:\n"
80 "[terminusLocator, stateSensor, "
81 "numericEffecter, stateEffecter, "
82 "EntityAssociation, fruRecord, ... ]");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060083
84 getPDRGroupOption = pdrOptionGroup->add_option(
85 "-i, --terminusID", pdrTerminus,
86 "retrieve all PDRs of the requested terminusID\n"
87 "supported IDs:\n [1, 2, 208...]");
88
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050089 allPDRs = false;
90 pdrOptionGroup->add_flag("-a, --all", allPDRs,
91 "retrieve all PDRs from a PDR repository");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060092
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050093 pdrOptionGroup->require_option(1);
94 }
95
Pavithra Barithayaa340eed2023-02-14 03:32:47 -060096 void parseGetPDROptions()
97 {
98 optTIDSet = false;
99 if (getPDRGroupOption->count() > 0)
100 {
101 optTIDSet = true;
102 getPDRs();
103 }
104 }
105
106 void getPDRs()
107 {
108 // start the array
109 std::cout << "[";
110
111 recordHandle = 0;
112 do
113 {
114 CommandInterface::exec();
115 } while (recordHandle != 0);
116
117 // close the array
118 std::cout << "]\n";
119
120 if (handleFound)
121 {
122 recordHandle = 0;
123 uint32_t prevRecordHandle = 0;
124 do
125 {
126 CommandInterface::exec();
127 if (recordHandle == prevRecordHandle)
128 {
129 return;
130 }
131 prevRecordHandle = recordHandle;
132 } while (recordHandle != 0);
133 }
134 }
135
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500136 void exec() override
137 {
138 if (allPDRs || !pdrRecType.empty())
139 {
140 if (!pdrRecType.empty())
141 {
142 std::transform(pdrRecType.begin(), pdrRecType.end(),
143 pdrRecType.begin(), tolower);
144 }
145
Brad Bishop16eff862021-10-14 19:44:32 -0400146 // start the array
147 std::cout << "[\n";
148
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500149 // Retrieve all PDR records starting from the first
150 recordHandle = 0;
151 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400152 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500153 do
154 {
155 CommandInterface::exec();
156 // recordHandle is updated to nextRecord when
157 // CommandInterface::exec() is successful.
158 // In case of any error, return.
159 if (recordHandle == prevRecordHandle)
160 {
161 return;
162 }
Brad Bishop02d71142021-10-14 19:00:17 -0400163
164 // check for circular references.
Patrick Williams6da4f912023-05-10 07:50:53 -0500165 auto result = recordsSeen.emplace(recordHandle,
166 prevRecordHandle);
Brad Bishop02d71142021-10-14 19:00:17 -0400167 if (!result.second)
168 {
169 std::cerr
170 << "Record handle " << recordHandle
171 << " has multiple references: " << result.first->second
172 << ", " << prevRecordHandle << "\n";
173 return;
174 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500175 prevRecordHandle = recordHandle;
Brad Bishop16eff862021-10-14 19:44:32 -0400176
177 if (recordHandle != 0)
178 {
179 // close the array
180 std::cout << ",";
181 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500182 } while (recordHandle != 0);
Brad Bishop16eff862021-10-14 19:44:32 -0400183
184 // close the array
185 std::cout << "]\n";
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500186 }
187 else
188 {
189 CommandInterface::exec();
190 }
George Liud6649362019-11-27 19:06:51 +0800191 }
192
193 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
194 {
195 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
196 PLDM_GET_PDR_REQ_BYTES);
197 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
198
Patrick Williams6da4f912023-05-10 07:50:53 -0500199 auto rc = encode_get_pdr_req(instanceId, recordHandle, 0,
200 PLDM_GET_FIRSTPART, UINT16_MAX, 0, request,
201 PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800202 return {rc, requestMsg};
203 }
204
205 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
206 {
207 uint8_t completionCode = 0;
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500208 uint8_t recordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800209 uint32_t nextRecordHndl = 0;
210 uint32_t nextDataTransferHndl = 0;
211 uint8_t transferFlag = 0;
212 uint16_t respCnt = 0;
213 uint8_t transferCRC = 0;
214
215 auto rc = decode_get_pdr_resp(
216 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
217 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
218 sizeof(recordData), &transferCRC);
219
220 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
221 {
222 std::cerr << "Response Message Error: "
223 << "rc=" << rc << ",cc=" << (int)completionCode
224 << std::endl;
225 return;
226 }
227
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600228 if (optTIDSet && !handleFound)
229 {
230 terminusHandle = getTerminusHandle(recordData, pdrTerminus);
231 if (terminusHandle.has_value())
232 {
233 recordHandle = 0;
234 return;
235 }
236 else
237 {
238 recordHandle = nextRecordHndl;
239 return;
240 }
241 }
242
243 else
244 {
245 printPDRMsg(nextRecordHndl, respCnt, recordData, terminusHandle);
246 recordHandle = nextRecordHndl;
247 }
George Liud6649362019-11-27 19:06:51 +0800248 }
249
250 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530251 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530252 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
253 {PLDM_ENTITY_OTHER, "Other"},
254 {PLDM_ENTITY_NETWORK, "Network"},
255 {PLDM_ENTITY_GROUP, "Group"},
256 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
257 "Remote Management Communication Device"},
258 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
259 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
260 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
261 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
262 {PLDM_ENTITY_KEYPAD, "keypad"},
263 {PLDM_ENTITY_SWITCH, "Switch"},
264 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
265 {PLDM_ENTITY_DISPLAY, "Display"},
266 {PLDM_ENTITY_INDICATOR, "Indicator"},
267 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530268 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530269 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530270 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530271 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
272 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
273 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530274 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530275 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
276 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
277 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
278 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
279 {PLDM_ENTITY_DOOR, "Door"},
280 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
281 {PLDM_ENTITY_COVER, "Cover"},
282 {PLDM_ENTITY_BOARD, "Board"},
283 {PLDM_ENTITY_CARD, "Card"},
284 {PLDM_ENTITY_MODULE, "Module"},
285 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530286 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530287 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530288 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
289 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530290 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530291 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530292 "Chassis front panel board(control panel)"},
293 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
294 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
295 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
296 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
297 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
298 "System internal expansion board"},
299 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
300 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
301 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
302 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
303 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
304 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
305 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
306 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
307 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
308 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500309 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530310 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
311 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
312 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
313 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
314 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
315 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
316 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
317 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
318 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
319 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500320 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530321 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
322 {PLDM_ENTITY_BATTERY, "Battery"},
323 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
324 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
325 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
326 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
327 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
328 {PLDM_ENTITY_PROC, "Processor"},
329 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
330 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
331 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
332 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
333 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
334 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
335 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
336 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
337 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
338 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
339 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500340 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530341 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
342 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
343 {PLDM_ENTITY_SYS_BUS, "System Bus"},
344 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
345 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
346 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
347 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
348 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
349 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
350 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
351 {PLDM_ENTITY_USB_BUS, "USB Bus"},
352 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
353 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
354 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
355 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
356 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
357 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500358 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530359 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
360 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
361 {PLDM_ENTITY_PLUG, "Plug"},
362 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500363 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500364
Tom Josepha65c0412020-07-03 21:14:44 +0530365 const std::map<uint16_t, std::string> stateSet = {
366 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
367 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530368 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
369 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
370 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
371 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
372 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530373 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530374 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
375 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530376 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
377 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530378 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
379 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530380 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530381 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530382 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530383 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
384 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
385 {PLDM_STATE_SET_VERSION, "Version"},
386 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
387 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
388 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
389 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530390 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530391 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
392 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
393 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
394 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
395 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
396 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
397 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
398 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
399 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
400 "Physical Communication Connection"},
401 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
402 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
403 "Foreign Network Detection Status"},
404 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
405 "Password-Protected Access Security"},
406 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
407 "Security Access –PrivilegeLevel"},
408 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530409 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530410 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530411 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530412 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
413 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
414 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530415 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530416 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
417 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
418 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
419 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
420 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
421 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
422 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
423 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
424 "Diagnostic Interrupt Requested"},
425 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
426 "Diagnostic Interrupt Received"},
427 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
428 "I/O Channel Check NMI Requested"},
429 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
430 "I/O Channel Check NMI Received"},
431 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
432 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
433 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
434 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
435 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
436 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
437 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
438 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
439 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
440 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
441 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
442 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
443 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
444 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
445 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
446 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
447 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
448 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
449 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
450 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
451 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
452 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
453 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
454 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
455 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
456 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
457 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
458 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
459 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
460 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
461 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
462 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
463 "Redundant Memory Activity Status"},
464 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
465 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
466 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
467 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500468 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
469 };
Tom Josepha65c0412020-07-03 21:14:44 +0530470
471 const std::array<std::string_view, 4> sensorInit = {
472 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
473
Tom Joseph97a7a762020-07-06 10:37:18 +0530474 const std::array<std::string_view, 4> effecterInit = {
475 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
476
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500477 const std::map<uint8_t, std::string> pdrType = {
478 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
479 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
480 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
481 "Numeric Sensor Initialization PDR"},
482 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
483 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
484 "State Sensor Initialization PDR"},
485 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
486 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
487 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
488 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
489 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
490 "Numeric Effecter Initialization PDR"},
491 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
492 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
493 "State Effecter Initialization PDR"},
494 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
495 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
496 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
497 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
498 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
499 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
500 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
501 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
502 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
503 {PLDM_OEM_PDR, "OEM PDR"},
504 };
505
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500506 static inline const std::map<uint8_t, std::string> setThermalTrip{
507 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
508 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
509
510 static inline const std::map<uint8_t, std::string> setIdentifyState{
511 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
512 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
513
514 static inline const std::map<uint8_t, std::string> setBootProgressState{
515 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
516 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
517 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
518 "Memory Initialization"},
519 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
520 "Secondary Processor(s) Initialization"},
521 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
522 "PCI Resource Configuration"},
523 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
524 "Starting Operating System"},
525 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
526 "Baseboard Initialization"},
527 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
kamal00a076d2022-11-08 04:24:36 -0600528 "Primary Processor Initialization"},
529 {PLDM_STATE_SET_BOOT_PROG_STATE_OSSTART, "OSStart"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500530
531 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -0500532 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
533 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_ERROR, "Error"},
534 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NON_RECOVERABLE_ERROR,
535 "Non Recoverable Error"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500536
537 static inline const std::map<uint8_t, std::string> setSysPowerState{
538 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
539 "Off-Soft Graceful"}};
540
541 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
542 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
543 "Graceful Restart Requested"}};
544
545 static inline const std::map<uint8_t, std::string> setAvailability{
546 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
547
548 static inline const std::map<uint8_t, std::string> setHealthState{
549 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530550 {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"},
551 {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"},
552 {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"},
553 {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"},
554 {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500555 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530556 {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"},
557 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"},
558 {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}};
559
560 static inline const std::map<uint8_t, std::string>
561 setOperationalRunningState{
562 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"},
563 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"},
564 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"},
565 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE,
566 "In Service"},
567 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"},
568 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500569
570 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
571 populatePStateMaps{
572 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
573 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
574 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
575 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
576 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
577 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
578 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
579 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530580 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
581 setOperationalRunningState},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500582 };
583
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500584 const std::map<std::string, uint8_t> strToPdrType = {
585 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
586 {"statesensor", PLDM_STATE_SENSOR_PDR},
587 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
588 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
589 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
590 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
591 // Add other types
592 };
593
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530594 bool isLogicalBitSet(const uint16_t entity_type)
595 {
596 return entity_type & 0x8000;
597 }
598
599 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
600 {
601 return logical_entity_type & 0x7FFF;
602 }
603
Tom Josepha65c0412020-07-03 21:14:44 +0530604 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500605 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530606 uint16_t entityNumber = type;
607 std::string entityName = "[Physical] ";
608
609 if (isLogicalBitSet(type))
610 {
611 entityName = "[Logical] ";
612 entityNumber = getEntityTypeForLogicalEntity(type);
613 }
614
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500615 try
616 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530617 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500618 }
619 catch (const std::out_of_range& e)
620 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500621 auto OemString =
622 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530623 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
624 type <= PLDM_OEM_ENTITY_TYPE_END)
625 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500626#ifdef OEM_IBM
627 if (OemIBMEntityType.contains(entityNumber))
628 {
629 return entityName + OemIBMEntityType.at(entityNumber) +
630 "(OEM)";
631 }
632#endif
633 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530634 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500635 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500636 }
637 }
638
Tom Josepha65c0412020-07-03 21:14:44 +0530639 std::string getStateSetName(uint16_t id)
640 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500641 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530642 try
643 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500644 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530645 }
646 catch (const std::out_of_range& e)
647 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500648 return typeString;
649 }
650 }
651
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500652 std::vector<std::string>
653 getStateSetPossibleStateNames(uint16_t stateId,
654 const std::vector<uint8_t>& value)
655 {
656 std::vector<std::string> data{};
657 std::map<uint8_t, std::string> stateNameMaps;
658
659 for (auto& s : value)
660 {
661 std::map<uint8_t, std::string> stateNameMaps;
662 auto pstr = std::to_string(s);
663
664#ifdef OEM_IBM
Manojkiran Edabe1a8572022-01-06 11:20:36 +0530665 if (stateId >= PLDM_OEM_STATE_SET_ID_START &&
666 stateId < PLDM_OEM_STATE_SET_ID_END)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500667 {
668 if (populateOemIBMStateMaps.contains(stateId))
669 {
670 const std::map<uint8_t, std::string> stateNames =
671 populateOemIBMStateMaps.at(stateId);
672 stateNameMaps.insert(stateNames.begin(), stateNames.end());
673 }
674 }
675#endif
676 if (populatePStateMaps.contains(stateId))
677 {
678 const std::map<uint8_t, std::string> stateNames =
679 populatePStateMaps.at(stateId);
680 stateNameMaps.insert(stateNames.begin(), stateNames.end());
681 }
682 if (stateNameMaps.contains(s))
683 {
684 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
685 }
686 else
687 {
688 data.push_back(pstr);
689 }
690 }
691 return data;
692 }
693
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500694 std::string getPDRType(uint8_t type)
695 {
696 auto typeString = std::to_string(type);
697 try
698 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500699 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500700 }
701 catch (const std::out_of_range& e)
702 {
703 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530704 }
705 }
706
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500707 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530708 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500709 output["recordHandle"] = hdr->record_handle;
710 output["PDRHeaderVersion"] = unsigned(hdr->version);
711 output["PDRType"] = getPDRType(hdr->type);
712 output["recordChangeNumber"] = hdr->record_change_num;
713 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530714 }
715
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500716 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
717 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530718 {
719 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500720 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500721 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
722 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530723 for (int i = 0; i < CHAR_BIT; i++)
724 {
725 if (val.byte & (1 << i))
726 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500727 pstates << (possibleStatesPos * CHAR_BIT + i);
728 data.push_back(
729 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600730 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530731 }
732 }
733 possibleStatesPos++;
734 };
735 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500736 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530737 }
738
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500739 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530740 {
741 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500742 output["PLDMTerminusHandle"] = pdr->terminus_handle;
743 output["sensorID"] = pdr->sensor_id;
744 output["entityType"] = getEntityName(pdr->entity_type);
745 output["entityInstanceNumber"] = pdr->entity_instance;
746 output["containerID"] = pdr->container_id;
747 output["sensorInit"] = sensorInit[pdr->sensor_init];
748 output["sensorAuxiliaryNamesPDR"] =
749 (pdr->sensor_auxiliary_names_pdr ? true : false);
750 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530751
752 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600753 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530754
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600755 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530756 {
757 auto state = reinterpret_cast<const state_sensor_possible_states*>(
758 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600759 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
760 getStateSetName(state->state_set_id));
761 output.emplace(
762 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
763 state->possible_states_size);
764 output.emplace(
765 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500766 getStateSetPossibleStateNames(
767 state->state_set_id,
768 printPossibleStates(state->possible_states_size,
769 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530770
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600771 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530772 {
773 statesPtr += sizeof(state_sensor_possible_states) +
774 state->possible_states_size - 1;
775 }
776 }
777 }
778
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500779 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500780 {
George Liu62d12ec2020-02-05 16:27:08 +0800781 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500782 {
783 return;
784 }
785
786 data += sizeof(pldm_pdr_hdr);
787 pldm_pdr_fru_record_set* pdr =
788 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530789 if (!pdr)
790 {
791 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
792 return;
793 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500794
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500795 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
796 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
797 output["entityType"] = getEntityName(pdr->entity_type);
798 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
799 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500800 }
801
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500802 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500803 {
804 const std::map<uint8_t, const char*> assocationType = {
805 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
806 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
807 };
808
George Liu62d12ec2020-02-05 16:27:08 +0800809 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500810 {
811 return;
812 }
813
814 data += sizeof(pldm_pdr_hdr);
815 pldm_pdr_entity_association* pdr =
816 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530817 if (!pdr)
818 {
819 std::cerr << "Failed to get the PDR eneity association"
820 << std::endl;
821 return;
822 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500823
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500824 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800825 if (assocationType.contains(pdr->association_type))
826 {
827 output["associationType"] =
828 assocationType.at(pdr->association_type);
829 }
830 else
831 {
832 std::cout << "Get associationType failed.\n";
833 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500834 output["containerEntityType"] =
835 getEntityName(pdr->container.entity_type);
836 output["containerEntityInstanceNumber"] =
837 int(pdr->container.entity_instance_num);
838 output["containerEntityContainerID"] =
839 int(pdr->container.entity_container_id);
840 output["containedEntityCount"] =
841 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500842
843 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
844 for (int i = 0; i < pdr->num_children; ++i)
845 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500846 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
847 getEntityName(child->entity_type));
848 output.emplace("containedEntityInstanceNumber[" +
849 std::to_string(i + 1) + "]",
850 unsigned(child->entity_instance_num));
851 output.emplace("containedEntityContainerID[" +
852 std::to_string(i + 1) + "]",
853 unsigned(child->entity_container_id));
854
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500855 ++child;
856 }
857 }
858
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500859 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800860 {
861 struct pldm_numeric_effecter_value_pdr* pdr =
862 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530863 if (!pdr)
864 {
865 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
866 return;
867 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500868
869 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
870 output["effecterID"] = int(pdr->effecter_id);
871 output["entityType"] = int(pdr->entity_type);
872 output["entityInstanceNumber"] = int(pdr->entity_instance);
873 output["containerID"] = int(pdr->container_id);
874 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
875 output["effecterInit"] = unsigned(pdr->effecter_init);
876 output["effecterAuxiliaryNames"] =
877 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
878 output["baseUnit"] = unsigned(pdr->base_unit);
879 output["unitModifier"] = unsigned(pdr->unit_modifier);
880 output["rateUnit"] = unsigned(pdr->rate_unit);
881 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
882 output["auxUnit"] = unsigned(pdr->aux_unit);
883 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
884 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
885 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
886 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
887 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
888 output["resolution"] = unsigned(pdr->resolution);
889 output["offset"] = unsigned(pdr->offset);
890 output["accuracy"] = unsigned(pdr->accuracy);
891 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
892 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
893 output["stateTransitionInterval"] =
894 unsigned(pdr->state_transition_interval);
895 output["TransitionInterval"] = unsigned(pdr->transition_interval);
896
George Liu62d12ec2020-02-05 16:27:08 +0800897 switch (pdr->effecter_data_size)
898 {
899 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530900 output["maxSettable"] = unsigned(pdr->max_settable.value_u8);
901 output["minSettable"] = unsigned(pdr->min_settable.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800902 break;
903 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530904 output["maxSettable"] = unsigned(pdr->max_settable.value_s8);
905 output["minSettable"] = unsigned(pdr->min_settable.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800906 break;
907 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530908 output["maxSettable"] = unsigned(pdr->max_settable.value_u16);
909 output["minSettable"] = unsigned(pdr->min_settable.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800910 break;
911 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530912 output["maxSettable"] = unsigned(pdr->max_settable.value_s16);
913 output["minSettable"] = unsigned(pdr->min_settable.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800914 break;
915 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530916 output["maxSettable"] = unsigned(pdr->max_settable.value_u32);
917 output["minSettable"] = unsigned(pdr->min_settable.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800918 break;
919 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530920 output["maxSettable"] = unsigned(pdr->max_settable.value_s32);
921 output["minSettable"] = unsigned(pdr->min_settable.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800922 break;
923 default:
924 break;
925 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500926
927 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
928 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
929
George Liu62d12ec2020-02-05 16:27:08 +0800930 switch (pdr->range_field_format)
931 {
932 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500933 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
934 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
935 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
936 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
937 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800938 break;
939 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500940 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
941 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
942 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
943 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
944 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800945 break;
946 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500947 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
948 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
949 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
950 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
951 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800952 break;
953 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500954 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
955 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
956 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
957 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
958 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800959 break;
960 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500961 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
962 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
963 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
964 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
965 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800966 break;
967 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500968 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
969 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
970 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
971 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
972 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800973 break;
974 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500975 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
976 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
977 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
978 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
979 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800980 break;
981 default:
982 break;
983 }
984 }
985
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500986 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800987 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530988 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800989
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500990 output["PLDMTerminusHandle"] = pdr->terminus_handle;
991 output["effecterID"] = pdr->effecter_id;
992 output["entityType"] = getEntityName(pdr->entity_type);
993 output["entityInstanceNumber"] = pdr->entity_instance;
994 output["containerID"] = pdr->container_id;
995 output["effecterSemanticID"] = pdr->effecter_semantic_id;
996 output["effecterInit"] = effecterInit[pdr->effecter_init];
Patrick Williams6da4f912023-05-10 07:50:53 -0500997 output["effecterDescriptionPDR"] = (pdr->has_description_pdr ? true
998 : false);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500999 output["compositeEffecterCount"] =
1000 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +08001001
Tom Joseph97a7a762020-07-06 10:37:18 +05301002 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001003 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +05301004
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001005 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +08001006 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301007 auto state =
1008 reinterpret_cast<const state_effecter_possible_states*>(
1009 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001010 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
1011 getStateSetName(state->state_set_id));
1012 output.emplace(
1013 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
1014 state->possible_states_size);
1015 output.emplace(
1016 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05001017 getStateSetPossibleStateNames(
1018 state->state_set_id,
1019 printPossibleStates(state->possible_states_size,
1020 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001021
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001022 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +05301023 {
1024 statesPtr += sizeof(state_effecter_possible_states) +
1025 state->possible_states_size - 1;
1026 }
George Liud6649362019-11-27 19:06:51 +08001027 }
1028 }
1029
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001030 bool checkTerminusHandle(const uint8_t* data,
1031 std::optional<uint16_t> terminusHandle)
1032 {
1033 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1034
1035 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1036 {
1037 auto tlpdr =
1038 reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1039
1040 if (tlpdr->terminus_handle != terminusHandle)
1041 {
1042 return true;
1043 }
1044 }
1045 else if (pdr->type == PLDM_STATE_SENSOR_PDR)
1046 {
1047 auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
1048
1049 if (sensor->terminus_handle != terminusHandle)
1050 {
1051 return true;
1052 }
1053 }
1054 else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR)
1055 {
1056 auto numericEffecter =
1057 reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data);
1058
1059 if (numericEffecter->terminus_handle != terminusHandle)
1060 {
1061 return true;
1062 }
1063 }
1064
1065 else if (pdr->type == PLDM_STATE_EFFECTER_PDR)
1066 {
1067 auto stateEffecter =
1068 reinterpret_cast<const pldm_state_effecter_pdr*>(data);
1069 if (stateEffecter->terminus_handle != terminusHandle)
1070 {
1071 return true;
1072 }
1073 }
1074 else if (pdr->type == PLDM_PDR_FRU_RECORD_SET)
1075 {
1076 data += sizeof(pldm_pdr_hdr);
1077 auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data);
1078
1079 if (fru->terminus_handle != terminusHandle)
1080 {
1081 return true;
1082 }
1083 }
1084 else
1085 {
1086 // Entity association PDRs does not have terminus handle
1087 return true;
1088 }
1089
1090 return false;
1091 }
1092
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001093 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -05001094 {
1095 const std::array<std::string_view, 4> terminusLocatorType = {
1096 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
1097
1098 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1099
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001100 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1101 output["validity"] = (pdr->validity ? "valid" : "notValid");
1102 output["TID"] = unsigned(pdr->tid);
1103 output["containerID"] = pdr->container_id;
1104 output["terminusLocatorType"] =
1105 terminusLocatorType[pdr->terminus_locator_type];
1106 output["terminusLocatorValueSize"] =
1107 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -05001108
1109 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
1110 {
1111 auto locatorValue =
1112 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
1113 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001114 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -05001115 }
1116 }
1117
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001118 std::optional<uint16_t> getTerminusHandle(uint8_t* data,
1119 std::optional<uint8_t> tid)
1120 {
1121 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1122 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1123 {
1124 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1125 if (pdr->tid == tid)
1126 {
1127 handleFound = true;
1128 return pdr->terminus_handle;
1129 }
1130 }
1131 return std::nullopt;
1132 }
1133
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001134 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001135 uint8_t* data, std::optional<uint16_t> terminusHandle)
George Liud6649362019-11-27 19:06:51 +08001136 {
George Liu62d12ec2020-02-05 16:27:08 +08001137 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +08001138 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301139 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +08001140 return;
1141 }
1142
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001143 ordered_json output;
1144 output["nextRecordHandle"] = nextRecordHndl;
1145 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +08001146
1147 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301148 if (!pdr)
1149 {
1150 return;
1151 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001152
1153 if (!pdrRecType.empty())
1154 {
1155 // Need to return if the requested PDR type
1156 // is not supported
1157 if (!strToPdrType.contains(pdrRecType))
1158 {
1159 std::cerr << "PDR type '" << pdrRecType
1160 << "' is not supported or invalid\n";
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -05001161 // PDR type not supported, setting next record handle to
1162 // 0 to avoid looping through all PDR records
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001163 nextRecordHndl = 0;
1164 return;
1165 }
1166
1167 // Do not print PDR record if the current record
1168 // PDR type does not match with requested type
1169 if (pdr->type != strToPdrType.at(pdrRecType))
1170 {
1171 return;
1172 }
1173 }
1174
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001175 if (pdrTerminus.has_value())
1176 {
1177 if (checkTerminusHandle(data, terminusHandle))
1178 {
1179 std::cerr << "The Terminus handle doesn't match return"
1180 << std::endl;
1181 return;
1182 }
1183 }
1184
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001185 printCommonPDRHeader(pdr, output);
1186
George Liud6649362019-11-27 19:06:51 +08001187 switch (pdr->type)
1188 {
Sampa Misra12afe112020-05-25 11:40:44 -05001189 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001190 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001191 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301192 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001193 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301194 break;
George Liu62d12ec2020-02-05 16:27:08 +08001195 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001196 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001197 break;
George Liud6649362019-11-27 19:06:51 +08001198 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001199 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001200 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001201 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001202 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001203 break;
1204 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001205 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001206 break;
George Liud6649362019-11-27 19:06:51 +08001207 default:
1208 break;
1209 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001210 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001211 }
1212
1213 private:
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001214 bool optTIDSet = false;
George Liud6649362019-11-27 19:06:51 +08001215 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001216 bool allPDRs;
1217 std::string pdrRecType;
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001218 std::optional<uint8_t> pdrTerminus;
1219 std::optional<uint16_t> terminusHandle;
1220 bool handleFound = false;
1221 CLI::Option* getPDRGroupOption = nullptr;
George Liud6649362019-11-27 19:06:51 +08001222};
1223
1224class SetStateEffecter : public CommandInterface
1225{
1226 public:
1227 ~SetStateEffecter() = default;
1228 SetStateEffecter() = delete;
1229 SetStateEffecter(const SetStateEffecter&) = delete;
1230 SetStateEffecter(SetStateEffecter&&) = default;
1231 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001232 SetStateEffecter& operator=(SetStateEffecter&&) = delete;
George Liud6649362019-11-27 19:06:51 +08001233
George Liuba4c1fb2020-02-05 14:13:30 +08001234 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1235 static constexpr auto maxEffecterDataSize = 16;
1236
1237 // compositeEffecterCount(value: 0x01 to 0x08)
1238 static constexpr auto minEffecterCount = 1;
1239 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001240 explicit SetStateEffecter(const char* type, const char* name,
1241 CLI::App* app) :
1242 CommandInterface(type, name, app)
1243 {
1244 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001245 "-i, --id", effecterId,
1246 "A handle that is used to identify and access the effecter")
1247 ->required();
1248 app->add_option("-c, --count", effecterCount,
1249 "The number of individual sets of effecter information")
1250 ->required();
1251 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001252 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001253 "Set effecter state data\n"
1254 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1255 ->required();
George Liud6649362019-11-27 19:06:51 +08001256 }
1257
1258 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1259 {
1260 std::vector<uint8_t> requestMsg(
1261 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
1262 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1263
George Liuba4c1fb2020-02-05 14:13:30 +08001264 if (effecterCount > maxEffecterCount ||
1265 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001266 {
George Liuba4c1fb2020-02-05 14:13:30 +08001267 std::cerr << "Request Message Error: effecterCount size "
1268 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001269 auto rc = PLDM_ERROR_INVALID_DATA;
1270 return {rc, requestMsg};
1271 }
1272
George Liuba4c1fb2020-02-05 14:13:30 +08001273 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001274 {
George Liuba4c1fb2020-02-05 14:13:30 +08001275 std::cerr << "Request Message Error: effecterData size "
1276 << effecterData.size() << "is invalid\n";
1277 auto rc = PLDM_ERROR_INVALID_DATA;
1278 return {rc, requestMsg};
1279 }
1280
1281 auto stateField = parseEffecterData(effecterData, effecterCount);
1282 if (!stateField)
1283 {
1284 std::cerr << "Failed to parse effecter data, effecterCount size "
1285 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001286 auto rc = PLDM_ERROR_INVALID_DATA;
1287 return {rc, requestMsg};
1288 }
1289
1290 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001291 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001292 return {rc, requestMsg};
1293 }
1294
1295 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1296 {
1297 uint8_t completionCode = 0;
1298 auto rc = decode_set_state_effecter_states_resp(
1299 responsePtr, payloadLength, &completionCode);
1300
1301 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1302 {
1303 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001304 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001305 return;
1306 }
1307
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001308 ordered_json data;
1309 data["Response"] = "SUCCESS";
1310 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001311 }
1312
1313 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001314 uint16_t effecterId;
1315 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001316 std::vector<uint8_t> effecterData;
1317};
1318
George Liucc9c20d2020-02-05 10:24:11 +08001319class SetNumericEffecterValue : public CommandInterface
1320{
1321 public:
1322 ~SetNumericEffecterValue() = default;
1323 SetNumericEffecterValue() = delete;
1324 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1325 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1326 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001327 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete;
George Liucc9c20d2020-02-05 10:24:11 +08001328
1329 explicit SetNumericEffecterValue(const char* type, const char* name,
1330 CLI::App* app) :
1331 CommandInterface(type, name, app)
1332 {
1333 app->add_option(
1334 "-i, --id", effecterId,
1335 "A handle that is used to identify and access the effecter")
1336 ->required();
1337 app->add_option("-s, --size", effecterDataSize,
1338 "The bit width and format of the setting value for the "
1339 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1340 "uint32, sint32}\n")
1341 ->required();
1342 app->add_option("-d,--data", maxEffecterValue,
1343 "The setting value of numeric effecter being "
1344 "requested\n")
1345 ->required();
1346 }
1347
1348 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1349 {
1350 std::vector<uint8_t> requestMsg(
1351 sizeof(pldm_msg_hdr) +
1352 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1353
1354 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1355
1356 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1357 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1358
1359 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1360 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1361 {
1362 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1363 }
1364 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1365 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1366 {
1367 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1368 }
1369 auto rc = encode_set_numeric_effecter_value_req(
1370 0, effecterId, effecterDataSize, effecterValue, request,
1371 payload_length);
1372
1373 return {rc, requestMsg};
1374 }
1375
1376 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1377 {
1378 uint8_t completionCode = 0;
1379 auto rc = decode_set_numeric_effecter_value_resp(
1380 responsePtr, payloadLength, &completionCode);
1381
1382 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1383 {
1384 std::cerr << "Response Message Error: "
1385 << "rc=" << rc << ",cc=" << (int)completionCode
1386 << std::endl;
1387 return;
1388 }
1389
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001390 ordered_json data;
1391 data["Response"] = "SUCCESS";
1392 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001393 }
1394
1395 private:
1396 uint16_t effecterId;
1397 uint8_t effecterDataSize;
1398 uint64_t maxEffecterValue;
1399};
1400
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001401class GetStateSensorReadings : public CommandInterface
1402{
1403 public:
1404 ~GetStateSensorReadings() = default;
1405 GetStateSensorReadings() = delete;
1406 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1407 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1408 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001409 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001410
1411 explicit GetStateSensorReadings(const char* type, const char* name,
1412 CLI::App* app) :
1413 CommandInterface(type, name, app)
1414 {
1415 app->add_option(
1416 "-i, --sensor_id", sensorId,
1417 "Sensor ID that is used to identify and access the sensor")
1418 ->required();
1419 app->add_option("-r, --rearm", sensorRearm,
1420 "Each bit location in this field corresponds to a "
1421 "particular sensor")
1422 ->required();
1423 }
1424
1425 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1426 {
1427 std::vector<uint8_t> requestMsg(
1428 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
1429 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1430
1431 uint8_t reserved = 0;
1432 bitfield8_t bf;
1433 bf.byte = sensorRearm;
1434 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1435 reserved, request);
1436
1437 return {rc, requestMsg};
1438 }
1439
1440 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1441 {
1442 uint8_t completionCode = 0;
1443 uint8_t compSensorCount = 0;
1444 std::array<get_sensor_state_field, 8> stateField{};
1445 auto rc = decode_get_state_sensor_readings_resp(
1446 responsePtr, payloadLength, &completionCode, &compSensorCount,
1447 stateField.data());
1448
1449 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1450 {
1451 std::cerr << "Response Message Error: "
1452 << "rc=" << rc << ",cc=" << (int)completionCode
1453 << std::endl;
1454 return;
1455 }
1456 ordered_json output;
1457 output["compositeSensorCount"] = (int)compSensorCount;
1458
1459 for (size_t i = 0; i < compSensorCount; i++)
1460 {
George Liubd5e2ea2021-04-22 20:33:06 +08001461 if (sensorOpState.contains(stateField[i].sensor_op_state))
1462 {
1463 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1464 sensorOpState.at(stateField[i].sensor_op_state));
1465 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001466
George Liubd5e2ea2021-04-22 20:33:06 +08001467 if (sensorPresState.contains(stateField[i].present_state))
1468 {
1469 output.emplace(("presentState[" + std::to_string(i) + "]"),
1470 sensorPresState.at(stateField[i].present_state));
1471 }
1472
1473 if (sensorPresState.contains(stateField[i].previous_state))
1474 {
1475 output.emplace(
1476 ("previousState[" + std::to_string(i) + "]"),
1477 sensorPresState.at(stateField[i].previous_state));
1478 }
1479
1480 if (sensorPresState.contains(stateField[i].event_state))
1481 {
1482 output.emplace(("eventState[" + std::to_string(i) + "]"),
1483 sensorPresState.at(stateField[i].event_state));
1484 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001485 }
1486
1487 pldmtool::helper::DisplayInJson(output);
1488 }
1489
1490 private:
1491 uint16_t sensorId;
1492 uint8_t sensorRearm;
1493};
1494
George Liud6649362019-11-27 19:06:51 +08001495void registerCommand(CLI::App& app)
1496{
1497 auto platform = app.add_subcommand("platform", "platform type command");
1498 platform->require_subcommand(1);
1499
Patrick Williams6da4f912023-05-10 07:50:53 -05001500 auto getPDR = platform->add_subcommand("GetPDR",
1501 "get platform descriptor records");
George Liud6649362019-11-27 19:06:51 +08001502 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
1503
1504 auto setStateEffecterStates = platform->add_subcommand(
1505 "SetStateEffecterStates", "set effecter states");
1506 commands.push_back(std::make_unique<SetStateEffecter>(
1507 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08001508
1509 auto setNumericEffecterValue = platform->add_subcommand(
1510 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
1511 commands.push_back(std::make_unique<SetNumericEffecterValue>(
1512 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001513
1514 auto getStateSensorReadings = platform->add_subcommand(
1515 "GetStateSensorReadings", "get the state sensor readings");
1516 commands.push_back(std::make_unique<GetStateSensorReadings>(
1517 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +08001518}
1519
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001520void parseGetPDROption()
1521{
1522 for (const auto& command : commands)
1523 {
1524 if (command.get()->getPLDMType() == "platform" &&
1525 command.get()->getCommandName() == "getPDR")
1526 {
1527 auto getPDR = dynamic_cast<GetPDR*>(command.get());
1528 getPDR->parseGetPDROptions();
1529 }
1530 }
1531}
1532
George Liud6649362019-11-27 19:06:51 +08001533} // namespace platform
1534} // namespace pldmtool