blob: aac669a6d0b2fee66b5b629a01ac52e4fd0c644b [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
Brad Bishop02d71142021-10-14 19:00:17 -04007#include <cstddef>
8#include <map>
9
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -050010#ifdef OEM_IBM
11#include "oem/ibm/oem_ibm_state_set.hpp"
12#endif
13
Brad Bishop5079ac42021-08-19 18:35:06 -040014using namespace pldm::utils;
15
George Liud6649362019-11-27 19:06:51 +080016namespace pldmtool
17{
18
19namespace platform
20{
21
22namespace
23{
24
25using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060026
27static const std::map<uint8_t, std::string> sensorPresState{
28 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
29 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
30 {PLDM_SENSOR_WARNING, "Sensor Warning"},
31 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
32 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
33 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
34 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
35 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
36 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
37 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
38 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
39
40static const std::map<uint8_t, std::string> sensorOpState{
41 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
42 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
43 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
44 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
45 {PLDM_SENSOR_FAILED, "Sensor Failed"},
46 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Intializing"},
47 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
48 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
49
George Liud6649362019-11-27 19:06:51 +080050std::vector<std::unique_ptr<CommandInterface>> commands;
51
52} // namespace
53
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050054using ordered_json = nlohmann::ordered_json;
55
George Liud6649362019-11-27 19:06:51 +080056class GetPDR : public CommandInterface
57{
58 public:
59 ~GetPDR() = default;
60 GetPDR() = delete;
61 GetPDR(const GetPDR&) = delete;
62 GetPDR(GetPDR&&) = default;
63 GetPDR& operator=(const GetPDR&) = delete;
64 GetPDR& operator=(GetPDR&&) = default;
65
66 using CommandInterface::CommandInterface;
67
George Liud6649362019-11-27 19:06:51 +080068 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
69 CommandInterface(type, name, app)
70 {
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -050071 auto pdrOptionGroup = app->add_option_group(
72 "Required Option",
73 "Retrieve individual PDR, all PDRs, or PDRs of a requested type");
74 pdrOptionGroup->add_option(
75 "-d,--data", recordHandle,
76 "retrieve individual PDRs from a PDR Repository\n"
77 "eg: The recordHandle value for the PDR to be retrieved and 0 "
78 "means get first PDR in the repository.");
79 pdrRecType = "";
80 pdrOptionGroup->add_option("-t, --type", pdrRecType,
81 "retrieve all PDRs of the requested type\n"
82 "supported types:\n"
83 "[terminusLocator, stateSensor, "
84 "numericEffecter, stateEffecter, "
85 "EntityAssociation, fruRecord, ... ]");
86 allPDRs = false;
87 pdrOptionGroup->add_flag("-a, --all", allPDRs,
88 "retrieve all PDRs from a PDR repository");
89 pdrOptionGroup->require_option(1);
90 }
91
92 void exec() override
93 {
94 if (allPDRs || !pdrRecType.empty())
95 {
96 if (!pdrRecType.empty())
97 {
98 std::transform(pdrRecType.begin(), pdrRecType.end(),
99 pdrRecType.begin(), tolower);
100 }
101
102 // Retrieve all PDR records starting from the first
103 recordHandle = 0;
104 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400105 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500106 do
107 {
108 CommandInterface::exec();
109 // recordHandle is updated to nextRecord when
110 // CommandInterface::exec() is successful.
111 // In case of any error, return.
112 if (recordHandle == prevRecordHandle)
113 {
114 return;
115 }
Brad Bishop02d71142021-10-14 19:00:17 -0400116
117 // check for circular references.
118 auto result =
119 recordsSeen.emplace(recordHandle, prevRecordHandle);
120 if (!result.second)
121 {
122 std::cerr
123 << "Record handle " << recordHandle
124 << " has multiple references: " << result.first->second
125 << ", " << prevRecordHandle << "\n";
126 return;
127 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500128 prevRecordHandle = recordHandle;
129 } while (recordHandle != 0);
130 }
131 else
132 {
133 CommandInterface::exec();
134 }
George Liud6649362019-11-27 19:06:51 +0800135 }
136
137 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
138 {
139 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
140 PLDM_GET_PDR_REQ_BYTES);
141 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
142
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500143 auto rc =
144 encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
145 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800146 return {rc, requestMsg};
147 }
148
149 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
150 {
151 uint8_t completionCode = 0;
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500152 uint8_t recordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800153 uint32_t nextRecordHndl = 0;
154 uint32_t nextDataTransferHndl = 0;
155 uint8_t transferFlag = 0;
156 uint16_t respCnt = 0;
157 uint8_t transferCRC = 0;
158
159 auto rc = decode_get_pdr_resp(
160 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
161 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
162 sizeof(recordData), &transferCRC);
163
164 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
165 {
166 std::cerr << "Response Message Error: "
167 << "rc=" << rc << ",cc=" << (int)completionCode
168 << std::endl;
169 return;
170 }
171
George Liu62d12ec2020-02-05 16:27:08 +0800172 printPDRMsg(nextRecordHndl, respCnt, recordData);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500173 recordHandle = nextRecordHndl;
George Liud6649362019-11-27 19:06:51 +0800174 }
175
176 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530177 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530178 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
179 {PLDM_ENTITY_OTHER, "Other"},
180 {PLDM_ENTITY_NETWORK, "Network"},
181 {PLDM_ENTITY_GROUP, "Group"},
182 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
183 "Remote Management Communication Device"},
184 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
185 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
186 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
187 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
188 {PLDM_ENTITY_KEYPAD, "keypad"},
189 {PLDM_ENTITY_SWITCH, "Switch"},
190 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
191 {PLDM_ENTITY_DISPLAY, "Display"},
192 {PLDM_ENTITY_INDICATOR, "Indicator"},
193 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530194 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530195 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530196 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530197 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
198 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
199 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530200 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530201 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
202 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
203 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
204 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
205 {PLDM_ENTITY_DOOR, "Door"},
206 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
207 {PLDM_ENTITY_COVER, "Cover"},
208 {PLDM_ENTITY_BOARD, "Board"},
209 {PLDM_ENTITY_CARD, "Card"},
210 {PLDM_ENTITY_MODULE, "Module"},
211 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530212 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530213 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530214 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
215 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530216 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530217 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530218 "Chassis front panel board(control panel)"},
219 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
220 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
221 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
222 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
223 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
224 "System internal expansion board"},
225 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
226 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
227 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
228 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
229 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
230 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
231 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
232 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
233 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
234 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500235 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530236 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
237 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
238 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
239 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
240 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
241 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
242 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
243 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
244 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
245 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500246 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530247 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
248 {PLDM_ENTITY_BATTERY, "Battery"},
249 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
250 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
251 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
252 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
253 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
254 {PLDM_ENTITY_PROC, "Processor"},
255 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
256 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
257 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
258 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
259 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
260 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
261 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
262 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
263 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
264 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
265 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500266 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530267 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
268 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
269 {PLDM_ENTITY_SYS_BUS, "System Bus"},
270 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
271 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
272 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
273 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
274 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
275 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
276 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
277 {PLDM_ENTITY_USB_BUS, "USB Bus"},
278 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
279 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
280 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
281 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
282 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
283 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500284 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530285 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
286 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
287 {PLDM_ENTITY_PLUG, "Plug"},
288 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500289 {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"},
290 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500291
Tom Josepha65c0412020-07-03 21:14:44 +0530292 const std::map<uint16_t, std::string> stateSet = {
293 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
294 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530295 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
296 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
297 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
298 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
299 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530300 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530301 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
302 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530303 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
304 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530305 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
306 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530307 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530308 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530309 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530310 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
311 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
312 {PLDM_STATE_SET_VERSION, "Version"},
313 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
314 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
315 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
316 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530317 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530318 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
319 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
320 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
321 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
322 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
323 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
324 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
325 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
326 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
327 "Physical Communication Connection"},
328 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
329 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
330 "Foreign Network Detection Status"},
331 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
332 "Password-Protected Access Security"},
333 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
334 "Security Access –PrivilegeLevel"},
335 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530336 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530337 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530338 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530339 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
340 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
341 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530342 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530343 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
344 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
345 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
346 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
347 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
348 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
349 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
350 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
351 "Diagnostic Interrupt Requested"},
352 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
353 "Diagnostic Interrupt Received"},
354 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
355 "I/O Channel Check NMI Requested"},
356 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
357 "I/O Channel Check NMI Received"},
358 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
359 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
360 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
361 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
362 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
363 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
364 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
365 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
366 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
367 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
368 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
369 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
370 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
371 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
372 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
373 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
374 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
375 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
376 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
377 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
378 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
379 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
380 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
381 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
382 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
383 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
384 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
385 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
386 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
387 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
388 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
389 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
390 "Redundant Memory Activity Status"},
391 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
392 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
393 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
394 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500395 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
396 };
Tom Josepha65c0412020-07-03 21:14:44 +0530397
398 const std::array<std::string_view, 4> sensorInit = {
399 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
400
Tom Joseph97a7a762020-07-06 10:37:18 +0530401 const std::array<std::string_view, 4> effecterInit = {
402 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
403
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500404 const std::map<uint8_t, std::string> pdrType = {
405 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
406 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
407 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
408 "Numeric Sensor Initialization PDR"},
409 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
410 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
411 "State Sensor Initialization PDR"},
412 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
413 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
414 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
415 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
416 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
417 "Numeric Effecter Initialization PDR"},
418 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
419 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
420 "State Effecter Initialization PDR"},
421 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
422 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
423 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
424 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
425 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
426 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
427 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
428 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
429 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
430 {PLDM_OEM_PDR, "OEM PDR"},
431 };
432
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500433 static inline const std::map<uint8_t, std::string> setThermalTrip{
434 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
435 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
436
437 static inline const std::map<uint8_t, std::string> setIdentifyState{
438 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
439 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
440
441 static inline const std::map<uint8_t, std::string> setBootProgressState{
442 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
443 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
444 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
445 "Memory Initialization"},
446 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
447 "Secondary Processor(s) Initialization"},
448 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
449 "PCI Resource Configuration"},
450 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
451 "Starting Operating System"},
452 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
453 "Baseboard Initialization"},
454 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
455 "Primary Processor Initialization"}};
456
457 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
458 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
459 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED, "Stressed"}};
460
461 static inline const std::map<uint8_t, std::string> setSysPowerState{
462 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
463 "Off-Soft Graceful"}};
464
465 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
466 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
467 "Graceful Restart Requested"}};
468
469 static inline const std::map<uint8_t, std::string> setAvailability{
470 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
471
472 static inline const std::map<uint8_t, std::string> setHealthState{
473 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
474 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
475 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"}};
476
477 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
478 populatePStateMaps{
479 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
480 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
481 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
482 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
483 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
484 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
485 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
486 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
487 };
488
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500489 const std::map<std::string, uint8_t> strToPdrType = {
490 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
491 {"statesensor", PLDM_STATE_SENSOR_PDR},
492 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
493 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
494 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
495 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
496 // Add other types
497 };
498
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530499 bool isLogicalBitSet(const uint16_t entity_type)
500 {
501 return entity_type & 0x8000;
502 }
503
504 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
505 {
506 return logical_entity_type & 0x7FFF;
507 }
508
Tom Josepha65c0412020-07-03 21:14:44 +0530509 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500510 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530511 uint16_t entityNumber = type;
512 std::string entityName = "[Physical] ";
513
514 if (isLogicalBitSet(type))
515 {
516 entityName = "[Logical] ";
517 entityNumber = getEntityTypeForLogicalEntity(type);
518 }
519
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500520 try
521 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530522 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500523 }
524 catch (const std::out_of_range& e)
525 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500526 auto OemString =
527 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530528 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
529 type <= PLDM_OEM_ENTITY_TYPE_END)
530 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500531#ifdef OEM_IBM
532 if (OemIBMEntityType.contains(entityNumber))
533 {
534 return entityName + OemIBMEntityType.at(entityNumber) +
535 "(OEM)";
536 }
537#endif
538 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530539 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500540 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500541 }
542 }
543
Tom Josepha65c0412020-07-03 21:14:44 +0530544 std::string getStateSetName(uint16_t id)
545 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500546 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530547 try
548 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500549 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530550 }
551 catch (const std::out_of_range& e)
552 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500553 return typeString;
554 }
555 }
556
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500557 std::vector<std::string>
558 getStateSetPossibleStateNames(uint16_t stateId,
559 const std::vector<uint8_t>& value)
560 {
561 std::vector<std::string> data{};
562 std::map<uint8_t, std::string> stateNameMaps;
563
564 for (auto& s : value)
565 {
566 std::map<uint8_t, std::string> stateNameMaps;
567 auto pstr = std::to_string(s);
568
569#ifdef OEM_IBM
570 if (stateId >= PLDM_OEM_STATE_SET_START &&
571 stateId <= PLDM_OEM_STATE_SET_END)
572 {
573 if (populateOemIBMStateMaps.contains(stateId))
574 {
575 const std::map<uint8_t, std::string> stateNames =
576 populateOemIBMStateMaps.at(stateId);
577 stateNameMaps.insert(stateNames.begin(), stateNames.end());
578 }
579 }
580#endif
581 if (populatePStateMaps.contains(stateId))
582 {
583 const std::map<uint8_t, std::string> stateNames =
584 populatePStateMaps.at(stateId);
585 stateNameMaps.insert(stateNames.begin(), stateNames.end());
586 }
587 if (stateNameMaps.contains(s))
588 {
589 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
590 }
591 else
592 {
593 data.push_back(pstr);
594 }
595 }
596 return data;
597 }
598
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500599 std::string getPDRType(uint8_t type)
600 {
601 auto typeString = std::to_string(type);
602 try
603 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500604 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500605 }
606 catch (const std::out_of_range& e)
607 {
608 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530609 }
610 }
611
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500612 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530613 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500614 output["recordHandle"] = hdr->record_handle;
615 output["PDRHeaderVersion"] = unsigned(hdr->version);
616 output["PDRType"] = getPDRType(hdr->type);
617 output["recordChangeNumber"] = hdr->record_change_num;
618 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530619 }
620
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500621 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
622 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530623 {
624 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500625 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500626 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
627 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530628 for (int i = 0; i < CHAR_BIT; i++)
629 {
630 if (val.byte & (1 << i))
631 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500632 pstates << (possibleStatesPos * CHAR_BIT + i);
633 data.push_back(
634 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600635 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530636 }
637 }
638 possibleStatesPos++;
639 };
640 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500641 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530642 }
643
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500644 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530645 {
646 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500647 output["PLDMTerminusHandle"] = pdr->terminus_handle;
648 output["sensorID"] = pdr->sensor_id;
649 output["entityType"] = getEntityName(pdr->entity_type);
650 output["entityInstanceNumber"] = pdr->entity_instance;
651 output["containerID"] = pdr->container_id;
652 output["sensorInit"] = sensorInit[pdr->sensor_init];
653 output["sensorAuxiliaryNamesPDR"] =
654 (pdr->sensor_auxiliary_names_pdr ? true : false);
655 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530656
657 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600658 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530659
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600660 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530661 {
662 auto state = reinterpret_cast<const state_sensor_possible_states*>(
663 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600664 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
665 getStateSetName(state->state_set_id));
666 output.emplace(
667 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
668 state->possible_states_size);
669 output.emplace(
670 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500671 getStateSetPossibleStateNames(
672 state->state_set_id,
673 printPossibleStates(state->possible_states_size,
674 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530675
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600676 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530677 {
678 statesPtr += sizeof(state_sensor_possible_states) +
679 state->possible_states_size - 1;
680 }
681 }
682 }
683
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500684 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500685 {
George Liu62d12ec2020-02-05 16:27:08 +0800686 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500687 {
688 return;
689 }
690
691 data += sizeof(pldm_pdr_hdr);
692 pldm_pdr_fru_record_set* pdr =
693 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530694 if (!pdr)
695 {
696 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
697 return;
698 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500699
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500700 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
701 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
702 output["entityType"] = getEntityName(pdr->entity_type);
703 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
704 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500705 }
706
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500707 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500708 {
709 const std::map<uint8_t, const char*> assocationType = {
710 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
711 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
712 };
713
George Liu62d12ec2020-02-05 16:27:08 +0800714 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500715 {
716 return;
717 }
718
719 data += sizeof(pldm_pdr_hdr);
720 pldm_pdr_entity_association* pdr =
721 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530722 if (!pdr)
723 {
724 std::cerr << "Failed to get the PDR eneity association"
725 << std::endl;
726 return;
727 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500728
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500729 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800730 if (assocationType.contains(pdr->association_type))
731 {
732 output["associationType"] =
733 assocationType.at(pdr->association_type);
734 }
735 else
736 {
737 std::cout << "Get associationType failed.\n";
738 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500739 output["containerEntityType"] =
740 getEntityName(pdr->container.entity_type);
741 output["containerEntityInstanceNumber"] =
742 int(pdr->container.entity_instance_num);
743 output["containerEntityContainerID"] =
744 int(pdr->container.entity_container_id);
745 output["containedEntityCount"] =
746 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500747
748 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
749 for (int i = 0; i < pdr->num_children; ++i)
750 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500751 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
752 getEntityName(child->entity_type));
753 output.emplace("containedEntityInstanceNumber[" +
754 std::to_string(i + 1) + "]",
755 unsigned(child->entity_instance_num));
756 output.emplace("containedEntityContainerID[" +
757 std::to_string(i + 1) + "]",
758 unsigned(child->entity_container_id));
759
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500760 ++child;
761 }
762 }
763
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500764 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800765 {
766 struct pldm_numeric_effecter_value_pdr* pdr =
767 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530768 if (!pdr)
769 {
770 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
771 return;
772 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500773
774 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
775 output["effecterID"] = int(pdr->effecter_id);
776 output["entityType"] = int(pdr->entity_type);
777 output["entityInstanceNumber"] = int(pdr->entity_instance);
778 output["containerID"] = int(pdr->container_id);
779 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
780 output["effecterInit"] = unsigned(pdr->effecter_init);
781 output["effecterAuxiliaryNames"] =
782 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
783 output["baseUnit"] = unsigned(pdr->base_unit);
784 output["unitModifier"] = unsigned(pdr->unit_modifier);
785 output["rateUnit"] = unsigned(pdr->rate_unit);
786 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
787 output["auxUnit"] = unsigned(pdr->aux_unit);
788 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
789 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
790 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
791 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
792 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
793 output["resolution"] = unsigned(pdr->resolution);
794 output["offset"] = unsigned(pdr->offset);
795 output["accuracy"] = unsigned(pdr->accuracy);
796 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
797 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
798 output["stateTransitionInterval"] =
799 unsigned(pdr->state_transition_interval);
800 output["TransitionInterval"] = unsigned(pdr->transition_interval);
801
George Liu62d12ec2020-02-05 16:27:08 +0800802 switch (pdr->effecter_data_size)
803 {
804 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500805 output["maxSettable"] = unsigned(pdr->max_set_table.value_u8);
806 output["minSettable"] = unsigned(pdr->min_set_table.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800807 break;
808 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500809 output["maxSettable"] = unsigned(pdr->max_set_table.value_s8);
810 output["minSettable"] = unsigned(pdr->min_set_table.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800811 break;
812 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500813 output["maxSettable"] = unsigned(pdr->max_set_table.value_u16);
814 output["minSettable"] = unsigned(pdr->min_set_table.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800815 break;
816 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500817 output["maxSettable"] = unsigned(pdr->max_set_table.value_s16);
818 output["minSettable"] = unsigned(pdr->min_set_table.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800819 break;
820 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500821 output["maxSettable"] = unsigned(pdr->max_set_table.value_u32);
822 output["minSettable"] = unsigned(pdr->min_set_table.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800823 break;
824 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500825 output["maxSettable"] = unsigned(pdr->max_set_table.value_s32);
826 output["minSettable"] = unsigned(pdr->min_set_table.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800827 break;
828 default:
829 break;
830 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500831
832 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
833 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
834
George Liu62d12ec2020-02-05 16:27:08 +0800835 switch (pdr->range_field_format)
836 {
837 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500838 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
839 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
840 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
841 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
842 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800843 break;
844 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500845 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
846 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
847 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
848 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
849 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800850 break;
851 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500852 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
853 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
854 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
855 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
856 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800857 break;
858 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500859 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
860 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
861 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
862 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
863 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800864 break;
865 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500866 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
867 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
868 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
869 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
870 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800871 break;
872 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500873 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
874 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
875 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
876 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
877 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800878 break;
879 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500880 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
881 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
882 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
883 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
884 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800885 break;
886 default:
887 break;
888 }
889 }
890
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500891 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800892 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530893 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800894
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500895 output["PLDMTerminusHandle"] = pdr->terminus_handle;
896 output["effecterID"] = pdr->effecter_id;
897 output["entityType"] = getEntityName(pdr->entity_type);
898 output["entityInstanceNumber"] = pdr->entity_instance;
899 output["containerID"] = pdr->container_id;
900 output["effecterSemanticID"] = pdr->effecter_semantic_id;
901 output["effecterInit"] = effecterInit[pdr->effecter_init];
902 output["effecterDescriptionPDR"] =
903 (pdr->has_description_pdr ? true : false);
904 output["compositeEffecterCount"] =
905 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +0800906
Tom Joseph97a7a762020-07-06 10:37:18 +0530907 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600908 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +0530909
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600910 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +0800911 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530912 auto state =
913 reinterpret_cast<const state_effecter_possible_states*>(
914 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600915 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
916 getStateSetName(state->state_set_id));
917 output.emplace(
918 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
919 state->possible_states_size);
920 output.emplace(
921 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500922 getStateSetPossibleStateNames(
923 state->state_set_id,
924 printPossibleStates(state->possible_states_size,
925 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500926
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600927 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +0530928 {
929 statesPtr += sizeof(state_effecter_possible_states) +
930 state->possible_states_size - 1;
931 }
George Liud6649362019-11-27 19:06:51 +0800932 }
933 }
934
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500935 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -0500936 {
937 const std::array<std::string_view, 4> terminusLocatorType = {
938 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
939
940 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
941
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500942 output["PLDMTerminusHandle"] = pdr->terminus_handle;
943 output["validity"] = (pdr->validity ? "valid" : "notValid");
944 output["TID"] = unsigned(pdr->tid);
945 output["containerID"] = pdr->container_id;
946 output["terminusLocatorType"] =
947 terminusLocatorType[pdr->terminus_locator_type];
948 output["terminusLocatorValueSize"] =
949 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -0500950
951 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
952 {
953 auto locatorValue =
954 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
955 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500956 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -0500957 }
958 }
959
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500960 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
George Liu62d12ec2020-02-05 16:27:08 +0800961 uint8_t* data)
George Liud6649362019-11-27 19:06:51 +0800962 {
George Liu62d12ec2020-02-05 16:27:08 +0800963 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800964 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530965 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +0800966 return;
967 }
968
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500969 ordered_json output;
970 output["nextRecordHandle"] = nextRecordHndl;
971 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +0800972
973 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530974 if (!pdr)
975 {
976 return;
977 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500978
979 if (!pdrRecType.empty())
980 {
981 // Need to return if the requested PDR type
982 // is not supported
983 if (!strToPdrType.contains(pdrRecType))
984 {
985 std::cerr << "PDR type '" << pdrRecType
986 << "' is not supported or invalid\n";
987 // PDR type not supported, setting next record handle to 0
988 // to avoid looping through all PDR records
989 nextRecordHndl = 0;
990 return;
991 }
992
993 // Do not print PDR record if the current record
994 // PDR type does not match with requested type
995 if (pdr->type != strToPdrType.at(pdrRecType))
996 {
997 return;
998 }
999 }
1000
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001001 printCommonPDRHeader(pdr, output);
1002
George Liud6649362019-11-27 19:06:51 +08001003 switch (pdr->type)
1004 {
Sampa Misra12afe112020-05-25 11:40:44 -05001005 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001006 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001007 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301008 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001009 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301010 break;
George Liu62d12ec2020-02-05 16:27:08 +08001011 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001012 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001013 break;
George Liud6649362019-11-27 19:06:51 +08001014 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001015 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001016 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001017 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001018 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001019 break;
1020 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001021 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001022 break;
George Liud6649362019-11-27 19:06:51 +08001023 default:
1024 break;
1025 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001026 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001027 }
1028
1029 private:
1030 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001031 bool allPDRs;
1032 std::string pdrRecType;
George Liud6649362019-11-27 19:06:51 +08001033};
1034
1035class SetStateEffecter : public CommandInterface
1036{
1037 public:
1038 ~SetStateEffecter() = default;
1039 SetStateEffecter() = delete;
1040 SetStateEffecter(const SetStateEffecter&) = delete;
1041 SetStateEffecter(SetStateEffecter&&) = default;
1042 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
1043 SetStateEffecter& operator=(SetStateEffecter&&) = default;
1044
George Liuba4c1fb2020-02-05 14:13:30 +08001045 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1046 static constexpr auto maxEffecterDataSize = 16;
1047
1048 // compositeEffecterCount(value: 0x01 to 0x08)
1049 static constexpr auto minEffecterCount = 1;
1050 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001051 explicit SetStateEffecter(const char* type, const char* name,
1052 CLI::App* app) :
1053 CommandInterface(type, name, app)
1054 {
1055 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001056 "-i, --id", effecterId,
1057 "A handle that is used to identify and access the effecter")
1058 ->required();
1059 app->add_option("-c, --count", effecterCount,
1060 "The number of individual sets of effecter information")
1061 ->required();
1062 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001063 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001064 "Set effecter state data\n"
1065 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1066 ->required();
George Liud6649362019-11-27 19:06:51 +08001067 }
1068
1069 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1070 {
1071 std::vector<uint8_t> requestMsg(
1072 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
1073 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1074
George Liuba4c1fb2020-02-05 14:13:30 +08001075 if (effecterCount > maxEffecterCount ||
1076 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001077 {
George Liuba4c1fb2020-02-05 14:13:30 +08001078 std::cerr << "Request Message Error: effecterCount size "
1079 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001080 auto rc = PLDM_ERROR_INVALID_DATA;
1081 return {rc, requestMsg};
1082 }
1083
George Liuba4c1fb2020-02-05 14:13:30 +08001084 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001085 {
George Liuba4c1fb2020-02-05 14:13:30 +08001086 std::cerr << "Request Message Error: effecterData size "
1087 << effecterData.size() << "is invalid\n";
1088 auto rc = PLDM_ERROR_INVALID_DATA;
1089 return {rc, requestMsg};
1090 }
1091
1092 auto stateField = parseEffecterData(effecterData, effecterCount);
1093 if (!stateField)
1094 {
1095 std::cerr << "Failed to parse effecter data, effecterCount size "
1096 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001097 auto rc = PLDM_ERROR_INVALID_DATA;
1098 return {rc, requestMsg};
1099 }
1100
1101 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001102 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001103 return {rc, requestMsg};
1104 }
1105
1106 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1107 {
1108 uint8_t completionCode = 0;
1109 auto rc = decode_set_state_effecter_states_resp(
1110 responsePtr, payloadLength, &completionCode);
1111
1112 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1113 {
1114 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001115 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001116 return;
1117 }
1118
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001119 ordered_json data;
1120 data["Response"] = "SUCCESS";
1121 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001122 }
1123
1124 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001125 uint16_t effecterId;
1126 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001127 std::vector<uint8_t> effecterData;
1128};
1129
George Liucc9c20d2020-02-05 10:24:11 +08001130class SetNumericEffecterValue : public CommandInterface
1131{
1132 public:
1133 ~SetNumericEffecterValue() = default;
1134 SetNumericEffecterValue() = delete;
1135 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1136 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1137 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
1138 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default;
1139
1140 explicit SetNumericEffecterValue(const char* type, const char* name,
1141 CLI::App* app) :
1142 CommandInterface(type, name, app)
1143 {
1144 app->add_option(
1145 "-i, --id", effecterId,
1146 "A handle that is used to identify and access the effecter")
1147 ->required();
1148 app->add_option("-s, --size", effecterDataSize,
1149 "The bit width and format of the setting value for the "
1150 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1151 "uint32, sint32}\n")
1152 ->required();
1153 app->add_option("-d,--data", maxEffecterValue,
1154 "The setting value of numeric effecter being "
1155 "requested\n")
1156 ->required();
1157 }
1158
1159 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1160 {
1161 std::vector<uint8_t> requestMsg(
1162 sizeof(pldm_msg_hdr) +
1163 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1164
1165 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1166
1167 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1168 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1169
1170 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1171 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1172 {
1173 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1174 }
1175 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1176 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1177 {
1178 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1179 }
1180 auto rc = encode_set_numeric_effecter_value_req(
1181 0, effecterId, effecterDataSize, effecterValue, request,
1182 payload_length);
1183
1184 return {rc, requestMsg};
1185 }
1186
1187 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1188 {
1189 uint8_t completionCode = 0;
1190 auto rc = decode_set_numeric_effecter_value_resp(
1191 responsePtr, payloadLength, &completionCode);
1192
1193 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1194 {
1195 std::cerr << "Response Message Error: "
1196 << "rc=" << rc << ",cc=" << (int)completionCode
1197 << std::endl;
1198 return;
1199 }
1200
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001201 ordered_json data;
1202 data["Response"] = "SUCCESS";
1203 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001204 }
1205
1206 private:
1207 uint16_t effecterId;
1208 uint8_t effecterDataSize;
1209 uint64_t maxEffecterValue;
1210};
1211
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001212class GetStateSensorReadings : public CommandInterface
1213{
1214 public:
1215 ~GetStateSensorReadings() = default;
1216 GetStateSensorReadings() = delete;
1217 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1218 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1219 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
1220 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default;
1221
1222 explicit GetStateSensorReadings(const char* type, const char* name,
1223 CLI::App* app) :
1224 CommandInterface(type, name, app)
1225 {
1226 app->add_option(
1227 "-i, --sensor_id", sensorId,
1228 "Sensor ID that is used to identify and access the sensor")
1229 ->required();
1230 app->add_option("-r, --rearm", sensorRearm,
1231 "Each bit location in this field corresponds to a "
1232 "particular sensor")
1233 ->required();
1234 }
1235
1236 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1237 {
1238 std::vector<uint8_t> requestMsg(
1239 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
1240 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1241
1242 uint8_t reserved = 0;
1243 bitfield8_t bf;
1244 bf.byte = sensorRearm;
1245 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1246 reserved, request);
1247
1248 return {rc, requestMsg};
1249 }
1250
1251 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1252 {
1253 uint8_t completionCode = 0;
1254 uint8_t compSensorCount = 0;
1255 std::array<get_sensor_state_field, 8> stateField{};
1256 auto rc = decode_get_state_sensor_readings_resp(
1257 responsePtr, payloadLength, &completionCode, &compSensorCount,
1258 stateField.data());
1259
1260 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1261 {
1262 std::cerr << "Response Message Error: "
1263 << "rc=" << rc << ",cc=" << (int)completionCode
1264 << std::endl;
1265 return;
1266 }
1267 ordered_json output;
1268 output["compositeSensorCount"] = (int)compSensorCount;
1269
1270 for (size_t i = 0; i < compSensorCount; i++)
1271 {
George Liubd5e2ea2021-04-22 20:33:06 +08001272 if (sensorOpState.contains(stateField[i].sensor_op_state))
1273 {
1274 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1275 sensorOpState.at(stateField[i].sensor_op_state));
1276 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001277
George Liubd5e2ea2021-04-22 20:33:06 +08001278 if (sensorPresState.contains(stateField[i].present_state))
1279 {
1280 output.emplace(("presentState[" + std::to_string(i) + "]"),
1281 sensorPresState.at(stateField[i].present_state));
1282 }
1283
1284 if (sensorPresState.contains(stateField[i].previous_state))
1285 {
1286 output.emplace(
1287 ("previousState[" + std::to_string(i) + "]"),
1288 sensorPresState.at(stateField[i].previous_state));
1289 }
1290
1291 if (sensorPresState.contains(stateField[i].event_state))
1292 {
1293 output.emplace(("eventState[" + std::to_string(i) + "]"),
1294 sensorPresState.at(stateField[i].event_state));
1295 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001296 }
1297
1298 pldmtool::helper::DisplayInJson(output);
1299 }
1300
1301 private:
1302 uint16_t sensorId;
1303 uint8_t sensorRearm;
1304};
1305
George Liud6649362019-11-27 19:06:51 +08001306void registerCommand(CLI::App& app)
1307{
1308 auto platform = app.add_subcommand("platform", "platform type command");
1309 platform->require_subcommand(1);
1310
1311 auto getPDR =
1312 platform->add_subcommand("GetPDR", "get platform descriptor records");
1313 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
1314
1315 auto setStateEffecterStates = platform->add_subcommand(
1316 "SetStateEffecterStates", "set effecter states");
1317 commands.push_back(std::make_unique<SetStateEffecter>(
1318 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08001319
1320 auto setNumericEffecterValue = platform->add_subcommand(
1321 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
1322 commands.push_back(std::make_unique<SetNumericEffecterValue>(
1323 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001324
1325 auto getStateSensorReadings = platform->add_subcommand(
1326 "GetStateSensorReadings", "get the state sensor readings");
1327 commands.push_back(std::make_unique<GetStateSensorReadings>(
1328 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +08001329}
1330
1331} // namespace platform
1332} // namespace pldmtool