blob: 1203e91334df29ed556874e69a0bf1632bf49894 [file] [log] [blame]
Tom Josepha65c0412020-07-03 21:14:44 +05301#include "libpldm/entity.h"
2#include "libpldm/state_set.h"
3
4#include "common/types.hpp"
George Liud6649362019-11-27 19:06:51 +08005#include "pldm_cmd_helper.hpp"
6
George Liud6649362019-11-27 19:06:51 +08007namespace pldmtool
8{
9
10namespace platform
11{
12
13namespace
14{
15
16using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060017
18static const std::map<uint8_t, std::string> sensorPresState{
19 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
20 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
21 {PLDM_SENSOR_WARNING, "Sensor Warning"},
22 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
23 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
24 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
25 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
26 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
27 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
28 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
29 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
30
31static const std::map<uint8_t, std::string> sensorOpState{
32 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
33 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
34 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
35 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
36 {PLDM_SENSOR_FAILED, "Sensor Failed"},
37 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Intializing"},
38 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
39 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
40
George Liud6649362019-11-27 19:06:51 +080041std::vector<std::unique_ptr<CommandInterface>> commands;
42
43} // namespace
44
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050045using ordered_json = nlohmann::ordered_json;
46
George Liud6649362019-11-27 19:06:51 +080047class GetPDR : public CommandInterface
48{
49 public:
50 ~GetPDR() = default;
51 GetPDR() = delete;
52 GetPDR(const GetPDR&) = delete;
53 GetPDR(GetPDR&&) = default;
54 GetPDR& operator=(const GetPDR&) = delete;
55 GetPDR& operator=(GetPDR&&) = default;
56
57 using CommandInterface::CommandInterface;
58
George Liud6649362019-11-27 19:06:51 +080059 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
60 CommandInterface(type, name, app)
61 {
62 app->add_option(
63 "-d,--data", recordHandle,
64 "retrieve individual PDRs from a PDR Repository\n"
65 "eg: The recordHandle value for the PDR to be retrieved and 0 "
66 "means get first PDR in the repository.")
67 ->required();
68 }
69
70 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
71 {
72 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
73 PLDM_GET_PDR_REQ_BYTES);
74 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
75
Deepak Kodihallia59cdc62020-07-14 05:11:33 -050076 auto rc =
77 encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
78 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +080079 return {rc, requestMsg};
80 }
81
82 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
83 {
84 uint8_t completionCode = 0;
Deepak Kodihallia59cdc62020-07-14 05:11:33 -050085 uint8_t recordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +080086 uint32_t nextRecordHndl = 0;
87 uint32_t nextDataTransferHndl = 0;
88 uint8_t transferFlag = 0;
89 uint16_t respCnt = 0;
90 uint8_t transferCRC = 0;
91
92 auto rc = decode_get_pdr_resp(
93 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
94 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
95 sizeof(recordData), &transferCRC);
96
97 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
98 {
99 std::cerr << "Response Message Error: "
100 << "rc=" << rc << ",cc=" << (int)completionCode
101 << std::endl;
102 return;
103 }
104
George Liu62d12ec2020-02-05 16:27:08 +0800105 printPDRMsg(nextRecordHndl, respCnt, recordData);
George Liud6649362019-11-27 19:06:51 +0800106 }
107
108 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530109 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530110 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
111 {PLDM_ENTITY_OTHER, "Other"},
112 {PLDM_ENTITY_NETWORK, "Network"},
113 {PLDM_ENTITY_GROUP, "Group"},
114 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
115 "Remote Management Communication Device"},
116 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
117 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
118 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
119 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
120 {PLDM_ENTITY_KEYPAD, "keypad"},
121 {PLDM_ENTITY_SWITCH, "Switch"},
122 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
123 {PLDM_ENTITY_DISPLAY, "Display"},
124 {PLDM_ENTITY_INDICATOR, "Indicator"},
125 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530126 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530127 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530128 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530129 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
130 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
131 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530132 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530133 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
134 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
135 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
136 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
137 {PLDM_ENTITY_DOOR, "Door"},
138 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
139 {PLDM_ENTITY_COVER, "Cover"},
140 {PLDM_ENTITY_BOARD, "Board"},
141 {PLDM_ENTITY_CARD, "Card"},
142 {PLDM_ENTITY_MODULE, "Module"},
143 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530144 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530145 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530146 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
147 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530148 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530149 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530150 "Chassis front panel board(control panel)"},
151 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
152 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
153 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
154 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
155 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
156 "System internal expansion board"},
157 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
158 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
159 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
160 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
161 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
162 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
163 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
164 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
165 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
166 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500167 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530168 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
169 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
170 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
171 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
172 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
173 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
174 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
175 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
176 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
177 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500178 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530179 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
180 {PLDM_ENTITY_BATTERY, "Battery"},
181 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
182 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
183 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
184 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
185 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
186 {PLDM_ENTITY_PROC, "Processor"},
187 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
188 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
189 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
190 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
191 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
192 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
193 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
194 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
195 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
196 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
197 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500198 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530199 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
200 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
201 {PLDM_ENTITY_SYS_BUS, "System Bus"},
202 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
203 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
204 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
205 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
206 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
207 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
208 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
209 {PLDM_ENTITY_USB_BUS, "USB Bus"},
210 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
211 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
212 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
213 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
214 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
215 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500216 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530217 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
218 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
219 {PLDM_ENTITY_PLUG, "Plug"},
220 {PLDM_ENTITY_SOCKET, "Socket"},
221 {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"}};
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500222
Tom Josepha65c0412020-07-03 21:14:44 +0530223 const std::map<uint16_t, std::string> stateSet = {
224 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
225 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530226 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
227 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
228 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
229 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
230 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530231 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530232 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
233 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530234 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
235 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530236 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
237 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530238 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530239 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530240 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530241 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
242 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
243 {PLDM_STATE_SET_VERSION, "Version"},
244 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
245 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
246 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
247 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530248 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530249 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
250 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
251 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
252 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
253 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
254 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
255 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
256 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
257 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
258 "Physical Communication Connection"},
259 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
260 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
261 "Foreign Network Detection Status"},
262 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
263 "Password-Protected Access Security"},
264 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
265 "Security Access –PrivilegeLevel"},
266 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530267 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530268 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530269 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530270 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
271 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
272 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530273 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530274 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
275 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
276 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
277 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
278 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
279 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
280 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
281 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
282 "Diagnostic Interrupt Requested"},
283 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
284 "Diagnostic Interrupt Received"},
285 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
286 "I/O Channel Check NMI Requested"},
287 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
288 "I/O Channel Check NMI Received"},
289 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
290 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
291 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
292 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
293 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
294 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
295 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
296 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
297 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
298 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
299 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
300 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
301 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
302 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
303 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
304 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
305 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
306 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
307 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
308 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
309 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
310 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
311 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
312 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
313 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
314 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
315 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
316 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
317 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
318 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
319 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
320 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
321 "Redundant Memory Activity Status"},
322 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
323 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
324 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
325 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
326 {PLDM_STATE_SET_SLOT_STATE, "Slot State"}};
Tom Josepha65c0412020-07-03 21:14:44 +0530327
328 const std::array<std::string_view, 4> sensorInit = {
329 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
330
Tom Joseph97a7a762020-07-06 10:37:18 +0530331 const std::array<std::string_view, 4> effecterInit = {
332 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
333
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500334 const std::map<uint8_t, std::string> pdrType = {
335 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
336 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
337 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
338 "Numeric Sensor Initialization PDR"},
339 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
340 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
341 "State Sensor Initialization PDR"},
342 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
343 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
344 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
345 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
346 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
347 "Numeric Effecter Initialization PDR"},
348 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
349 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
350 "State Effecter Initialization PDR"},
351 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
352 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
353 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
354 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
355 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
356 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
357 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
358 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
359 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
360 {PLDM_OEM_PDR, "OEM PDR"},
361 };
362
Tom Josepha65c0412020-07-03 21:14:44 +0530363 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500364 {
365 try
366 {
367 return entityType.at(type);
368 }
369 catch (const std::out_of_range& e)
370 {
371 return std::to_string(static_cast<unsigned>(type)) + "(OEM)";
372 }
373 }
374
Tom Josepha65c0412020-07-03 21:14:44 +0530375 std::string getStateSetName(uint16_t id)
376 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500377 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530378 try
379 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500380 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530381 }
382 catch (const std::out_of_range& e)
383 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500384 return typeString;
385 }
386 }
387
388 std::string getPDRType(uint8_t type)
389 {
390 auto typeString = std::to_string(type);
391 try
392 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500393 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500394 }
395 catch (const std::out_of_range& e)
396 {
397 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530398 }
399 }
400
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500401 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530402 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500403 output["recordHandle"] = hdr->record_handle;
404 output["PDRHeaderVersion"] = unsigned(hdr->version);
405 output["PDRType"] = getPDRType(hdr->type);
406 output["recordChangeNumber"] = hdr->record_change_num;
407 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530408 }
409
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500410 std::string printPossibleStates(uint8_t possibleStatesSize,
411 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530412 {
413 uint8_t possibleStatesPos{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500414 std::string data;
415 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
416 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530417 for (int i = 0; i < CHAR_BIT; i++)
418 {
419 if (val.byte & (1 << i))
420 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500421 pstates << " " << (possibleStatesPos * CHAR_BIT + i);
422 data.append(pstates.str());
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600423 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530424 }
425 }
426 possibleStatesPos++;
427 };
428 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500429 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530430 }
431
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500432 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530433 {
434 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500435 output["PLDMTerminusHandle"] = pdr->terminus_handle;
436 output["sensorID"] = pdr->sensor_id;
437 output["entityType"] = getEntityName(pdr->entity_type);
438 output["entityInstanceNumber"] = pdr->entity_instance;
439 output["containerID"] = pdr->container_id;
440 output["sensorInit"] = sensorInit[pdr->sensor_init];
441 output["sensorAuxiliaryNamesPDR"] =
442 (pdr->sensor_auxiliary_names_pdr ? true : false);
443 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530444
445 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600446 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530447
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600448 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530449 {
450 auto state = reinterpret_cast<const state_sensor_possible_states*>(
451 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600452 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
453 getStateSetName(state->state_set_id));
454 output.emplace(
455 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
456 state->possible_states_size);
457 output.emplace(
458 ("possibleStates[" + std::to_string(compCount) + "]"),
459 printPossibleStates(state->possible_states_size,
460 state->states));
Tom Josepha65c0412020-07-03 21:14:44 +0530461
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600462 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530463 {
464 statesPtr += sizeof(state_sensor_possible_states) +
465 state->possible_states_size - 1;
466 }
467 }
468 }
469
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500470 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500471 {
George Liu62d12ec2020-02-05 16:27:08 +0800472 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500473 {
474 return;
475 }
476
477 data += sizeof(pldm_pdr_hdr);
478 pldm_pdr_fru_record_set* pdr =
479 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530480 if (!pdr)
481 {
482 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
483 return;
484 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500485
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500486 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
487 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
488 output["entityType"] = getEntityName(pdr->entity_type);
489 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
490 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500491 }
492
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500493 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500494 {
495 const std::map<uint8_t, const char*> assocationType = {
496 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
497 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
498 };
499
George Liu62d12ec2020-02-05 16:27:08 +0800500 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500501 {
502 return;
503 }
504
505 data += sizeof(pldm_pdr_hdr);
506 pldm_pdr_entity_association* pdr =
507 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530508 if (!pdr)
509 {
510 std::cerr << "Failed to get the PDR eneity association"
511 << std::endl;
512 return;
513 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500514
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500515 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800516 if (assocationType.contains(pdr->association_type))
517 {
518 output["associationType"] =
519 assocationType.at(pdr->association_type);
520 }
521 else
522 {
523 std::cout << "Get associationType failed.\n";
524 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500525 output["containerEntityType"] =
526 getEntityName(pdr->container.entity_type);
527 output["containerEntityInstanceNumber"] =
528 int(pdr->container.entity_instance_num);
529 output["containerEntityContainerID"] =
530 int(pdr->container.entity_container_id);
531 output["containedEntityCount"] =
532 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500533
534 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
535 for (int i = 0; i < pdr->num_children; ++i)
536 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500537 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
538 getEntityName(child->entity_type));
539 output.emplace("containedEntityInstanceNumber[" +
540 std::to_string(i + 1) + "]",
541 unsigned(child->entity_instance_num));
542 output.emplace("containedEntityContainerID[" +
543 std::to_string(i + 1) + "]",
544 unsigned(child->entity_container_id));
545
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500546 ++child;
547 }
548 }
549
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500550 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800551 {
552 struct pldm_numeric_effecter_value_pdr* pdr =
553 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530554 if (!pdr)
555 {
556 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
557 return;
558 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500559
560 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
561 output["effecterID"] = int(pdr->effecter_id);
562 output["entityType"] = int(pdr->entity_type);
563 output["entityInstanceNumber"] = int(pdr->entity_instance);
564 output["containerID"] = int(pdr->container_id);
565 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
566 output["effecterInit"] = unsigned(pdr->effecter_init);
567 output["effecterAuxiliaryNames"] =
568 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
569 output["baseUnit"] = unsigned(pdr->base_unit);
570 output["unitModifier"] = unsigned(pdr->unit_modifier);
571 output["rateUnit"] = unsigned(pdr->rate_unit);
572 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
573 output["auxUnit"] = unsigned(pdr->aux_unit);
574 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
575 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
576 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
577 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
578 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
579 output["resolution"] = unsigned(pdr->resolution);
580 output["offset"] = unsigned(pdr->offset);
581 output["accuracy"] = unsigned(pdr->accuracy);
582 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
583 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
584 output["stateTransitionInterval"] =
585 unsigned(pdr->state_transition_interval);
586 output["TransitionInterval"] = unsigned(pdr->transition_interval);
587
George Liu62d12ec2020-02-05 16:27:08 +0800588 switch (pdr->effecter_data_size)
589 {
590 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500591 output["maxSettable"] = unsigned(pdr->max_set_table.value_u8);
592 output["minSettable"] = unsigned(pdr->min_set_table.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800593 break;
594 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500595 output["maxSettable"] = unsigned(pdr->max_set_table.value_s8);
596 output["minSettable"] = unsigned(pdr->min_set_table.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800597 break;
598 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500599 output["maxSettable"] = unsigned(pdr->max_set_table.value_u16);
600 output["minSettable"] = unsigned(pdr->min_set_table.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800601 break;
602 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500603 output["maxSettable"] = unsigned(pdr->max_set_table.value_s16);
604 output["minSettable"] = unsigned(pdr->min_set_table.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800605 break;
606 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500607 output["maxSettable"] = unsigned(pdr->max_set_table.value_u32);
608 output["minSettable"] = unsigned(pdr->min_set_table.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800609 break;
610 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500611 output["maxSettable"] = unsigned(pdr->max_set_table.value_s32);
612 output["minSettable"] = unsigned(pdr->min_set_table.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800613 break;
614 default:
615 break;
616 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500617
618 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
619 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
620
George Liu62d12ec2020-02-05 16:27:08 +0800621 switch (pdr->range_field_format)
622 {
623 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500624 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
625 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
626 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
627 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
628 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800629 break;
630 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500631 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
632 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
633 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
634 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
635 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800636 break;
637 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500638 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
639 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
640 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
641 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
642 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800643 break;
644 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500645 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
646 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
647 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
648 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
649 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800650 break;
651 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500652 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
653 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
654 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
655 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
656 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800657 break;
658 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500659 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
660 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
661 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
662 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
663 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800664 break;
665 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500666 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
667 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
668 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
669 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
670 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800671 break;
672 default:
673 break;
674 }
675 }
676
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500677 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800678 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530679 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800680
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500681 output["PLDMTerminusHandle"] = pdr->terminus_handle;
682 output["effecterID"] = pdr->effecter_id;
683 output["entityType"] = getEntityName(pdr->entity_type);
684 output["entityInstanceNumber"] = pdr->entity_instance;
685 output["containerID"] = pdr->container_id;
686 output["effecterSemanticID"] = pdr->effecter_semantic_id;
687 output["effecterInit"] = effecterInit[pdr->effecter_init];
688 output["effecterDescriptionPDR"] =
689 (pdr->has_description_pdr ? true : false);
690 output["compositeEffecterCount"] =
691 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +0800692
Tom Joseph97a7a762020-07-06 10:37:18 +0530693 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600694 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +0530695
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600696 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +0800697 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530698 auto state =
699 reinterpret_cast<const state_effecter_possible_states*>(
700 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600701 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
702 getStateSetName(state->state_set_id));
703 output.emplace(
704 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
705 state->possible_states_size);
706 output.emplace(
707 ("possibleStates[" + std::to_string(compEffCount) + "]"),
708 printPossibleStates(state->possible_states_size,
709 state->states));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500710
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600711 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +0530712 {
713 statesPtr += sizeof(state_effecter_possible_states) +
714 state->possible_states_size - 1;
715 }
George Liud6649362019-11-27 19:06:51 +0800716 }
717 }
718
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500719 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -0500720 {
721 const std::array<std::string_view, 4> terminusLocatorType = {
722 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
723
724 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
725
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500726 output["PLDMTerminusHandle"] = pdr->terminus_handle;
727 output["validity"] = (pdr->validity ? "valid" : "notValid");
728 output["TID"] = unsigned(pdr->tid);
729 output["containerID"] = pdr->container_id;
730 output["terminusLocatorType"] =
731 terminusLocatorType[pdr->terminus_locator_type];
732 output["terminusLocatorValueSize"] =
733 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -0500734
735 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
736 {
737 auto locatorValue =
738 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
739 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500740 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -0500741 }
742 }
743
George Liud6649362019-11-27 19:06:51 +0800744 void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt,
George Liu62d12ec2020-02-05 16:27:08 +0800745 uint8_t* data)
George Liud6649362019-11-27 19:06:51 +0800746 {
George Liu62d12ec2020-02-05 16:27:08 +0800747 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800748 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530749 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +0800750 return;
751 }
752
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500753 ordered_json output;
754 output["nextRecordHandle"] = nextRecordHndl;
755 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +0800756
757 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530758 if (!pdr)
759 {
760 return;
761 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500762 printCommonPDRHeader(pdr, output);
763
George Liud6649362019-11-27 19:06:51 +0800764 switch (pdr->type)
765 {
Sampa Misra12afe112020-05-25 11:40:44 -0500766 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500767 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -0500768 break;
Tom Josepha65c0412020-07-03 21:14:44 +0530769 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500770 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +0530771 break;
George Liu62d12ec2020-02-05 16:27:08 +0800772 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500773 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +0800774 break;
George Liud6649362019-11-27 19:06:51 +0800775 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500776 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +0800777 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500778 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500779 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500780 break;
781 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500782 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500783 break;
George Liud6649362019-11-27 19:06:51 +0800784 default:
785 break;
786 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500787 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +0800788 }
789
790 private:
791 uint32_t recordHandle;
792};
793
794class SetStateEffecter : public CommandInterface
795{
796 public:
797 ~SetStateEffecter() = default;
798 SetStateEffecter() = delete;
799 SetStateEffecter(const SetStateEffecter&) = delete;
800 SetStateEffecter(SetStateEffecter&&) = default;
801 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
802 SetStateEffecter& operator=(SetStateEffecter&&) = default;
803
George Liuba4c1fb2020-02-05 14:13:30 +0800804 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
805 static constexpr auto maxEffecterDataSize = 16;
806
807 // compositeEffecterCount(value: 0x01 to 0x08)
808 static constexpr auto minEffecterCount = 1;
809 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +0800810 explicit SetStateEffecter(const char* type, const char* name,
811 CLI::App* app) :
812 CommandInterface(type, name, app)
813 {
814 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +0800815 "-i, --id", effecterId,
816 "A handle that is used to identify and access the effecter")
817 ->required();
818 app->add_option("-c, --count", effecterCount,
819 "The number of individual sets of effecter information")
820 ->required();
821 app->add_option(
George Liud6649362019-11-27 19:06:51 +0800822 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +0800823 "Set effecter state data\n"
824 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
825 ->required();
George Liud6649362019-11-27 19:06:51 +0800826 }
827
828 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
829 {
830 std::vector<uint8_t> requestMsg(
831 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
832 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
833
George Liuba4c1fb2020-02-05 14:13:30 +0800834 if (effecterCount > maxEffecterCount ||
835 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +0800836 {
George Liuba4c1fb2020-02-05 14:13:30 +0800837 std::cerr << "Request Message Error: effecterCount size "
838 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +0800839 auto rc = PLDM_ERROR_INVALID_DATA;
840 return {rc, requestMsg};
841 }
842
George Liuba4c1fb2020-02-05 14:13:30 +0800843 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +0800844 {
George Liuba4c1fb2020-02-05 14:13:30 +0800845 std::cerr << "Request Message Error: effecterData size "
846 << effecterData.size() << "is invalid\n";
847 auto rc = PLDM_ERROR_INVALID_DATA;
848 return {rc, requestMsg};
849 }
850
851 auto stateField = parseEffecterData(effecterData, effecterCount);
852 if (!stateField)
853 {
854 std::cerr << "Failed to parse effecter data, effecterCount size "
855 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +0800856 auto rc = PLDM_ERROR_INVALID_DATA;
857 return {rc, requestMsg};
858 }
859
860 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600861 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +0800862 return {rc, requestMsg};
863 }
864
865 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
866 {
867 uint8_t completionCode = 0;
868 auto rc = decode_set_state_effecter_states_resp(
869 responsePtr, payloadLength, &completionCode);
870
871 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
872 {
873 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +0800874 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +0800875 return;
876 }
877
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500878 ordered_json data;
879 data["Response"] = "SUCCESS";
880 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +0800881 }
882
883 private:
George Liuba4c1fb2020-02-05 14:13:30 +0800884 uint16_t effecterId;
885 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +0800886 std::vector<uint8_t> effecterData;
887};
888
George Liucc9c20d2020-02-05 10:24:11 +0800889class SetNumericEffecterValue : public CommandInterface
890{
891 public:
892 ~SetNumericEffecterValue() = default;
893 SetNumericEffecterValue() = delete;
894 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
895 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
896 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
897 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default;
898
899 explicit SetNumericEffecterValue(const char* type, const char* name,
900 CLI::App* app) :
901 CommandInterface(type, name, app)
902 {
903 app->add_option(
904 "-i, --id", effecterId,
905 "A handle that is used to identify and access the effecter")
906 ->required();
907 app->add_option("-s, --size", effecterDataSize,
908 "The bit width and format of the setting value for the "
909 "effecter. enum value: {uint8, sint8, uint16, sint16, "
910 "uint32, sint32}\n")
911 ->required();
912 app->add_option("-d,--data", maxEffecterValue,
913 "The setting value of numeric effecter being "
914 "requested\n")
915 ->required();
916 }
917
918 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
919 {
920 std::vector<uint8_t> requestMsg(
921 sizeof(pldm_msg_hdr) +
922 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
923
924 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
925
926 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
927 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
928
929 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
930 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
931 {
932 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
933 }
934 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
935 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
936 {
937 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
938 }
939 auto rc = encode_set_numeric_effecter_value_req(
940 0, effecterId, effecterDataSize, effecterValue, request,
941 payload_length);
942
943 return {rc, requestMsg};
944 }
945
946 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
947 {
948 uint8_t completionCode = 0;
949 auto rc = decode_set_numeric_effecter_value_resp(
950 responsePtr, payloadLength, &completionCode);
951
952 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
953 {
954 std::cerr << "Response Message Error: "
955 << "rc=" << rc << ",cc=" << (int)completionCode
956 << std::endl;
957 return;
958 }
959
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500960 ordered_json data;
961 data["Response"] = "SUCCESS";
962 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +0800963 }
964
965 private:
966 uint16_t effecterId;
967 uint8_t effecterDataSize;
968 uint64_t maxEffecterValue;
969};
970
Sridevi Rameshf31b5042021-01-22 05:42:07 -0600971class GetStateSensorReadings : public CommandInterface
972{
973 public:
974 ~GetStateSensorReadings() = default;
975 GetStateSensorReadings() = delete;
976 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
977 GetStateSensorReadings(GetStateSensorReadings&&) = default;
978 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
979 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default;
980
981 explicit GetStateSensorReadings(const char* type, const char* name,
982 CLI::App* app) :
983 CommandInterface(type, name, app)
984 {
985 app->add_option(
986 "-i, --sensor_id", sensorId,
987 "Sensor ID that is used to identify and access the sensor")
988 ->required();
989 app->add_option("-r, --rearm", sensorRearm,
990 "Each bit location in this field corresponds to a "
991 "particular sensor")
992 ->required();
993 }
994
995 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
996 {
997 std::vector<uint8_t> requestMsg(
998 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
999 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1000
1001 uint8_t reserved = 0;
1002 bitfield8_t bf;
1003 bf.byte = sensorRearm;
1004 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1005 reserved, request);
1006
1007 return {rc, requestMsg};
1008 }
1009
1010 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1011 {
1012 uint8_t completionCode = 0;
1013 uint8_t compSensorCount = 0;
1014 std::array<get_sensor_state_field, 8> stateField{};
1015 auto rc = decode_get_state_sensor_readings_resp(
1016 responsePtr, payloadLength, &completionCode, &compSensorCount,
1017 stateField.data());
1018
1019 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1020 {
1021 std::cerr << "Response Message Error: "
1022 << "rc=" << rc << ",cc=" << (int)completionCode
1023 << std::endl;
1024 return;
1025 }
1026 ordered_json output;
1027 output["compositeSensorCount"] = (int)compSensorCount;
1028
1029 for (size_t i = 0; i < compSensorCount; i++)
1030 {
George Liubd5e2ea2021-04-22 20:33:06 +08001031 if (sensorOpState.contains(stateField[i].sensor_op_state))
1032 {
1033 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1034 sensorOpState.at(stateField[i].sensor_op_state));
1035 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001036
George Liubd5e2ea2021-04-22 20:33:06 +08001037 if (sensorPresState.contains(stateField[i].present_state))
1038 {
1039 output.emplace(("presentState[" + std::to_string(i) + "]"),
1040 sensorPresState.at(stateField[i].present_state));
1041 }
1042
1043 if (sensorPresState.contains(stateField[i].previous_state))
1044 {
1045 output.emplace(
1046 ("previousState[" + std::to_string(i) + "]"),
1047 sensorPresState.at(stateField[i].previous_state));
1048 }
1049
1050 if (sensorPresState.contains(stateField[i].event_state))
1051 {
1052 output.emplace(("eventState[" + std::to_string(i) + "]"),
1053 sensorPresState.at(stateField[i].event_state));
1054 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001055 }
1056
1057 pldmtool::helper::DisplayInJson(output);
1058 }
1059
1060 private:
1061 uint16_t sensorId;
1062 uint8_t sensorRearm;
1063};
1064
George Liud6649362019-11-27 19:06:51 +08001065void registerCommand(CLI::App& app)
1066{
1067 auto platform = app.add_subcommand("platform", "platform type command");
1068 platform->require_subcommand(1);
1069
1070 auto getPDR =
1071 platform->add_subcommand("GetPDR", "get platform descriptor records");
1072 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
1073
1074 auto setStateEffecterStates = platform->add_subcommand(
1075 "SetStateEffecterStates", "set effecter states");
1076 commands.push_back(std::make_unique<SetStateEffecter>(
1077 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08001078
1079 auto setNumericEffecterValue = platform->add_subcommand(
1080 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
1081 commands.push_back(std::make_unique<SetNumericEffecterValue>(
1082 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001083
1084 auto getStateSensorReadings = platform->add_subcommand(
1085 "GetStateSensorReadings", "get the state sensor readings");
1086 commands.push_back(std::make_unique<GetStateSensorReadings>(
1087 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +08001088}
1089
1090} // namespace platform
1091} // namespace pldmtool