blob: 7949d4570b175140738b3e5bfcfa5ef46318f526 [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
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05007#ifdef OEM_IBM
8#include "oem/ibm/oem_ibm_state_set.hpp"
9#endif
10
Brad Bishop5079ac42021-08-19 18:35:06 -040011using namespace pldm::utils;
12
George Liud6649362019-11-27 19:06:51 +080013namespace pldmtool
14{
15
16namespace platform
17{
18
19namespace
20{
21
22using 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;
61 GetPDR& operator=(GetPDR&&) = default;
62
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",
70 "Retrieve individual PDR, all PDRs, or PDRs of a requested type");
71 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, ... ]");
83 allPDRs = false;
84 pdrOptionGroup->add_flag("-a, --all", allPDRs,
85 "retrieve all PDRs from a PDR repository");
86 pdrOptionGroup->require_option(1);
87 }
88
89 void exec() override
90 {
91 if (allPDRs || !pdrRecType.empty())
92 {
93 if (!pdrRecType.empty())
94 {
95 std::transform(pdrRecType.begin(), pdrRecType.end(),
96 pdrRecType.begin(), tolower);
97 }
98
99 // Retrieve all PDR records starting from the first
100 recordHandle = 0;
101 uint32_t prevRecordHandle = 0;
102 do
103 {
104 CommandInterface::exec();
105 // recordHandle is updated to nextRecord when
106 // CommandInterface::exec() is successful.
107 // In case of any error, return.
108 if (recordHandle == prevRecordHandle)
109 {
110 return;
111 }
112 prevRecordHandle = recordHandle;
113 } while (recordHandle != 0);
114 }
115 else
116 {
117 CommandInterface::exec();
118 }
George Liud6649362019-11-27 19:06:51 +0800119 }
120
121 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
122 {
123 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
124 PLDM_GET_PDR_REQ_BYTES);
125 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
126
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500127 auto rc =
128 encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
129 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800130 return {rc, requestMsg};
131 }
132
133 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
134 {
135 uint8_t completionCode = 0;
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500136 uint8_t recordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800137 uint32_t nextRecordHndl = 0;
138 uint32_t nextDataTransferHndl = 0;
139 uint8_t transferFlag = 0;
140 uint16_t respCnt = 0;
141 uint8_t transferCRC = 0;
142
143 auto rc = decode_get_pdr_resp(
144 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
145 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
146 sizeof(recordData), &transferCRC);
147
148 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
149 {
150 std::cerr << "Response Message Error: "
151 << "rc=" << rc << ",cc=" << (int)completionCode
152 << std::endl;
153 return;
154 }
155
George Liu62d12ec2020-02-05 16:27:08 +0800156 printPDRMsg(nextRecordHndl, respCnt, recordData);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500157 recordHandle = nextRecordHndl;
George Liud6649362019-11-27 19:06:51 +0800158 }
159
160 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530161 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530162 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
163 {PLDM_ENTITY_OTHER, "Other"},
164 {PLDM_ENTITY_NETWORK, "Network"},
165 {PLDM_ENTITY_GROUP, "Group"},
166 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
167 "Remote Management Communication Device"},
168 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
169 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
170 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
171 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
172 {PLDM_ENTITY_KEYPAD, "keypad"},
173 {PLDM_ENTITY_SWITCH, "Switch"},
174 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
175 {PLDM_ENTITY_DISPLAY, "Display"},
176 {PLDM_ENTITY_INDICATOR, "Indicator"},
177 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530178 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530179 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530180 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530181 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
182 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
183 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530184 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530185 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
186 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
187 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
188 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
189 {PLDM_ENTITY_DOOR, "Door"},
190 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
191 {PLDM_ENTITY_COVER, "Cover"},
192 {PLDM_ENTITY_BOARD, "Board"},
193 {PLDM_ENTITY_CARD, "Card"},
194 {PLDM_ENTITY_MODULE, "Module"},
195 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530196 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530197 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530198 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
199 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530200 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530201 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530202 "Chassis front panel board(control panel)"},
203 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
204 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
205 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
206 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
207 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
208 "System internal expansion board"},
209 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
210 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
211 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
212 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
213 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
214 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
215 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
216 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
217 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
218 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500219 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530220 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
221 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
222 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
223 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
224 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
225 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
226 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
227 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
228 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
229 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500230 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530231 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
232 {PLDM_ENTITY_BATTERY, "Battery"},
233 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
234 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
235 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
236 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
237 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
238 {PLDM_ENTITY_PROC, "Processor"},
239 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
240 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
241 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
242 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
243 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
244 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
245 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
246 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
247 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
248 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
249 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500250 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530251 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
252 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
253 {PLDM_ENTITY_SYS_BUS, "System Bus"},
254 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
255 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
256 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
257 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
258 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
259 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
260 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
261 {PLDM_ENTITY_USB_BUS, "USB Bus"},
262 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
263 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
264 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
265 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
266 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
267 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500268 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530269 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
270 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
271 {PLDM_ENTITY_PLUG, "Plug"},
272 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500273 {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"},
274 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500275
Tom Josepha65c0412020-07-03 21:14:44 +0530276 const std::map<uint16_t, std::string> stateSet = {
277 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
278 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530279 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
280 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
281 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
282 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
283 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530284 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530285 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
286 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530287 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
288 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530289 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
290 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530291 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530292 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530293 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530294 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
295 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
296 {PLDM_STATE_SET_VERSION, "Version"},
297 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
298 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
299 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
300 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530301 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530302 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
303 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
304 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
305 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
306 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
307 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
308 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
309 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
310 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
311 "Physical Communication Connection"},
312 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
313 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
314 "Foreign Network Detection Status"},
315 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
316 "Password-Protected Access Security"},
317 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
318 "Security Access –PrivilegeLevel"},
319 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530320 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530321 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530322 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530323 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
324 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
325 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530326 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530327 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
328 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
329 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
330 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
331 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
332 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
333 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
334 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
335 "Diagnostic Interrupt Requested"},
336 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
337 "Diagnostic Interrupt Received"},
338 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
339 "I/O Channel Check NMI Requested"},
340 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
341 "I/O Channel Check NMI Received"},
342 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
343 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
344 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
345 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
346 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
347 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
348 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
349 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
350 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
351 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
352 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
353 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
354 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
355 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
356 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
357 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
358 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
359 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
360 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
361 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
362 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
363 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
364 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
365 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
366 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
367 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
368 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
369 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
370 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
371 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
372 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
373 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
374 "Redundant Memory Activity Status"},
375 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
376 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
377 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
378 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500379 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
380 };
Tom Josepha65c0412020-07-03 21:14:44 +0530381
382 const std::array<std::string_view, 4> sensorInit = {
383 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
384
Tom Joseph97a7a762020-07-06 10:37:18 +0530385 const std::array<std::string_view, 4> effecterInit = {
386 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
387
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500388 const std::map<uint8_t, std::string> pdrType = {
389 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
390 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
391 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
392 "Numeric Sensor Initialization PDR"},
393 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
394 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
395 "State Sensor Initialization PDR"},
396 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
397 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
398 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
399 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
400 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
401 "Numeric Effecter Initialization PDR"},
402 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
403 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
404 "State Effecter Initialization PDR"},
405 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
406 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
407 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
408 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
409 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
410 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
411 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
412 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
413 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
414 {PLDM_OEM_PDR, "OEM PDR"},
415 };
416
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500417 static inline const std::map<uint8_t, std::string> setThermalTrip{
418 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
419 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
420
421 static inline const std::map<uint8_t, std::string> setIdentifyState{
422 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
423 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
424
425 static inline const std::map<uint8_t, std::string> setBootProgressState{
426 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
427 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
428 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
429 "Memory Initialization"},
430 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
431 "Secondary Processor(s) Initialization"},
432 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
433 "PCI Resource Configuration"},
434 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
435 "Starting Operating System"},
436 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
437 "Baseboard Initialization"},
438 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
439 "Primary Processor Initialization"}};
440
441 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
442 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
443 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED, "Stressed"}};
444
445 static inline const std::map<uint8_t, std::string> setSysPowerState{
446 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
447 "Off-Soft Graceful"}};
448
449 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
450 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
451 "Graceful Restart Requested"}};
452
453 static inline const std::map<uint8_t, std::string> setAvailability{
454 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
455
456 static inline const std::map<uint8_t, std::string> setHealthState{
457 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
458 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
459 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"}};
460
461 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
462 populatePStateMaps{
463 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
464 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
465 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
466 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
467 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
468 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
469 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
470 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
471 };
472
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500473 const std::map<std::string, uint8_t> strToPdrType = {
474 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
475 {"statesensor", PLDM_STATE_SENSOR_PDR},
476 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
477 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
478 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
479 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
480 // Add other types
481 };
482
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530483 bool isLogicalBitSet(const uint16_t entity_type)
484 {
485 return entity_type & 0x8000;
486 }
487
488 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
489 {
490 return logical_entity_type & 0x7FFF;
491 }
492
Tom Josepha65c0412020-07-03 21:14:44 +0530493 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500494 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530495 uint16_t entityNumber = type;
496 std::string entityName = "[Physical] ";
497
498 if (isLogicalBitSet(type))
499 {
500 entityName = "[Logical] ";
501 entityNumber = getEntityTypeForLogicalEntity(type);
502 }
503
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500504 try
505 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530506 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500507 }
508 catch (const std::out_of_range& e)
509 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500510 auto OemString =
511 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530512 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
513 type <= PLDM_OEM_ENTITY_TYPE_END)
514 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500515#ifdef OEM_IBM
516 if (OemIBMEntityType.contains(entityNumber))
517 {
518 return entityName + OemIBMEntityType.at(entityNumber) +
519 "(OEM)";
520 }
521#endif
522 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530523 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500524 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500525 }
526 }
527
Tom Josepha65c0412020-07-03 21:14:44 +0530528 std::string getStateSetName(uint16_t id)
529 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500530 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530531 try
532 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500533 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530534 }
535 catch (const std::out_of_range& e)
536 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500537 return typeString;
538 }
539 }
540
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500541 std::vector<std::string>
542 getStateSetPossibleStateNames(uint16_t stateId,
543 const std::vector<uint8_t>& value)
544 {
545 std::vector<std::string> data{};
546 std::map<uint8_t, std::string> stateNameMaps;
547
548 for (auto& s : value)
549 {
550 std::map<uint8_t, std::string> stateNameMaps;
551 auto pstr = std::to_string(s);
552
553#ifdef OEM_IBM
554 if (stateId >= PLDM_OEM_STATE_SET_START &&
555 stateId <= PLDM_OEM_STATE_SET_END)
556 {
557 if (populateOemIBMStateMaps.contains(stateId))
558 {
559 const std::map<uint8_t, std::string> stateNames =
560 populateOemIBMStateMaps.at(stateId);
561 stateNameMaps.insert(stateNames.begin(), stateNames.end());
562 }
563 }
564#endif
565 if (populatePStateMaps.contains(stateId))
566 {
567 const std::map<uint8_t, std::string> stateNames =
568 populatePStateMaps.at(stateId);
569 stateNameMaps.insert(stateNames.begin(), stateNames.end());
570 }
571 if (stateNameMaps.contains(s))
572 {
573 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
574 }
575 else
576 {
577 data.push_back(pstr);
578 }
579 }
580 return data;
581 }
582
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500583 std::string getPDRType(uint8_t type)
584 {
585 auto typeString = std::to_string(type);
586 try
587 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500588 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500589 }
590 catch (const std::out_of_range& e)
591 {
592 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530593 }
594 }
595
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500596 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530597 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500598 output["recordHandle"] = hdr->record_handle;
599 output["PDRHeaderVersion"] = unsigned(hdr->version);
600 output["PDRType"] = getPDRType(hdr->type);
601 output["recordChangeNumber"] = hdr->record_change_num;
602 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530603 }
604
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500605 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
606 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530607 {
608 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500609 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500610 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
611 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530612 for (int i = 0; i < CHAR_BIT; i++)
613 {
614 if (val.byte & (1 << i))
615 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500616 pstates << (possibleStatesPos * CHAR_BIT + i);
617 data.push_back(
618 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600619 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530620 }
621 }
622 possibleStatesPos++;
623 };
624 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500625 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530626 }
627
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500628 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530629 {
630 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500631 output["PLDMTerminusHandle"] = pdr->terminus_handle;
632 output["sensorID"] = pdr->sensor_id;
633 output["entityType"] = getEntityName(pdr->entity_type);
634 output["entityInstanceNumber"] = pdr->entity_instance;
635 output["containerID"] = pdr->container_id;
636 output["sensorInit"] = sensorInit[pdr->sensor_init];
637 output["sensorAuxiliaryNamesPDR"] =
638 (pdr->sensor_auxiliary_names_pdr ? true : false);
639 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530640
641 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600642 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530643
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600644 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530645 {
646 auto state = reinterpret_cast<const state_sensor_possible_states*>(
647 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600648 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
649 getStateSetName(state->state_set_id));
650 output.emplace(
651 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
652 state->possible_states_size);
653 output.emplace(
654 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500655 getStateSetPossibleStateNames(
656 state->state_set_id,
657 printPossibleStates(state->possible_states_size,
658 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530659
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600660 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530661 {
662 statesPtr += sizeof(state_sensor_possible_states) +
663 state->possible_states_size - 1;
664 }
665 }
666 }
667
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500668 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500669 {
George Liu62d12ec2020-02-05 16:27:08 +0800670 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500671 {
672 return;
673 }
674
675 data += sizeof(pldm_pdr_hdr);
676 pldm_pdr_fru_record_set* pdr =
677 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530678 if (!pdr)
679 {
680 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
681 return;
682 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500683
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500684 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
685 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
686 output["entityType"] = getEntityName(pdr->entity_type);
687 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
688 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500689 }
690
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500691 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500692 {
693 const std::map<uint8_t, const char*> assocationType = {
694 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
695 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
696 };
697
George Liu62d12ec2020-02-05 16:27:08 +0800698 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500699 {
700 return;
701 }
702
703 data += sizeof(pldm_pdr_hdr);
704 pldm_pdr_entity_association* pdr =
705 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530706 if (!pdr)
707 {
708 std::cerr << "Failed to get the PDR eneity association"
709 << std::endl;
710 return;
711 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500712
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500713 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800714 if (assocationType.contains(pdr->association_type))
715 {
716 output["associationType"] =
717 assocationType.at(pdr->association_type);
718 }
719 else
720 {
721 std::cout << "Get associationType failed.\n";
722 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500723 output["containerEntityType"] =
724 getEntityName(pdr->container.entity_type);
725 output["containerEntityInstanceNumber"] =
726 int(pdr->container.entity_instance_num);
727 output["containerEntityContainerID"] =
728 int(pdr->container.entity_container_id);
729 output["containedEntityCount"] =
730 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500731
732 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
733 for (int i = 0; i < pdr->num_children; ++i)
734 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500735 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
736 getEntityName(child->entity_type));
737 output.emplace("containedEntityInstanceNumber[" +
738 std::to_string(i + 1) + "]",
739 unsigned(child->entity_instance_num));
740 output.emplace("containedEntityContainerID[" +
741 std::to_string(i + 1) + "]",
742 unsigned(child->entity_container_id));
743
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500744 ++child;
745 }
746 }
747
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500748 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800749 {
750 struct pldm_numeric_effecter_value_pdr* pdr =
751 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530752 if (!pdr)
753 {
754 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
755 return;
756 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500757
758 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
759 output["effecterID"] = int(pdr->effecter_id);
760 output["entityType"] = int(pdr->entity_type);
761 output["entityInstanceNumber"] = int(pdr->entity_instance);
762 output["containerID"] = int(pdr->container_id);
763 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
764 output["effecterInit"] = unsigned(pdr->effecter_init);
765 output["effecterAuxiliaryNames"] =
766 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
767 output["baseUnit"] = unsigned(pdr->base_unit);
768 output["unitModifier"] = unsigned(pdr->unit_modifier);
769 output["rateUnit"] = unsigned(pdr->rate_unit);
770 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
771 output["auxUnit"] = unsigned(pdr->aux_unit);
772 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
773 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
774 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
775 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
776 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
777 output["resolution"] = unsigned(pdr->resolution);
778 output["offset"] = unsigned(pdr->offset);
779 output["accuracy"] = unsigned(pdr->accuracy);
780 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
781 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
782 output["stateTransitionInterval"] =
783 unsigned(pdr->state_transition_interval);
784 output["TransitionInterval"] = unsigned(pdr->transition_interval);
785
George Liu62d12ec2020-02-05 16:27:08 +0800786 switch (pdr->effecter_data_size)
787 {
788 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500789 output["maxSettable"] = unsigned(pdr->max_set_table.value_u8);
790 output["minSettable"] = unsigned(pdr->min_set_table.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800791 break;
792 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500793 output["maxSettable"] = unsigned(pdr->max_set_table.value_s8);
794 output["minSettable"] = unsigned(pdr->min_set_table.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800795 break;
796 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500797 output["maxSettable"] = unsigned(pdr->max_set_table.value_u16);
798 output["minSettable"] = unsigned(pdr->min_set_table.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800799 break;
800 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500801 output["maxSettable"] = unsigned(pdr->max_set_table.value_s16);
802 output["minSettable"] = unsigned(pdr->min_set_table.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800803 break;
804 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500805 output["maxSettable"] = unsigned(pdr->max_set_table.value_u32);
806 output["minSettable"] = unsigned(pdr->min_set_table.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800807 break;
808 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500809 output["maxSettable"] = unsigned(pdr->max_set_table.value_s32);
810 output["minSettable"] = unsigned(pdr->min_set_table.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800811 break;
812 default:
813 break;
814 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500815
816 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
817 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
818
George Liu62d12ec2020-02-05 16:27:08 +0800819 switch (pdr->range_field_format)
820 {
821 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500822 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
823 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
824 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
825 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
826 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800827 break;
828 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500829 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
830 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
831 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
832 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
833 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800834 break;
835 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500836 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
837 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
838 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
839 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
840 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800841 break;
842 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500843 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
844 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
845 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
846 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
847 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800848 break;
849 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500850 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
851 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
852 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
853 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
854 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800855 break;
856 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500857 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
858 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
859 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
860 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
861 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800862 break;
863 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500864 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
865 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
866 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
867 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
868 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800869 break;
870 default:
871 break;
872 }
873 }
874
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500875 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800876 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530877 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800878
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500879 output["PLDMTerminusHandle"] = pdr->terminus_handle;
880 output["effecterID"] = pdr->effecter_id;
881 output["entityType"] = getEntityName(pdr->entity_type);
882 output["entityInstanceNumber"] = pdr->entity_instance;
883 output["containerID"] = pdr->container_id;
884 output["effecterSemanticID"] = pdr->effecter_semantic_id;
885 output["effecterInit"] = effecterInit[pdr->effecter_init];
886 output["effecterDescriptionPDR"] =
887 (pdr->has_description_pdr ? true : false);
888 output["compositeEffecterCount"] =
889 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +0800890
Tom Joseph97a7a762020-07-06 10:37:18 +0530891 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600892 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +0530893
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600894 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +0800895 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530896 auto state =
897 reinterpret_cast<const state_effecter_possible_states*>(
898 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600899 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
900 getStateSetName(state->state_set_id));
901 output.emplace(
902 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
903 state->possible_states_size);
904 output.emplace(
905 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500906 getStateSetPossibleStateNames(
907 state->state_set_id,
908 printPossibleStates(state->possible_states_size,
909 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500910
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600911 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +0530912 {
913 statesPtr += sizeof(state_effecter_possible_states) +
914 state->possible_states_size - 1;
915 }
George Liud6649362019-11-27 19:06:51 +0800916 }
917 }
918
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500919 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -0500920 {
921 const std::array<std::string_view, 4> terminusLocatorType = {
922 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
923
924 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
925
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500926 output["PLDMTerminusHandle"] = pdr->terminus_handle;
927 output["validity"] = (pdr->validity ? "valid" : "notValid");
928 output["TID"] = unsigned(pdr->tid);
929 output["containerID"] = pdr->container_id;
930 output["terminusLocatorType"] =
931 terminusLocatorType[pdr->terminus_locator_type];
932 output["terminusLocatorValueSize"] =
933 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -0500934
935 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
936 {
937 auto locatorValue =
938 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
939 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500940 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -0500941 }
942 }
943
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500944 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
George Liu62d12ec2020-02-05 16:27:08 +0800945 uint8_t* data)
George Liud6649362019-11-27 19:06:51 +0800946 {
George Liu62d12ec2020-02-05 16:27:08 +0800947 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800948 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530949 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +0800950 return;
951 }
952
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500953 ordered_json output;
954 output["nextRecordHandle"] = nextRecordHndl;
955 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +0800956
957 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530958 if (!pdr)
959 {
960 return;
961 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500962
963 if (!pdrRecType.empty())
964 {
965 // Need to return if the requested PDR type
966 // is not supported
967 if (!strToPdrType.contains(pdrRecType))
968 {
969 std::cerr << "PDR type '" << pdrRecType
970 << "' is not supported or invalid\n";
971 // PDR type not supported, setting next record handle to 0
972 // to avoid looping through all PDR records
973 nextRecordHndl = 0;
974 return;
975 }
976
977 // Do not print PDR record if the current record
978 // PDR type does not match with requested type
979 if (pdr->type != strToPdrType.at(pdrRecType))
980 {
981 return;
982 }
983 }
984
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500985 printCommonPDRHeader(pdr, output);
986
George Liud6649362019-11-27 19:06:51 +0800987 switch (pdr->type)
988 {
Sampa Misra12afe112020-05-25 11:40:44 -0500989 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500990 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -0500991 break;
Tom Josepha65c0412020-07-03 21:14:44 +0530992 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500993 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +0530994 break;
George Liu62d12ec2020-02-05 16:27:08 +0800995 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500996 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +0800997 break;
George Liud6649362019-11-27 19:06:51 +0800998 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500999 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001000 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001001 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001002 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001003 break;
1004 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001005 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001006 break;
George Liud6649362019-11-27 19:06:51 +08001007 default:
1008 break;
1009 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001010 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001011 }
1012
1013 private:
1014 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001015 bool allPDRs;
1016 std::string pdrRecType;
George Liud6649362019-11-27 19:06:51 +08001017};
1018
1019class SetStateEffecter : public CommandInterface
1020{
1021 public:
1022 ~SetStateEffecter() = default;
1023 SetStateEffecter() = delete;
1024 SetStateEffecter(const SetStateEffecter&) = delete;
1025 SetStateEffecter(SetStateEffecter&&) = default;
1026 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
1027 SetStateEffecter& operator=(SetStateEffecter&&) = default;
1028
George Liuba4c1fb2020-02-05 14:13:30 +08001029 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1030 static constexpr auto maxEffecterDataSize = 16;
1031
1032 // compositeEffecterCount(value: 0x01 to 0x08)
1033 static constexpr auto minEffecterCount = 1;
1034 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001035 explicit SetStateEffecter(const char* type, const char* name,
1036 CLI::App* app) :
1037 CommandInterface(type, name, app)
1038 {
1039 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001040 "-i, --id", effecterId,
1041 "A handle that is used to identify and access the effecter")
1042 ->required();
1043 app->add_option("-c, --count", effecterCount,
1044 "The number of individual sets of effecter information")
1045 ->required();
1046 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001047 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001048 "Set effecter state data\n"
1049 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1050 ->required();
George Liud6649362019-11-27 19:06:51 +08001051 }
1052
1053 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1054 {
1055 std::vector<uint8_t> requestMsg(
1056 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
1057 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1058
George Liuba4c1fb2020-02-05 14:13:30 +08001059 if (effecterCount > maxEffecterCount ||
1060 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001061 {
George Liuba4c1fb2020-02-05 14:13:30 +08001062 std::cerr << "Request Message Error: effecterCount size "
1063 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001064 auto rc = PLDM_ERROR_INVALID_DATA;
1065 return {rc, requestMsg};
1066 }
1067
George Liuba4c1fb2020-02-05 14:13:30 +08001068 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001069 {
George Liuba4c1fb2020-02-05 14:13:30 +08001070 std::cerr << "Request Message Error: effecterData size "
1071 << effecterData.size() << "is invalid\n";
1072 auto rc = PLDM_ERROR_INVALID_DATA;
1073 return {rc, requestMsg};
1074 }
1075
1076 auto stateField = parseEffecterData(effecterData, effecterCount);
1077 if (!stateField)
1078 {
1079 std::cerr << "Failed to parse effecter data, effecterCount size "
1080 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001081 auto rc = PLDM_ERROR_INVALID_DATA;
1082 return {rc, requestMsg};
1083 }
1084
1085 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001086 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001087 return {rc, requestMsg};
1088 }
1089
1090 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1091 {
1092 uint8_t completionCode = 0;
1093 auto rc = decode_set_state_effecter_states_resp(
1094 responsePtr, payloadLength, &completionCode);
1095
1096 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1097 {
1098 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001099 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001100 return;
1101 }
1102
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001103 ordered_json data;
1104 data["Response"] = "SUCCESS";
1105 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001106 }
1107
1108 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001109 uint16_t effecterId;
1110 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001111 std::vector<uint8_t> effecterData;
1112};
1113
George Liucc9c20d2020-02-05 10:24:11 +08001114class SetNumericEffecterValue : public CommandInterface
1115{
1116 public:
1117 ~SetNumericEffecterValue() = default;
1118 SetNumericEffecterValue() = delete;
1119 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1120 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1121 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
1122 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default;
1123
1124 explicit SetNumericEffecterValue(const char* type, const char* name,
1125 CLI::App* app) :
1126 CommandInterface(type, name, app)
1127 {
1128 app->add_option(
1129 "-i, --id", effecterId,
1130 "A handle that is used to identify and access the effecter")
1131 ->required();
1132 app->add_option("-s, --size", effecterDataSize,
1133 "The bit width and format of the setting value for the "
1134 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1135 "uint32, sint32}\n")
1136 ->required();
1137 app->add_option("-d,--data", maxEffecterValue,
1138 "The setting value of numeric effecter being "
1139 "requested\n")
1140 ->required();
1141 }
1142
1143 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1144 {
1145 std::vector<uint8_t> requestMsg(
1146 sizeof(pldm_msg_hdr) +
1147 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1148
1149 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1150
1151 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1152 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1153
1154 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1155 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1156 {
1157 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1158 }
1159 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1160 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1161 {
1162 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1163 }
1164 auto rc = encode_set_numeric_effecter_value_req(
1165 0, effecterId, effecterDataSize, effecterValue, request,
1166 payload_length);
1167
1168 return {rc, requestMsg};
1169 }
1170
1171 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1172 {
1173 uint8_t completionCode = 0;
1174 auto rc = decode_set_numeric_effecter_value_resp(
1175 responsePtr, payloadLength, &completionCode);
1176
1177 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1178 {
1179 std::cerr << "Response Message Error: "
1180 << "rc=" << rc << ",cc=" << (int)completionCode
1181 << std::endl;
1182 return;
1183 }
1184
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001185 ordered_json data;
1186 data["Response"] = "SUCCESS";
1187 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001188 }
1189
1190 private:
1191 uint16_t effecterId;
1192 uint8_t effecterDataSize;
1193 uint64_t maxEffecterValue;
1194};
1195
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001196class GetStateSensorReadings : public CommandInterface
1197{
1198 public:
1199 ~GetStateSensorReadings() = default;
1200 GetStateSensorReadings() = delete;
1201 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1202 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1203 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
1204 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default;
1205
1206 explicit GetStateSensorReadings(const char* type, const char* name,
1207 CLI::App* app) :
1208 CommandInterface(type, name, app)
1209 {
1210 app->add_option(
1211 "-i, --sensor_id", sensorId,
1212 "Sensor ID that is used to identify and access the sensor")
1213 ->required();
1214 app->add_option("-r, --rearm", sensorRearm,
1215 "Each bit location in this field corresponds to a "
1216 "particular sensor")
1217 ->required();
1218 }
1219
1220 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1221 {
1222 std::vector<uint8_t> requestMsg(
1223 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
1224 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1225
1226 uint8_t reserved = 0;
1227 bitfield8_t bf;
1228 bf.byte = sensorRearm;
1229 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1230 reserved, request);
1231
1232 return {rc, requestMsg};
1233 }
1234
1235 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1236 {
1237 uint8_t completionCode = 0;
1238 uint8_t compSensorCount = 0;
1239 std::array<get_sensor_state_field, 8> stateField{};
1240 auto rc = decode_get_state_sensor_readings_resp(
1241 responsePtr, payloadLength, &completionCode, &compSensorCount,
1242 stateField.data());
1243
1244 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1245 {
1246 std::cerr << "Response Message Error: "
1247 << "rc=" << rc << ",cc=" << (int)completionCode
1248 << std::endl;
1249 return;
1250 }
1251 ordered_json output;
1252 output["compositeSensorCount"] = (int)compSensorCount;
1253
1254 for (size_t i = 0; i < compSensorCount; i++)
1255 {
George Liubd5e2ea2021-04-22 20:33:06 +08001256 if (sensorOpState.contains(stateField[i].sensor_op_state))
1257 {
1258 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1259 sensorOpState.at(stateField[i].sensor_op_state));
1260 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001261
George Liubd5e2ea2021-04-22 20:33:06 +08001262 if (sensorPresState.contains(stateField[i].present_state))
1263 {
1264 output.emplace(("presentState[" + std::to_string(i) + "]"),
1265 sensorPresState.at(stateField[i].present_state));
1266 }
1267
1268 if (sensorPresState.contains(stateField[i].previous_state))
1269 {
1270 output.emplace(
1271 ("previousState[" + std::to_string(i) + "]"),
1272 sensorPresState.at(stateField[i].previous_state));
1273 }
1274
1275 if (sensorPresState.contains(stateField[i].event_state))
1276 {
1277 output.emplace(("eventState[" + std::to_string(i) + "]"),
1278 sensorPresState.at(stateField[i].event_state));
1279 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001280 }
1281
1282 pldmtool::helper::DisplayInJson(output);
1283 }
1284
1285 private:
1286 uint16_t sensorId;
1287 uint8_t sensorRearm;
1288};
1289
George Liud6649362019-11-27 19:06:51 +08001290void registerCommand(CLI::App& app)
1291{
1292 auto platform = app.add_subcommand("platform", "platform type command");
1293 platform->require_subcommand(1);
1294
1295 auto getPDR =
1296 platform->add_subcommand("GetPDR", "get platform descriptor records");
1297 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
1298
1299 auto setStateEffecterStates = platform->add_subcommand(
1300 "SetStateEffecterStates", "set effecter states");
1301 commands.push_back(std::make_unique<SetStateEffecter>(
1302 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08001303
1304 auto setNumericEffecterValue = platform->add_subcommand(
1305 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
1306 commands.push_back(std::make_unique<SetNumericEffecterValue>(
1307 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001308
1309 auto getStateSensorReadings = platform->add_subcommand(
1310 "GetStateSensorReadings", "get the state sensor readings");
1311 commands.push_back(std::make_unique<GetStateSensorReadings>(
1312 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +08001313}
1314
1315} // namespace platform
1316} // namespace pldmtool