blob: d8b1b15bbac97af622b63508f70fb58c665b5e7e [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{
532 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
533 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED, "Stressed"}};
534
535 static inline const std::map<uint8_t, std::string> setSysPowerState{
536 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
537 "Off-Soft Graceful"}};
538
539 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
540 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
541 "Graceful Restart Requested"}};
542
543 static inline const std::map<uint8_t, std::string> setAvailability{
544 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
545
546 static inline const std::map<uint8_t, std::string> setHealthState{
547 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530548 {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"},
549 {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"},
550 {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"},
551 {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"},
552 {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500553 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530554 {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"},
555 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"},
556 {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}};
557
558 static inline const std::map<uint8_t, std::string>
559 setOperationalRunningState{
560 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"},
561 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"},
562 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"},
563 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE,
564 "In Service"},
565 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"},
566 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500567
568 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
569 populatePStateMaps{
570 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
571 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
572 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
573 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
574 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
575 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
576 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
577 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530578 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
579 setOperationalRunningState},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500580 };
581
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500582 const std::map<std::string, uint8_t> strToPdrType = {
583 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
584 {"statesensor", PLDM_STATE_SENSOR_PDR},
585 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
586 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
587 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
588 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
589 // Add other types
590 };
591
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530592 bool isLogicalBitSet(const uint16_t entity_type)
593 {
594 return entity_type & 0x8000;
595 }
596
597 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
598 {
599 return logical_entity_type & 0x7FFF;
600 }
601
Tom Josepha65c0412020-07-03 21:14:44 +0530602 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500603 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530604 uint16_t entityNumber = type;
605 std::string entityName = "[Physical] ";
606
607 if (isLogicalBitSet(type))
608 {
609 entityName = "[Logical] ";
610 entityNumber = getEntityTypeForLogicalEntity(type);
611 }
612
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500613 try
614 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530615 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500616 }
617 catch (const std::out_of_range& e)
618 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500619 auto OemString =
620 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530621 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
622 type <= PLDM_OEM_ENTITY_TYPE_END)
623 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500624#ifdef OEM_IBM
625 if (OemIBMEntityType.contains(entityNumber))
626 {
627 return entityName + OemIBMEntityType.at(entityNumber) +
628 "(OEM)";
629 }
630#endif
631 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530632 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500633 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500634 }
635 }
636
Tom Josepha65c0412020-07-03 21:14:44 +0530637 std::string getStateSetName(uint16_t id)
638 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500639 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530640 try
641 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500642 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530643 }
644 catch (const std::out_of_range& e)
645 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500646 return typeString;
647 }
648 }
649
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500650 std::vector<std::string>
651 getStateSetPossibleStateNames(uint16_t stateId,
652 const std::vector<uint8_t>& value)
653 {
654 std::vector<std::string> data{};
655 std::map<uint8_t, std::string> stateNameMaps;
656
657 for (auto& s : value)
658 {
659 std::map<uint8_t, std::string> stateNameMaps;
660 auto pstr = std::to_string(s);
661
662#ifdef OEM_IBM
Manojkiran Edabe1a8572022-01-06 11:20:36 +0530663 if (stateId >= PLDM_OEM_STATE_SET_ID_START &&
664 stateId < PLDM_OEM_STATE_SET_ID_END)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500665 {
666 if (populateOemIBMStateMaps.contains(stateId))
667 {
668 const std::map<uint8_t, std::string> stateNames =
669 populateOemIBMStateMaps.at(stateId);
670 stateNameMaps.insert(stateNames.begin(), stateNames.end());
671 }
672 }
673#endif
674 if (populatePStateMaps.contains(stateId))
675 {
676 const std::map<uint8_t, std::string> stateNames =
677 populatePStateMaps.at(stateId);
678 stateNameMaps.insert(stateNames.begin(), stateNames.end());
679 }
680 if (stateNameMaps.contains(s))
681 {
682 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
683 }
684 else
685 {
686 data.push_back(pstr);
687 }
688 }
689 return data;
690 }
691
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500692 std::string getPDRType(uint8_t type)
693 {
694 auto typeString = std::to_string(type);
695 try
696 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500697 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500698 }
699 catch (const std::out_of_range& e)
700 {
701 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530702 }
703 }
704
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500705 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530706 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500707 output["recordHandle"] = hdr->record_handle;
708 output["PDRHeaderVersion"] = unsigned(hdr->version);
709 output["PDRType"] = getPDRType(hdr->type);
710 output["recordChangeNumber"] = hdr->record_change_num;
711 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530712 }
713
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500714 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
715 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530716 {
717 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500718 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500719 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
720 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530721 for (int i = 0; i < CHAR_BIT; i++)
722 {
723 if (val.byte & (1 << i))
724 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500725 pstates << (possibleStatesPos * CHAR_BIT + i);
726 data.push_back(
727 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600728 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530729 }
730 }
731 possibleStatesPos++;
732 };
733 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500734 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530735 }
736
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500737 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530738 {
739 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500740 output["PLDMTerminusHandle"] = pdr->terminus_handle;
741 output["sensorID"] = pdr->sensor_id;
742 output["entityType"] = getEntityName(pdr->entity_type);
743 output["entityInstanceNumber"] = pdr->entity_instance;
744 output["containerID"] = pdr->container_id;
745 output["sensorInit"] = sensorInit[pdr->sensor_init];
746 output["sensorAuxiliaryNamesPDR"] =
747 (pdr->sensor_auxiliary_names_pdr ? true : false);
748 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530749
750 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600751 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530752
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600753 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530754 {
755 auto state = reinterpret_cast<const state_sensor_possible_states*>(
756 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600757 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
758 getStateSetName(state->state_set_id));
759 output.emplace(
760 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
761 state->possible_states_size);
762 output.emplace(
763 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500764 getStateSetPossibleStateNames(
765 state->state_set_id,
766 printPossibleStates(state->possible_states_size,
767 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530768
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600769 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530770 {
771 statesPtr += sizeof(state_sensor_possible_states) +
772 state->possible_states_size - 1;
773 }
774 }
775 }
776
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500777 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500778 {
George Liu62d12ec2020-02-05 16:27:08 +0800779 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500780 {
781 return;
782 }
783
784 data += sizeof(pldm_pdr_hdr);
785 pldm_pdr_fru_record_set* pdr =
786 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530787 if (!pdr)
788 {
789 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
790 return;
791 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500792
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500793 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
794 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
795 output["entityType"] = getEntityName(pdr->entity_type);
796 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
797 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500798 }
799
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500800 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500801 {
802 const std::map<uint8_t, const char*> assocationType = {
803 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
804 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
805 };
806
George Liu62d12ec2020-02-05 16:27:08 +0800807 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500808 {
809 return;
810 }
811
812 data += sizeof(pldm_pdr_hdr);
813 pldm_pdr_entity_association* pdr =
814 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530815 if (!pdr)
816 {
817 std::cerr << "Failed to get the PDR eneity association"
818 << std::endl;
819 return;
820 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500821
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500822 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800823 if (assocationType.contains(pdr->association_type))
824 {
825 output["associationType"] =
826 assocationType.at(pdr->association_type);
827 }
828 else
829 {
830 std::cout << "Get associationType failed.\n";
831 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500832 output["containerEntityType"] =
833 getEntityName(pdr->container.entity_type);
834 output["containerEntityInstanceNumber"] =
835 int(pdr->container.entity_instance_num);
836 output["containerEntityContainerID"] =
837 int(pdr->container.entity_container_id);
838 output["containedEntityCount"] =
839 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500840
841 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
842 for (int i = 0; i < pdr->num_children; ++i)
843 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500844 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
845 getEntityName(child->entity_type));
846 output.emplace("containedEntityInstanceNumber[" +
847 std::to_string(i + 1) + "]",
848 unsigned(child->entity_instance_num));
849 output.emplace("containedEntityContainerID[" +
850 std::to_string(i + 1) + "]",
851 unsigned(child->entity_container_id));
852
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500853 ++child;
854 }
855 }
856
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500857 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800858 {
859 struct pldm_numeric_effecter_value_pdr* pdr =
860 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530861 if (!pdr)
862 {
863 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
864 return;
865 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500866
867 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
868 output["effecterID"] = int(pdr->effecter_id);
869 output["entityType"] = int(pdr->entity_type);
870 output["entityInstanceNumber"] = int(pdr->entity_instance);
871 output["containerID"] = int(pdr->container_id);
872 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
873 output["effecterInit"] = unsigned(pdr->effecter_init);
874 output["effecterAuxiliaryNames"] =
875 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
876 output["baseUnit"] = unsigned(pdr->base_unit);
877 output["unitModifier"] = unsigned(pdr->unit_modifier);
878 output["rateUnit"] = unsigned(pdr->rate_unit);
879 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
880 output["auxUnit"] = unsigned(pdr->aux_unit);
881 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
882 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
883 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
884 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
885 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
886 output["resolution"] = unsigned(pdr->resolution);
887 output["offset"] = unsigned(pdr->offset);
888 output["accuracy"] = unsigned(pdr->accuracy);
889 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
890 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
891 output["stateTransitionInterval"] =
892 unsigned(pdr->state_transition_interval);
893 output["TransitionInterval"] = unsigned(pdr->transition_interval);
894
George Liu62d12ec2020-02-05 16:27:08 +0800895 switch (pdr->effecter_data_size)
896 {
897 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530898 output["maxSettable"] = unsigned(pdr->max_settable.value_u8);
899 output["minSettable"] = unsigned(pdr->min_settable.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800900 break;
901 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530902 output["maxSettable"] = unsigned(pdr->max_settable.value_s8);
903 output["minSettable"] = unsigned(pdr->min_settable.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800904 break;
905 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530906 output["maxSettable"] = unsigned(pdr->max_settable.value_u16);
907 output["minSettable"] = unsigned(pdr->min_settable.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800908 break;
909 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530910 output["maxSettable"] = unsigned(pdr->max_settable.value_s16);
911 output["minSettable"] = unsigned(pdr->min_settable.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800912 break;
913 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530914 output["maxSettable"] = unsigned(pdr->max_settable.value_u32);
915 output["minSettable"] = unsigned(pdr->min_settable.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800916 break;
917 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +0530918 output["maxSettable"] = unsigned(pdr->max_settable.value_s32);
919 output["minSettable"] = unsigned(pdr->min_settable.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800920 break;
921 default:
922 break;
923 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500924
925 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
926 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
927
George Liu62d12ec2020-02-05 16:27:08 +0800928 switch (pdr->range_field_format)
929 {
930 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500931 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
932 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
933 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
934 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
935 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800936 break;
937 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500938 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
939 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
940 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
941 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
942 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800943 break;
944 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500945 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
946 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
947 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
948 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
949 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800950 break;
951 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500952 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
953 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
954 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
955 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
956 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800957 break;
958 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500959 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
960 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
961 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
962 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
963 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800964 break;
965 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500966 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
967 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
968 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
969 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
970 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800971 break;
972 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500973 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
974 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
975 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
976 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
977 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800978 break;
979 default:
980 break;
981 }
982 }
983
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500984 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800985 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530986 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800987
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500988 output["PLDMTerminusHandle"] = pdr->terminus_handle;
989 output["effecterID"] = pdr->effecter_id;
990 output["entityType"] = getEntityName(pdr->entity_type);
991 output["entityInstanceNumber"] = pdr->entity_instance;
992 output["containerID"] = pdr->container_id;
993 output["effecterSemanticID"] = pdr->effecter_semantic_id;
994 output["effecterInit"] = effecterInit[pdr->effecter_init];
Patrick Williams6da4f912023-05-10 07:50:53 -0500995 output["effecterDescriptionPDR"] = (pdr->has_description_pdr ? true
996 : false);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500997 output["compositeEffecterCount"] =
998 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +0800999
Tom Joseph97a7a762020-07-06 10:37:18 +05301000 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001001 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +05301002
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001003 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +08001004 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301005 auto state =
1006 reinterpret_cast<const state_effecter_possible_states*>(
1007 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001008 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
1009 getStateSetName(state->state_set_id));
1010 output.emplace(
1011 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
1012 state->possible_states_size);
1013 output.emplace(
1014 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05001015 getStateSetPossibleStateNames(
1016 state->state_set_id,
1017 printPossibleStates(state->possible_states_size,
1018 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001019
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001020 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +05301021 {
1022 statesPtr += sizeof(state_effecter_possible_states) +
1023 state->possible_states_size - 1;
1024 }
George Liud6649362019-11-27 19:06:51 +08001025 }
1026 }
1027
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001028 bool checkTerminusHandle(const uint8_t* data,
1029 std::optional<uint16_t> terminusHandle)
1030 {
1031 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1032
1033 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1034 {
1035 auto tlpdr =
1036 reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1037
1038 if (tlpdr->terminus_handle != terminusHandle)
1039 {
1040 return true;
1041 }
1042 }
1043 else if (pdr->type == PLDM_STATE_SENSOR_PDR)
1044 {
1045 auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
1046
1047 if (sensor->terminus_handle != terminusHandle)
1048 {
1049 return true;
1050 }
1051 }
1052 else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR)
1053 {
1054 auto numericEffecter =
1055 reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data);
1056
1057 if (numericEffecter->terminus_handle != terminusHandle)
1058 {
1059 return true;
1060 }
1061 }
1062
1063 else if (pdr->type == PLDM_STATE_EFFECTER_PDR)
1064 {
1065 auto stateEffecter =
1066 reinterpret_cast<const pldm_state_effecter_pdr*>(data);
1067 if (stateEffecter->terminus_handle != terminusHandle)
1068 {
1069 return true;
1070 }
1071 }
1072 else if (pdr->type == PLDM_PDR_FRU_RECORD_SET)
1073 {
1074 data += sizeof(pldm_pdr_hdr);
1075 auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data);
1076
1077 if (fru->terminus_handle != terminusHandle)
1078 {
1079 return true;
1080 }
1081 }
1082 else
1083 {
1084 // Entity association PDRs does not have terminus handle
1085 return true;
1086 }
1087
1088 return false;
1089 }
1090
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001091 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -05001092 {
1093 const std::array<std::string_view, 4> terminusLocatorType = {
1094 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
1095
1096 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1097
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001098 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1099 output["validity"] = (pdr->validity ? "valid" : "notValid");
1100 output["TID"] = unsigned(pdr->tid);
1101 output["containerID"] = pdr->container_id;
1102 output["terminusLocatorType"] =
1103 terminusLocatorType[pdr->terminus_locator_type];
1104 output["terminusLocatorValueSize"] =
1105 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -05001106
1107 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
1108 {
1109 auto locatorValue =
1110 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
1111 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001112 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -05001113 }
1114 }
1115
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001116 std::optional<uint16_t> getTerminusHandle(uint8_t* data,
1117 std::optional<uint8_t> tid)
1118 {
1119 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1120 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1121 {
1122 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1123 if (pdr->tid == tid)
1124 {
1125 handleFound = true;
1126 return pdr->terminus_handle;
1127 }
1128 }
1129 return std::nullopt;
1130 }
1131
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001132 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001133 uint8_t* data, std::optional<uint16_t> terminusHandle)
George Liud6649362019-11-27 19:06:51 +08001134 {
George Liu62d12ec2020-02-05 16:27:08 +08001135 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +08001136 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301137 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +08001138 return;
1139 }
1140
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001141 ordered_json output;
1142 output["nextRecordHandle"] = nextRecordHndl;
1143 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +08001144
1145 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301146 if (!pdr)
1147 {
1148 return;
1149 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001150
1151 if (!pdrRecType.empty())
1152 {
1153 // Need to return if the requested PDR type
1154 // is not supported
1155 if (!strToPdrType.contains(pdrRecType))
1156 {
1157 std::cerr << "PDR type '" << pdrRecType
1158 << "' is not supported or invalid\n";
1159 // PDR type not supported, setting next record handle to 0
1160 // to avoid looping through all PDR records
1161 nextRecordHndl = 0;
1162 return;
1163 }
1164
1165 // Do not print PDR record if the current record
1166 // PDR type does not match with requested type
1167 if (pdr->type != strToPdrType.at(pdrRecType))
1168 {
1169 return;
1170 }
1171 }
1172
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001173 if (pdrTerminus.has_value())
1174 {
1175 if (checkTerminusHandle(data, terminusHandle))
1176 {
1177 std::cerr << "The Terminus handle doesn't match return"
1178 << std::endl;
1179 return;
1180 }
1181 }
1182
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001183 printCommonPDRHeader(pdr, output);
1184
George Liud6649362019-11-27 19:06:51 +08001185 switch (pdr->type)
1186 {
Sampa Misra12afe112020-05-25 11:40:44 -05001187 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001188 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001189 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301190 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001191 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301192 break;
George Liu62d12ec2020-02-05 16:27:08 +08001193 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001194 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001195 break;
George Liud6649362019-11-27 19:06:51 +08001196 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001197 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001198 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001199 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001200 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001201 break;
1202 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001203 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001204 break;
George Liud6649362019-11-27 19:06:51 +08001205 default:
1206 break;
1207 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001208 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001209 }
1210
1211 private:
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001212 bool optTIDSet = false;
George Liud6649362019-11-27 19:06:51 +08001213 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001214 bool allPDRs;
1215 std::string pdrRecType;
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001216 std::optional<uint8_t> pdrTerminus;
1217 std::optional<uint16_t> terminusHandle;
1218 bool handleFound = false;
1219 CLI::Option* getPDRGroupOption = nullptr;
George Liud6649362019-11-27 19:06:51 +08001220};
1221
1222class SetStateEffecter : public CommandInterface
1223{
1224 public:
1225 ~SetStateEffecter() = default;
1226 SetStateEffecter() = delete;
1227 SetStateEffecter(const SetStateEffecter&) = delete;
1228 SetStateEffecter(SetStateEffecter&&) = default;
1229 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001230 SetStateEffecter& operator=(SetStateEffecter&&) = delete;
George Liud6649362019-11-27 19:06:51 +08001231
George Liuba4c1fb2020-02-05 14:13:30 +08001232 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1233 static constexpr auto maxEffecterDataSize = 16;
1234
1235 // compositeEffecterCount(value: 0x01 to 0x08)
1236 static constexpr auto minEffecterCount = 1;
1237 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001238 explicit SetStateEffecter(const char* type, const char* name,
1239 CLI::App* app) :
1240 CommandInterface(type, name, app)
1241 {
1242 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001243 "-i, --id", effecterId,
1244 "A handle that is used to identify and access the effecter")
1245 ->required();
1246 app->add_option("-c, --count", effecterCount,
1247 "The number of individual sets of effecter information")
1248 ->required();
1249 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001250 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001251 "Set effecter state data\n"
1252 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1253 ->required();
George Liud6649362019-11-27 19:06:51 +08001254 }
1255
1256 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1257 {
1258 std::vector<uint8_t> requestMsg(
1259 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
1260 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1261
George Liuba4c1fb2020-02-05 14:13:30 +08001262 if (effecterCount > maxEffecterCount ||
1263 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001264 {
George Liuba4c1fb2020-02-05 14:13:30 +08001265 std::cerr << "Request Message Error: effecterCount size "
1266 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001267 auto rc = PLDM_ERROR_INVALID_DATA;
1268 return {rc, requestMsg};
1269 }
1270
George Liuba4c1fb2020-02-05 14:13:30 +08001271 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001272 {
George Liuba4c1fb2020-02-05 14:13:30 +08001273 std::cerr << "Request Message Error: effecterData size "
1274 << effecterData.size() << "is invalid\n";
1275 auto rc = PLDM_ERROR_INVALID_DATA;
1276 return {rc, requestMsg};
1277 }
1278
1279 auto stateField = parseEffecterData(effecterData, effecterCount);
1280 if (!stateField)
1281 {
1282 std::cerr << "Failed to parse effecter data, effecterCount size "
1283 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001284 auto rc = PLDM_ERROR_INVALID_DATA;
1285 return {rc, requestMsg};
1286 }
1287
1288 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001289 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001290 return {rc, requestMsg};
1291 }
1292
1293 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1294 {
1295 uint8_t completionCode = 0;
1296 auto rc = decode_set_state_effecter_states_resp(
1297 responsePtr, payloadLength, &completionCode);
1298
1299 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1300 {
1301 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001302 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001303 return;
1304 }
1305
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001306 ordered_json data;
1307 data["Response"] = "SUCCESS";
1308 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001309 }
1310
1311 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001312 uint16_t effecterId;
1313 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001314 std::vector<uint8_t> effecterData;
1315};
1316
George Liucc9c20d2020-02-05 10:24:11 +08001317class SetNumericEffecterValue : public CommandInterface
1318{
1319 public:
1320 ~SetNumericEffecterValue() = default;
1321 SetNumericEffecterValue() = delete;
1322 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1323 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1324 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001325 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete;
George Liucc9c20d2020-02-05 10:24:11 +08001326
1327 explicit SetNumericEffecterValue(const char* type, const char* name,
1328 CLI::App* app) :
1329 CommandInterface(type, name, app)
1330 {
1331 app->add_option(
1332 "-i, --id", effecterId,
1333 "A handle that is used to identify and access the effecter")
1334 ->required();
1335 app->add_option("-s, --size", effecterDataSize,
1336 "The bit width and format of the setting value for the "
1337 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1338 "uint32, sint32}\n")
1339 ->required();
1340 app->add_option("-d,--data", maxEffecterValue,
1341 "The setting value of numeric effecter being "
1342 "requested\n")
1343 ->required();
1344 }
1345
1346 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1347 {
1348 std::vector<uint8_t> requestMsg(
1349 sizeof(pldm_msg_hdr) +
1350 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1351
1352 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1353
1354 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1355 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1356
1357 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1358 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1359 {
1360 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1361 }
1362 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1363 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1364 {
1365 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1366 }
1367 auto rc = encode_set_numeric_effecter_value_req(
1368 0, effecterId, effecterDataSize, effecterValue, request,
1369 payload_length);
1370
1371 return {rc, requestMsg};
1372 }
1373
1374 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1375 {
1376 uint8_t completionCode = 0;
1377 auto rc = decode_set_numeric_effecter_value_resp(
1378 responsePtr, payloadLength, &completionCode);
1379
1380 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1381 {
1382 std::cerr << "Response Message Error: "
1383 << "rc=" << rc << ",cc=" << (int)completionCode
1384 << std::endl;
1385 return;
1386 }
1387
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001388 ordered_json data;
1389 data["Response"] = "SUCCESS";
1390 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001391 }
1392
1393 private:
1394 uint16_t effecterId;
1395 uint8_t effecterDataSize;
1396 uint64_t maxEffecterValue;
1397};
1398
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001399class GetStateSensorReadings : public CommandInterface
1400{
1401 public:
1402 ~GetStateSensorReadings() = default;
1403 GetStateSensorReadings() = delete;
1404 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1405 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1406 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001407 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001408
1409 explicit GetStateSensorReadings(const char* type, const char* name,
1410 CLI::App* app) :
1411 CommandInterface(type, name, app)
1412 {
1413 app->add_option(
1414 "-i, --sensor_id", sensorId,
1415 "Sensor ID that is used to identify and access the sensor")
1416 ->required();
1417 app->add_option("-r, --rearm", sensorRearm,
1418 "Each bit location in this field corresponds to a "
1419 "particular sensor")
1420 ->required();
1421 }
1422
1423 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1424 {
1425 std::vector<uint8_t> requestMsg(
1426 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
1427 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1428
1429 uint8_t reserved = 0;
1430 bitfield8_t bf;
1431 bf.byte = sensorRearm;
1432 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1433 reserved, request);
1434
1435 return {rc, requestMsg};
1436 }
1437
1438 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1439 {
1440 uint8_t completionCode = 0;
1441 uint8_t compSensorCount = 0;
1442 std::array<get_sensor_state_field, 8> stateField{};
1443 auto rc = decode_get_state_sensor_readings_resp(
1444 responsePtr, payloadLength, &completionCode, &compSensorCount,
1445 stateField.data());
1446
1447 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1448 {
1449 std::cerr << "Response Message Error: "
1450 << "rc=" << rc << ",cc=" << (int)completionCode
1451 << std::endl;
1452 return;
1453 }
1454 ordered_json output;
1455 output["compositeSensorCount"] = (int)compSensorCount;
1456
1457 for (size_t i = 0; i < compSensorCount; i++)
1458 {
George Liubd5e2ea2021-04-22 20:33:06 +08001459 if (sensorOpState.contains(stateField[i].sensor_op_state))
1460 {
1461 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1462 sensorOpState.at(stateField[i].sensor_op_state));
1463 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001464
George Liubd5e2ea2021-04-22 20:33:06 +08001465 if (sensorPresState.contains(stateField[i].present_state))
1466 {
1467 output.emplace(("presentState[" + std::to_string(i) + "]"),
1468 sensorPresState.at(stateField[i].present_state));
1469 }
1470
1471 if (sensorPresState.contains(stateField[i].previous_state))
1472 {
1473 output.emplace(
1474 ("previousState[" + std::to_string(i) + "]"),
1475 sensorPresState.at(stateField[i].previous_state));
1476 }
1477
1478 if (sensorPresState.contains(stateField[i].event_state))
1479 {
1480 output.emplace(("eventState[" + std::to_string(i) + "]"),
1481 sensorPresState.at(stateField[i].event_state));
1482 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001483 }
1484
1485 pldmtool::helper::DisplayInJson(output);
1486 }
1487
1488 private:
1489 uint16_t sensorId;
1490 uint8_t sensorRearm;
1491};
1492
George Liud6649362019-11-27 19:06:51 +08001493void registerCommand(CLI::App& app)
1494{
1495 auto platform = app.add_subcommand("platform", "platform type command");
1496 platform->require_subcommand(1);
1497
Patrick Williams6da4f912023-05-10 07:50:53 -05001498 auto getPDR = platform->add_subcommand("GetPDR",
1499 "get platform descriptor records");
George Liud6649362019-11-27 19:06:51 +08001500 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
1501
1502 auto setStateEffecterStates = platform->add_subcommand(
1503 "SetStateEffecterStates", "set effecter states");
1504 commands.push_back(std::make_unique<SetStateEffecter>(
1505 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08001506
1507 auto setNumericEffecterValue = platform->add_subcommand(
1508 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
1509 commands.push_back(std::make_unique<SetNumericEffecterValue>(
1510 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001511
1512 auto getStateSensorReadings = platform->add_subcommand(
1513 "GetStateSensorReadings", "get the state sensor readings");
1514 commands.push_back(std::make_unique<GetStateSensorReadings>(
1515 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +08001516}
1517
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001518void parseGetPDROption()
1519{
1520 for (const auto& command : commands)
1521 {
1522 if (command.get()->getPLDMType() == "platform" &&
1523 command.get()->getCommandName() == "getPDR")
1524 {
1525 auto getPDR = dynamic_cast<GetPDR*>(command.get());
1526 getPDR->parseGetPDROptions();
1527 }
1528 }
1529}
1530
George Liud6649362019-11-27 19:06:51 +08001531} // namespace platform
1532} // namespace pldmtool