blob: 694528554824a2b91555113c2eda02921029c85c [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
Brad Bishop16eff862021-10-14 19:44:32 -0400102 // start the array
103 std::cout << "[\n";
104
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500105 // Retrieve all PDR records starting from the first
106 recordHandle = 0;
107 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400108 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500109 do
110 {
111 CommandInterface::exec();
112 // recordHandle is updated to nextRecord when
113 // CommandInterface::exec() is successful.
114 // In case of any error, return.
115 if (recordHandle == prevRecordHandle)
116 {
117 return;
118 }
Brad Bishop02d71142021-10-14 19:00:17 -0400119
120 // check for circular references.
121 auto result =
122 recordsSeen.emplace(recordHandle, prevRecordHandle);
123 if (!result.second)
124 {
125 std::cerr
126 << "Record handle " << recordHandle
127 << " has multiple references: " << result.first->second
128 << ", " << prevRecordHandle << "\n";
129 return;
130 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500131 prevRecordHandle = recordHandle;
Brad Bishop16eff862021-10-14 19:44:32 -0400132
133 if (recordHandle != 0)
134 {
135 // close the array
136 std::cout << ",";
137 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500138 } while (recordHandle != 0);
Brad Bishop16eff862021-10-14 19:44:32 -0400139
140 // close the array
141 std::cout << "]\n";
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500142 }
143 else
144 {
145 CommandInterface::exec();
146 }
George Liud6649362019-11-27 19:06:51 +0800147 }
148
149 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
150 {
151 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) +
152 PLDM_GET_PDR_REQ_BYTES);
153 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
154
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500155 auto rc =
156 encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART,
157 UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800158 return {rc, requestMsg};
159 }
160
161 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
162 {
163 uint8_t completionCode = 0;
Deepak Kodihallia59cdc62020-07-14 05:11:33 -0500164 uint8_t recordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800165 uint32_t nextRecordHndl = 0;
166 uint32_t nextDataTransferHndl = 0;
167 uint8_t transferFlag = 0;
168 uint16_t respCnt = 0;
169 uint8_t transferCRC = 0;
170
171 auto rc = decode_get_pdr_resp(
172 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
173 &nextDataTransferHndl, &transferFlag, &respCnt, recordData,
174 sizeof(recordData), &transferCRC);
175
176 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
177 {
178 std::cerr << "Response Message Error: "
179 << "rc=" << rc << ",cc=" << (int)completionCode
180 << std::endl;
181 return;
182 }
183
George Liu62d12ec2020-02-05 16:27:08 +0800184 printPDRMsg(nextRecordHndl, respCnt, recordData);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500185 recordHandle = nextRecordHndl;
George Liud6649362019-11-27 19:06:51 +0800186 }
187
188 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530189 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530190 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
191 {PLDM_ENTITY_OTHER, "Other"},
192 {PLDM_ENTITY_NETWORK, "Network"},
193 {PLDM_ENTITY_GROUP, "Group"},
194 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
195 "Remote Management Communication Device"},
196 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
197 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
198 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
199 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
200 {PLDM_ENTITY_KEYPAD, "keypad"},
201 {PLDM_ENTITY_SWITCH, "Switch"},
202 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
203 {PLDM_ENTITY_DISPLAY, "Display"},
204 {PLDM_ENTITY_INDICATOR, "Indicator"},
205 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530206 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530207 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530208 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530209 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
210 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
211 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530212 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530213 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
214 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
215 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
216 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
217 {PLDM_ENTITY_DOOR, "Door"},
218 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
219 {PLDM_ENTITY_COVER, "Cover"},
220 {PLDM_ENTITY_BOARD, "Board"},
221 {PLDM_ENTITY_CARD, "Card"},
222 {PLDM_ENTITY_MODULE, "Module"},
223 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530224 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530225 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530226 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
227 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530228 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530229 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530230 "Chassis front panel board(control panel)"},
231 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
232 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
233 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
234 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
235 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
236 "System internal expansion board"},
237 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
238 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
239 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
240 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
241 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
242 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
243 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
244 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
245 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
246 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500247 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530248 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
249 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
250 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
251 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
252 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
253 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
254 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
255 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
256 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
257 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500258 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530259 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
260 {PLDM_ENTITY_BATTERY, "Battery"},
261 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
262 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
263 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
264 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
265 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
266 {PLDM_ENTITY_PROC, "Processor"},
267 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
268 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
269 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
270 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
271 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
272 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
273 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
274 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
275 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
276 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
277 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500278 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530279 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
280 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
281 {PLDM_ENTITY_SYS_BUS, "System Bus"},
282 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
283 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
284 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
285 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
286 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
287 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
288 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
289 {PLDM_ENTITY_USB_BUS, "USB Bus"},
290 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
291 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
292 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
293 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
294 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
295 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500296 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530297 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
298 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
299 {PLDM_ENTITY_PLUG, "Plug"},
300 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500301 {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"},
302 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500303
Tom Josepha65c0412020-07-03 21:14:44 +0530304 const std::map<uint16_t, std::string> stateSet = {
305 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
306 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530307 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
308 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
309 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
310 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
311 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530312 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530313 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
314 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530315 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
316 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530317 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
318 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530319 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530320 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530321 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530322 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
323 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
324 {PLDM_STATE_SET_VERSION, "Version"},
325 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
326 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
327 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
328 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530329 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530330 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
331 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
332 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
333 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
334 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
335 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
336 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
337 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
338 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
339 "Physical Communication Connection"},
340 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
341 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
342 "Foreign Network Detection Status"},
343 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
344 "Password-Protected Access Security"},
345 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
346 "Security Access –PrivilegeLevel"},
347 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530348 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530349 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530350 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530351 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
352 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
353 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530354 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530355 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
356 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
357 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
358 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
359 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
360 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
361 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
362 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
363 "Diagnostic Interrupt Requested"},
364 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
365 "Diagnostic Interrupt Received"},
366 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
367 "I/O Channel Check NMI Requested"},
368 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
369 "I/O Channel Check NMI Received"},
370 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
371 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
372 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
373 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
374 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
375 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
376 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
377 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
378 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
379 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
380 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
381 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
382 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
383 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
384 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
385 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
386 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
387 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
388 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
389 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
390 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
391 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
392 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
393 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
394 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
395 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
396 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
397 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
398 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
399 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
400 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
401 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
402 "Redundant Memory Activity Status"},
403 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
404 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
405 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
406 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500407 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
408 };
Tom Josepha65c0412020-07-03 21:14:44 +0530409
410 const std::array<std::string_view, 4> sensorInit = {
411 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
412
Tom Joseph97a7a762020-07-06 10:37:18 +0530413 const std::array<std::string_view, 4> effecterInit = {
414 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
415
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500416 const std::map<uint8_t, std::string> pdrType = {
417 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
418 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
419 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
420 "Numeric Sensor Initialization PDR"},
421 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
422 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
423 "State Sensor Initialization PDR"},
424 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
425 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
426 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
427 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
428 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
429 "Numeric Effecter Initialization PDR"},
430 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
431 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
432 "State Effecter Initialization PDR"},
433 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
434 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
435 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
436 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
437 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
438 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
439 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
440 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
441 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
442 {PLDM_OEM_PDR, "OEM PDR"},
443 };
444
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500445 static inline const std::map<uint8_t, std::string> setThermalTrip{
446 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
447 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
448
449 static inline const std::map<uint8_t, std::string> setIdentifyState{
450 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
451 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
452
453 static inline const std::map<uint8_t, std::string> setBootProgressState{
454 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
455 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
456 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
457 "Memory Initialization"},
458 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
459 "Secondary Processor(s) Initialization"},
460 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
461 "PCI Resource Configuration"},
462 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
463 "Starting Operating System"},
464 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
465 "Baseboard Initialization"},
466 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
467 "Primary Processor Initialization"}};
468
469 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
470 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
471 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_STRESSED, "Stressed"}};
472
473 static inline const std::map<uint8_t, std::string> setSysPowerState{
474 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
475 "Off-Soft Graceful"}};
476
477 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
478 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
479 "Graceful Restart Requested"}};
480
481 static inline const std::map<uint8_t, std::string> setAvailability{
482 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
483
484 static inline const std::map<uint8_t, std::string> setHealthState{
485 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
486 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
487 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"}};
488
489 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
490 populatePStateMaps{
491 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
492 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
493 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
494 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
495 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
496 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
497 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
498 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
499 };
500
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500501 const std::map<std::string, uint8_t> strToPdrType = {
502 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
503 {"statesensor", PLDM_STATE_SENSOR_PDR},
504 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
505 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
506 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
507 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
508 // Add other types
509 };
510
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530511 bool isLogicalBitSet(const uint16_t entity_type)
512 {
513 return entity_type & 0x8000;
514 }
515
516 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
517 {
518 return logical_entity_type & 0x7FFF;
519 }
520
Tom Josepha65c0412020-07-03 21:14:44 +0530521 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500522 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530523 uint16_t entityNumber = type;
524 std::string entityName = "[Physical] ";
525
526 if (isLogicalBitSet(type))
527 {
528 entityName = "[Logical] ";
529 entityNumber = getEntityTypeForLogicalEntity(type);
530 }
531
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500532 try
533 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530534 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500535 }
536 catch (const std::out_of_range& e)
537 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500538 auto OemString =
539 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530540 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
541 type <= PLDM_OEM_ENTITY_TYPE_END)
542 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500543#ifdef OEM_IBM
544 if (OemIBMEntityType.contains(entityNumber))
545 {
546 return entityName + OemIBMEntityType.at(entityNumber) +
547 "(OEM)";
548 }
549#endif
550 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530551 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500552 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500553 }
554 }
555
Tom Josepha65c0412020-07-03 21:14:44 +0530556 std::string getStateSetName(uint16_t id)
557 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500558 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530559 try
560 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500561 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530562 }
563 catch (const std::out_of_range& e)
564 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500565 return typeString;
566 }
567 }
568
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500569 std::vector<std::string>
570 getStateSetPossibleStateNames(uint16_t stateId,
571 const std::vector<uint8_t>& value)
572 {
573 std::vector<std::string> data{};
574 std::map<uint8_t, std::string> stateNameMaps;
575
576 for (auto& s : value)
577 {
578 std::map<uint8_t, std::string> stateNameMaps;
579 auto pstr = std::to_string(s);
580
581#ifdef OEM_IBM
582 if (stateId >= PLDM_OEM_STATE_SET_START &&
583 stateId <= PLDM_OEM_STATE_SET_END)
584 {
585 if (populateOemIBMStateMaps.contains(stateId))
586 {
587 const std::map<uint8_t, std::string> stateNames =
588 populateOemIBMStateMaps.at(stateId);
589 stateNameMaps.insert(stateNames.begin(), stateNames.end());
590 }
591 }
592#endif
593 if (populatePStateMaps.contains(stateId))
594 {
595 const std::map<uint8_t, std::string> stateNames =
596 populatePStateMaps.at(stateId);
597 stateNameMaps.insert(stateNames.begin(), stateNames.end());
598 }
599 if (stateNameMaps.contains(s))
600 {
601 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
602 }
603 else
604 {
605 data.push_back(pstr);
606 }
607 }
608 return data;
609 }
610
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500611 std::string getPDRType(uint8_t type)
612 {
613 auto typeString = std::to_string(type);
614 try
615 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500616 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500617 }
618 catch (const std::out_of_range& e)
619 {
620 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530621 }
622 }
623
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500624 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530625 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500626 output["recordHandle"] = hdr->record_handle;
627 output["PDRHeaderVersion"] = unsigned(hdr->version);
628 output["PDRType"] = getPDRType(hdr->type);
629 output["recordChangeNumber"] = hdr->record_change_num;
630 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530631 }
632
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500633 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
634 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530635 {
636 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500637 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500638 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
639 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530640 for (int i = 0; i < CHAR_BIT; i++)
641 {
642 if (val.byte & (1 << i))
643 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500644 pstates << (possibleStatesPos * CHAR_BIT + i);
645 data.push_back(
646 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600647 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530648 }
649 }
650 possibleStatesPos++;
651 };
652 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500653 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530654 }
655
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500656 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530657 {
658 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500659 output["PLDMTerminusHandle"] = pdr->terminus_handle;
660 output["sensorID"] = pdr->sensor_id;
661 output["entityType"] = getEntityName(pdr->entity_type);
662 output["entityInstanceNumber"] = pdr->entity_instance;
663 output["containerID"] = pdr->container_id;
664 output["sensorInit"] = sensorInit[pdr->sensor_init];
665 output["sensorAuxiliaryNamesPDR"] =
666 (pdr->sensor_auxiliary_names_pdr ? true : false);
667 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530668
669 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600670 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530671
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600672 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530673 {
674 auto state = reinterpret_cast<const state_sensor_possible_states*>(
675 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600676 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
677 getStateSetName(state->state_set_id));
678 output.emplace(
679 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
680 state->possible_states_size);
681 output.emplace(
682 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500683 getStateSetPossibleStateNames(
684 state->state_set_id,
685 printPossibleStates(state->possible_states_size,
686 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530687
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600688 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530689 {
690 statesPtr += sizeof(state_sensor_possible_states) +
691 state->possible_states_size - 1;
692 }
693 }
694 }
695
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500696 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500697 {
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_fru_record_set* pdr =
705 reinterpret_cast<pldm_pdr_fru_record_set*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530706 if (!pdr)
707 {
708 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
709 return;
710 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500711
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500712 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
713 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
714 output["entityType"] = getEntityName(pdr->entity_type);
715 output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
716 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500717 }
718
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500719 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500720 {
721 const std::map<uint8_t, const char*> assocationType = {
722 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
723 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
724 };
725
George Liu62d12ec2020-02-05 16:27:08 +0800726 if (data == NULL)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500727 {
728 return;
729 }
730
731 data += sizeof(pldm_pdr_hdr);
732 pldm_pdr_entity_association* pdr =
733 reinterpret_cast<pldm_pdr_entity_association*>(data);
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530734 if (!pdr)
735 {
736 std::cerr << "Failed to get the PDR eneity association"
737 << std::endl;
738 return;
739 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500740
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500741 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800742 if (assocationType.contains(pdr->association_type))
743 {
744 output["associationType"] =
745 assocationType.at(pdr->association_type);
746 }
747 else
748 {
749 std::cout << "Get associationType failed.\n";
750 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500751 output["containerEntityType"] =
752 getEntityName(pdr->container.entity_type);
753 output["containerEntityInstanceNumber"] =
754 int(pdr->container.entity_instance_num);
755 output["containerEntityContainerID"] =
756 int(pdr->container.entity_container_id);
757 output["containedEntityCount"] =
758 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500759
760 auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
761 for (int i = 0; i < pdr->num_children; ++i)
762 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500763 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
764 getEntityName(child->entity_type));
765 output.emplace("containedEntityInstanceNumber[" +
766 std::to_string(i + 1) + "]",
767 unsigned(child->entity_instance_num));
768 output.emplace("containedEntityContainerID[" +
769 std::to_string(i + 1) + "]",
770 unsigned(child->entity_container_id));
771
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500772 ++child;
773 }
774 }
775
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500776 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800777 {
778 struct pldm_numeric_effecter_value_pdr* pdr =
779 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530780 if (!pdr)
781 {
782 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
783 return;
784 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500785
786 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
787 output["effecterID"] = int(pdr->effecter_id);
788 output["entityType"] = int(pdr->entity_type);
789 output["entityInstanceNumber"] = int(pdr->entity_instance);
790 output["containerID"] = int(pdr->container_id);
791 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
792 output["effecterInit"] = unsigned(pdr->effecter_init);
793 output["effecterAuxiliaryNames"] =
794 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
795 output["baseUnit"] = unsigned(pdr->base_unit);
796 output["unitModifier"] = unsigned(pdr->unit_modifier);
797 output["rateUnit"] = unsigned(pdr->rate_unit);
798 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
799 output["auxUnit"] = unsigned(pdr->aux_unit);
800 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
801 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
802 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
803 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
804 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
805 output["resolution"] = unsigned(pdr->resolution);
806 output["offset"] = unsigned(pdr->offset);
807 output["accuracy"] = unsigned(pdr->accuracy);
808 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
809 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
810 output["stateTransitionInterval"] =
811 unsigned(pdr->state_transition_interval);
812 output["TransitionInterval"] = unsigned(pdr->transition_interval);
813
George Liu62d12ec2020-02-05 16:27:08 +0800814 switch (pdr->effecter_data_size)
815 {
816 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500817 output["maxSettable"] = unsigned(pdr->max_set_table.value_u8);
818 output["minSettable"] = unsigned(pdr->min_set_table.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800819 break;
820 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500821 output["maxSettable"] = unsigned(pdr->max_set_table.value_s8);
822 output["minSettable"] = unsigned(pdr->min_set_table.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800823 break;
824 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500825 output["maxSettable"] = unsigned(pdr->max_set_table.value_u16);
826 output["minSettable"] = unsigned(pdr->min_set_table.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800827 break;
828 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500829 output["maxSettable"] = unsigned(pdr->max_set_table.value_s16);
830 output["minSettable"] = unsigned(pdr->min_set_table.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800831 break;
832 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500833 output["maxSettable"] = unsigned(pdr->max_set_table.value_u32);
834 output["minSettable"] = unsigned(pdr->min_set_table.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800835 break;
836 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500837 output["maxSettable"] = unsigned(pdr->max_set_table.value_s32);
838 output["minSettable"] = unsigned(pdr->min_set_table.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800839 break;
840 default:
841 break;
842 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500843
844 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
845 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
846
George Liu62d12ec2020-02-05 16:27:08 +0800847 switch (pdr->range_field_format)
848 {
849 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500850 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
851 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
852 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
853 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
854 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +0800855 break;
856 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500857 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
858 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
859 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
860 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
861 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +0800862 break;
863 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500864 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
865 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
866 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
867 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
868 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +0800869 break;
870 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500871 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
872 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
873 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
874 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
875 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +0800876 break;
877 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500878 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
879 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
880 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
881 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
882 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +0800883 break;
884 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500885 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
886 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
887 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
888 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
889 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +0800890 break;
891 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500892 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
893 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
894 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
895 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
896 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +0800897 break;
898 default:
899 break;
900 }
901 }
902
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500903 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +0800904 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530905 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +0800906
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500907 output["PLDMTerminusHandle"] = pdr->terminus_handle;
908 output["effecterID"] = pdr->effecter_id;
909 output["entityType"] = getEntityName(pdr->entity_type);
910 output["entityInstanceNumber"] = pdr->entity_instance;
911 output["containerID"] = pdr->container_id;
912 output["effecterSemanticID"] = pdr->effecter_semantic_id;
913 output["effecterInit"] = effecterInit[pdr->effecter_init];
914 output["effecterDescriptionPDR"] =
915 (pdr->has_description_pdr ? true : false);
916 output["compositeEffecterCount"] =
917 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +0800918
Tom Joseph97a7a762020-07-06 10:37:18 +0530919 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600920 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +0530921
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600922 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +0800923 {
Tom Joseph97a7a762020-07-06 10:37:18 +0530924 auto state =
925 reinterpret_cast<const state_effecter_possible_states*>(
926 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600927 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
928 getStateSetName(state->state_set_id));
929 output.emplace(
930 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
931 state->possible_states_size);
932 output.emplace(
933 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500934 getStateSetPossibleStateNames(
935 state->state_set_id,
936 printPossibleStates(state->possible_states_size,
937 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500938
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600939 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +0530940 {
941 statesPtr += sizeof(state_effecter_possible_states) +
942 state->possible_states_size - 1;
943 }
George Liud6649362019-11-27 19:06:51 +0800944 }
945 }
946
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500947 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -0500948 {
949 const std::array<std::string_view, 4> terminusLocatorType = {
950 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
951
952 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
953
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500954 output["PLDMTerminusHandle"] = pdr->terminus_handle;
955 output["validity"] = (pdr->validity ? "valid" : "notValid");
956 output["TID"] = unsigned(pdr->tid);
957 output["containerID"] = pdr->container_id;
958 output["terminusLocatorType"] =
959 terminusLocatorType[pdr->terminus_locator_type];
960 output["terminusLocatorValueSize"] =
961 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -0500962
963 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
964 {
965 auto locatorValue =
966 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
967 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500968 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -0500969 }
970 }
971
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500972 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
George Liu62d12ec2020-02-05 16:27:08 +0800973 uint8_t* data)
George Liud6649362019-11-27 19:06:51 +0800974 {
George Liu62d12ec2020-02-05 16:27:08 +0800975 if (data == NULL)
George Liud6649362019-11-27 19:06:51 +0800976 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530977 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +0800978 return;
979 }
980
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500981 ordered_json output;
982 output["nextRecordHandle"] = nextRecordHndl;
983 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +0800984
985 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530986 if (!pdr)
987 {
988 return;
989 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500990
991 if (!pdrRecType.empty())
992 {
993 // Need to return if the requested PDR type
994 // is not supported
995 if (!strToPdrType.contains(pdrRecType))
996 {
997 std::cerr << "PDR type '" << pdrRecType
998 << "' is not supported or invalid\n";
999 // PDR type not supported, setting next record handle to 0
1000 // to avoid looping through all PDR records
1001 nextRecordHndl = 0;
1002 return;
1003 }
1004
1005 // Do not print PDR record if the current record
1006 // PDR type does not match with requested type
1007 if (pdr->type != strToPdrType.at(pdrRecType))
1008 {
1009 return;
1010 }
1011 }
1012
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001013 printCommonPDRHeader(pdr, output);
1014
George Liud6649362019-11-27 19:06:51 +08001015 switch (pdr->type)
1016 {
Sampa Misra12afe112020-05-25 11:40:44 -05001017 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001018 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001019 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301020 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001021 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301022 break;
George Liu62d12ec2020-02-05 16:27:08 +08001023 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001024 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001025 break;
George Liud6649362019-11-27 19:06:51 +08001026 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001027 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001028 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001029 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001030 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001031 break;
1032 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001033 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001034 break;
George Liud6649362019-11-27 19:06:51 +08001035 default:
1036 break;
1037 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001038 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001039 }
1040
1041 private:
1042 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001043 bool allPDRs;
1044 std::string pdrRecType;
George Liud6649362019-11-27 19:06:51 +08001045};
1046
1047class SetStateEffecter : public CommandInterface
1048{
1049 public:
1050 ~SetStateEffecter() = default;
1051 SetStateEffecter() = delete;
1052 SetStateEffecter(const SetStateEffecter&) = delete;
1053 SetStateEffecter(SetStateEffecter&&) = default;
1054 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
1055 SetStateEffecter& operator=(SetStateEffecter&&) = default;
1056
George Liuba4c1fb2020-02-05 14:13:30 +08001057 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1058 static constexpr auto maxEffecterDataSize = 16;
1059
1060 // compositeEffecterCount(value: 0x01 to 0x08)
1061 static constexpr auto minEffecterCount = 1;
1062 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001063 explicit SetStateEffecter(const char* type, const char* name,
1064 CLI::App* app) :
1065 CommandInterface(type, name, app)
1066 {
1067 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001068 "-i, --id", effecterId,
1069 "A handle that is used to identify and access the effecter")
1070 ->required();
1071 app->add_option("-c, --count", effecterCount,
1072 "The number of individual sets of effecter information")
1073 ->required();
1074 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001075 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001076 "Set effecter state data\n"
1077 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1078 ->required();
George Liud6649362019-11-27 19:06:51 +08001079 }
1080
1081 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1082 {
1083 std::vector<uint8_t> requestMsg(
1084 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
1085 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1086
George Liuba4c1fb2020-02-05 14:13:30 +08001087 if (effecterCount > maxEffecterCount ||
1088 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001089 {
George Liuba4c1fb2020-02-05 14:13:30 +08001090 std::cerr << "Request Message Error: effecterCount size "
1091 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001092 auto rc = PLDM_ERROR_INVALID_DATA;
1093 return {rc, requestMsg};
1094 }
1095
George Liuba4c1fb2020-02-05 14:13:30 +08001096 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001097 {
George Liuba4c1fb2020-02-05 14:13:30 +08001098 std::cerr << "Request Message Error: effecterData size "
1099 << effecterData.size() << "is invalid\n";
1100 auto rc = PLDM_ERROR_INVALID_DATA;
1101 return {rc, requestMsg};
1102 }
1103
1104 auto stateField = parseEffecterData(effecterData, effecterCount);
1105 if (!stateField)
1106 {
1107 std::cerr << "Failed to parse effecter data, effecterCount size "
1108 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001109 auto rc = PLDM_ERROR_INVALID_DATA;
1110 return {rc, requestMsg};
1111 }
1112
1113 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001114 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001115 return {rc, requestMsg};
1116 }
1117
1118 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1119 {
1120 uint8_t completionCode = 0;
1121 auto rc = decode_set_state_effecter_states_resp(
1122 responsePtr, payloadLength, &completionCode);
1123
1124 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1125 {
1126 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001127 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001128 return;
1129 }
1130
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001131 ordered_json data;
1132 data["Response"] = "SUCCESS";
1133 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001134 }
1135
1136 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001137 uint16_t effecterId;
1138 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001139 std::vector<uint8_t> effecterData;
1140};
1141
George Liucc9c20d2020-02-05 10:24:11 +08001142class SetNumericEffecterValue : public CommandInterface
1143{
1144 public:
1145 ~SetNumericEffecterValue() = default;
1146 SetNumericEffecterValue() = delete;
1147 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1148 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1149 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
1150 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default;
1151
1152 explicit SetNumericEffecterValue(const char* type, const char* name,
1153 CLI::App* app) :
1154 CommandInterface(type, name, app)
1155 {
1156 app->add_option(
1157 "-i, --id", effecterId,
1158 "A handle that is used to identify and access the effecter")
1159 ->required();
1160 app->add_option("-s, --size", effecterDataSize,
1161 "The bit width and format of the setting value for the "
1162 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1163 "uint32, sint32}\n")
1164 ->required();
1165 app->add_option("-d,--data", maxEffecterValue,
1166 "The setting value of numeric effecter being "
1167 "requested\n")
1168 ->required();
1169 }
1170
1171 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1172 {
1173 std::vector<uint8_t> requestMsg(
1174 sizeof(pldm_msg_hdr) +
1175 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1176
1177 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1178
1179 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1180 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1181
1182 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1183 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1184 {
1185 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1186 }
1187 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1188 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1189 {
1190 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1191 }
1192 auto rc = encode_set_numeric_effecter_value_req(
1193 0, effecterId, effecterDataSize, effecterValue, request,
1194 payload_length);
1195
1196 return {rc, requestMsg};
1197 }
1198
1199 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1200 {
1201 uint8_t completionCode = 0;
1202 auto rc = decode_set_numeric_effecter_value_resp(
1203 responsePtr, payloadLength, &completionCode);
1204
1205 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1206 {
1207 std::cerr << "Response Message Error: "
1208 << "rc=" << rc << ",cc=" << (int)completionCode
1209 << std::endl;
1210 return;
1211 }
1212
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001213 ordered_json data;
1214 data["Response"] = "SUCCESS";
1215 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001216 }
1217
1218 private:
1219 uint16_t effecterId;
1220 uint8_t effecterDataSize;
1221 uint64_t maxEffecterValue;
1222};
1223
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001224class GetStateSensorReadings : public CommandInterface
1225{
1226 public:
1227 ~GetStateSensorReadings() = default;
1228 GetStateSensorReadings() = delete;
1229 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1230 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1231 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
1232 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default;
1233
1234 explicit GetStateSensorReadings(const char* type, const char* name,
1235 CLI::App* app) :
1236 CommandInterface(type, name, app)
1237 {
1238 app->add_option(
1239 "-i, --sensor_id", sensorId,
1240 "Sensor ID that is used to identify and access the sensor")
1241 ->required();
1242 app->add_option("-r, --rearm", sensorRearm,
1243 "Each bit location in this field corresponds to a "
1244 "particular sensor")
1245 ->required();
1246 }
1247
1248 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1249 {
1250 std::vector<uint8_t> requestMsg(
1251 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
1252 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
1253
1254 uint8_t reserved = 0;
1255 bitfield8_t bf;
1256 bf.byte = sensorRearm;
1257 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1258 reserved, request);
1259
1260 return {rc, requestMsg};
1261 }
1262
1263 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1264 {
1265 uint8_t completionCode = 0;
1266 uint8_t compSensorCount = 0;
1267 std::array<get_sensor_state_field, 8> stateField{};
1268 auto rc = decode_get_state_sensor_readings_resp(
1269 responsePtr, payloadLength, &completionCode, &compSensorCount,
1270 stateField.data());
1271
1272 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1273 {
1274 std::cerr << "Response Message Error: "
1275 << "rc=" << rc << ",cc=" << (int)completionCode
1276 << std::endl;
1277 return;
1278 }
1279 ordered_json output;
1280 output["compositeSensorCount"] = (int)compSensorCount;
1281
1282 for (size_t i = 0; i < compSensorCount; i++)
1283 {
George Liubd5e2ea2021-04-22 20:33:06 +08001284 if (sensorOpState.contains(stateField[i].sensor_op_state))
1285 {
1286 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1287 sensorOpState.at(stateField[i].sensor_op_state));
1288 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001289
George Liubd5e2ea2021-04-22 20:33:06 +08001290 if (sensorPresState.contains(stateField[i].present_state))
1291 {
1292 output.emplace(("presentState[" + std::to_string(i) + "]"),
1293 sensorPresState.at(stateField[i].present_state));
1294 }
1295
1296 if (sensorPresState.contains(stateField[i].previous_state))
1297 {
1298 output.emplace(
1299 ("previousState[" + std::to_string(i) + "]"),
1300 sensorPresState.at(stateField[i].previous_state));
1301 }
1302
1303 if (sensorPresState.contains(stateField[i].event_state))
1304 {
1305 output.emplace(("eventState[" + std::to_string(i) + "]"),
1306 sensorPresState.at(stateField[i].event_state));
1307 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001308 }
1309
1310 pldmtool::helper::DisplayInJson(output);
1311 }
1312
1313 private:
1314 uint16_t sensorId;
1315 uint8_t sensorRearm;
1316};
1317
George Liud6649362019-11-27 19:06:51 +08001318void registerCommand(CLI::App& app)
1319{
1320 auto platform = app.add_subcommand("platform", "platform type command");
1321 platform->require_subcommand(1);
1322
1323 auto getPDR =
1324 platform->add_subcommand("GetPDR", "get platform descriptor records");
1325 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
1326
1327 auto setStateEffecterStates = platform->add_subcommand(
1328 "SetStateEffecterStates", "set effecter states");
1329 commands.push_back(std::make_unique<SetStateEffecter>(
1330 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08001331
1332 auto setNumericEffecterValue = platform->add_subcommand(
1333 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
1334 commands.push_back(std::make_unique<SetNumericEffecterValue>(
1335 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001336
1337 auto getStateSensorReadings = platform->add_subcommand(
1338 "GetStateSensorReadings", "get the state sensor readings");
1339 commands.push_back(std::make_unique<GetStateSensorReadings>(
1340 "platform", "getStateSensorReadings", getStateSensorReadings));
George Liud6649362019-11-27 19:06:51 +08001341}
1342
1343} // namespace platform
1344} // namespace pldmtool