blob: 0198dc1e0d0b394c8caecbd8e4f97f6fafbdfaa5 [file] [log] [blame]
Tom Josepha65c0412020-07-03 21:14:44 +05301#include "common/types.hpp"
George Liud6649362019-11-27 19:06:51 +08002#include "pldm_cmd_helper.hpp"
3
George Liuc453e162022-12-21 17:16:23 +08004#include <libpldm/entity.h>
Thu Nguyen846d38f2022-03-26 08:57:21 +07005#include <libpldm/platform.h>
George Liuc453e162022-12-21 17:16:23 +08006#include <libpldm/state_set.h>
7
Thu Nguyen846d38f2022-03-26 08:57:21 +07008#include <algorithm>
Brad Bishop02d71142021-10-14 19:00:17 -04009#include <cstddef>
Tal Yacobi8570fcc2024-05-28 11:11:23 +030010#include <format>
Brad Bishop02d71142021-10-14 19:00:17 -040011#include <map>
Tal Yacobi8570fcc2024-05-28 11:11:23 +030012#include <memory>
Thu Nguyen846d38f2022-03-26 08:57:21 +070013#include <ranges>
Brad Bishop02d71142021-10-14 19:00:17 -040014
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -050015#ifdef OEM_IBM
16#include "oem/ibm/oem_ibm_state_set.hpp"
17#endif
18
Brad Bishop5079ac42021-08-19 18:35:06 -040019using namespace pldm::utils;
20
George Liud6649362019-11-27 19:06:51 +080021namespace pldmtool
22{
George Liud6649362019-11-27 19:06:51 +080023namespace platform
24{
George Liud6649362019-11-27 19:06:51 +080025namespace
26{
George Liud6649362019-11-27 19:06:51 +080027using namespace pldmtool::helper;
Sridevi Rameshf31b5042021-01-22 05:42:07 -060028
29static const std::map<uint8_t, std::string> sensorPresState{
30 {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"},
31 {PLDM_SENSOR_NORMAL, "Sensor Normal"},
32 {PLDM_SENSOR_WARNING, "Sensor Warning"},
33 {PLDM_SENSOR_CRITICAL, "Sensor Critical"},
34 {PLDM_SENSOR_FATAL, "Sensor Fatal"},
35 {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"},
36 {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"},
37 {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"},
38 {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"},
39 {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"},
40 {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}};
41
42static const std::map<uint8_t, std::string> sensorOpState{
43 {PLDM_SENSOR_ENABLED, "Sensor Enabled"},
44 {PLDM_SENSOR_DISABLED, "Sensor Disabled"},
45 {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"},
46 {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"},
47 {PLDM_SENSOR_FAILED, "Sensor Failed"},
Manojkiran Eda2576aec2024-06-17 12:05:17 +053048 {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Initializing"},
Sridevi Rameshf31b5042021-01-22 05:42:07 -060049 {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"},
50 {PLDM_SENSOR_INTEST, "Sensor Intest"}};
51
Tal Yacobi8570fcc2024-05-28 11:11:23 +030052const std::map<uint8_t, std::string> effecterOpState{
53 {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING,
54 "Effecter Enabled Update Pending"},
55 {EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING,
56 "Effecter Enabled No Update Pending"},
57 {EFFECTER_OPER_STATE_DISABLED, "Effecter Disabled"},
58 {EFFECTER_OPER_STATE_UNAVAILABLE, "Effecter Unavailable"},
59 {EFFECTER_OPER_STATE_STATUSUNKNOWN, "Effecter Status Unknown"},
60 {EFFECTER_OPER_STATE_FAILED, "Effecter Failed"},
61 {EFFECTER_OPER_STATE_INITIALIZING, "Effecter Initializing"},
62 {EFFECTER_OPER_STATE_SHUTTINGDOWN, "Effecter Shutting Down"},
63 {EFFECTER_OPER_STATE_INTEST, "Effecter In Test"}};
64
65std::string getEffecterOpState(uint8_t state)
66{
67 return effecterOpState.contains(state) ? effecterOpState.at(state)
68 : std::to_string(state);
69}
70
George Liud6649362019-11-27 19:06:51 +080071std::vector<std::unique_ptr<CommandInterface>> commands;
72
73} // namespace
74
Sridevi Ramesh27c512a2020-08-12 03:29:42 -050075using ordered_json = nlohmann::ordered_json;
76
Roger G. Coscojuela4aea4bd2025-03-18 15:51:55 +010077class GetEventReceiver : public CommandInterface
78{
79 public:
80 ~GetEventReceiver() = default;
81 GetEventReceiver() = delete;
82 GetEventReceiver(const GetEventReceiver&) = delete;
83 GetEventReceiver(GetEventReceiver&&) = default;
84 GetEventReceiver& operator=(const GetEventReceiver&) = delete;
85 GetEventReceiver& operator=(GetEventReceiver&&) = delete;
86
87 explicit GetEventReceiver(const char* type, const char* name,
88 CLI::App* app) : CommandInterface(type, name, app)
89 {}
90 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
91 {
92 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
93 auto request = new (requestMsg.data()) pldm_msg;
94 auto rc =
95 encode_pldm_header_only(PLDM_REQUEST, instanceId, PLDM_PLATFORM,
96 PLDM_GET_EVENT_RECEIVER, request);
97 if (rc != PLDM_SUCCESS)
98 {
99 std::cerr << "Failed to encode_pldm_header_only, return code " << rc
100 << std::endl;
101 }
102 return {rc, requestMsg};
103 }
104 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
105 {
106 struct pldm_get_event_receiver_resp event_receiver_resp_data;
107 auto rc = decode_get_event_receiver_resp(responsePtr, payloadLength,
108 &event_receiver_resp_data);
109 if (rc || event_receiver_resp_data.completion_code)
110 {
111 std::cerr << "Response Message Error: "
112 << "return code " << rc << ", completion code "
113 << static_cast<int>(
114 event_receiver_resp_data.completion_code)
115 << std::endl;
116 return;
117 }
118 if (event_receiver_resp_data.transport_protocol_type !=
119 PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP)
120 {
121 std::cerr << "Unsupported response protocol type " << std::endl;
122 return;
123 }
124
125 ordered_json data;
126 data["completionCode"] = event_receiver_resp_data.completion_code;
127 data["transportProtocolType"] =
128 event_receiver_resp_data.transport_protocol_type;
129 data["eventReceiverAddressInfo"] =
130 event_receiver_resp_data.event_receiver_address.mctp_eid;
131 pldmtool::helper::DisplayInJson(data);
132 }
133};
134
George Liud6649362019-11-27 19:06:51 +0800135class GetPDR : public CommandInterface
136{
137 public:
138 ~GetPDR() = default;
139 GetPDR() = delete;
140 GetPDR(const GetPDR&) = delete;
141 GetPDR(GetPDR&&) = default;
142 GetPDR& operator=(const GetPDR&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500143 GetPDR& operator=(GetPDR&&) = delete;
George Liud6649362019-11-27 19:06:51 +0800144
145 using CommandInterface::CommandInterface;
146
George Liud6649362019-11-27 19:06:51 +0800147 explicit GetPDR(const char* type, const char* name, CLI::App* app) :
Potin Lai3e52d582024-06-13 11:03:46 +0800148 CommandInterface(type, name, app), dataTransferHandle(0),
149 operationFlag(PLDM_GET_FIRSTPART), requestCount(UINT16_MAX),
150 recordChangeNumber(0), nextPartRequired(false)
George Liud6649362019-11-27 19:06:51 +0800151 {
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500152 auto pdrOptionGroup = app->add_option_group(
153 "Required Option",
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600154 "Retrieve individual PDR, all PDRs, PDRs of a requested type or retrieve all PDRs of the requested terminusID");
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500155 pdrOptionGroup->add_option(
156 "-d,--data", recordHandle,
157 "retrieve individual PDRs from a PDR Repository\n"
158 "eg: The recordHandle value for the PDR to be retrieved and 0 "
159 "means get first PDR in the repository.");
160 pdrRecType = "";
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400161 pdrOptionGroup->add_option(
162 "-t, --type", pdrRecType,
163 "retrieve all PDRs of the requested type\n"
164 "supported types:\n"
165 "[terminusLocator, stateSensor, "
166 "numericEffecter, stateEffecter, "
167 "compactNumericSensor, sensorauxname, "
168 "efffecterAuxName, numericsensor, "
169 "EntityAssociation, fruRecord, ... ]");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600170
171 getPDRGroupOption = pdrOptionGroup->add_option(
172 "-i, --terminusID", pdrTerminus,
173 "retrieve all PDRs of the requested terminusID\n"
174 "supported IDs:\n [1, 2, 208...]");
175
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500176 allPDRs = false;
177 pdrOptionGroup->add_flag("-a, --all", allPDRs,
178 "retrieve all PDRs from a PDR repository");
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600179
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500180 pdrOptionGroup->require_option(1);
181 }
182
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600183 void parseGetPDROptions()
184 {
185 optTIDSet = false;
186 if (getPDRGroupOption->count() > 0)
187 {
188 optTIDSet = true;
189 getPDRs();
190 }
191 }
192
193 void getPDRs()
194 {
195 // start the array
196 std::cout << "[";
197
198 recordHandle = 0;
199 do
200 {
201 CommandInterface::exec();
202 } while (recordHandle != 0);
203
204 // close the array
205 std::cout << "]\n";
206
207 if (handleFound)
208 {
209 recordHandle = 0;
210 uint32_t prevRecordHandle = 0;
211 do
212 {
213 CommandInterface::exec();
214 if (recordHandle == prevRecordHandle)
215 {
216 return;
217 }
218 prevRecordHandle = recordHandle;
219 } while (recordHandle != 0);
220 }
221 }
222
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500223 void exec() override
224 {
225 if (allPDRs || !pdrRecType.empty())
226 {
227 if (!pdrRecType.empty())
228 {
229 std::transform(pdrRecType.begin(), pdrRecType.end(),
230 pdrRecType.begin(), tolower);
231 }
232
Brad Bishop16eff862021-10-14 19:44:32 -0400233 // start the array
234 std::cout << "[\n";
235
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500236 // Retrieve all PDR records starting from the first
237 recordHandle = 0;
238 uint32_t prevRecordHandle = 0;
Brad Bishop02d71142021-10-14 19:00:17 -0400239 std::map<uint32_t, uint32_t> recordsSeen;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500240 do
241 {
242 CommandInterface::exec();
243 // recordHandle is updated to nextRecord when
244 // CommandInterface::exec() is successful.
245 // In case of any error, return.
Potin Lai3e52d582024-06-13 11:03:46 +0800246 if (recordHandle == prevRecordHandle && !nextPartRequired)
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500247 {
248 return;
249 }
Brad Bishop02d71142021-10-14 19:00:17 -0400250
251 // check for circular references.
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400252 auto result =
253 recordsSeen.emplace(recordHandle, prevRecordHandle);
Potin Lai3e52d582024-06-13 11:03:46 +0800254 if (!result.second && !nextPartRequired)
Brad Bishop02d71142021-10-14 19:00:17 -0400255 {
256 std::cerr
257 << "Record handle " << recordHandle
258 << " has multiple references: " << result.first->second
259 << ", " << prevRecordHandle << "\n";
260 return;
261 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500262 prevRecordHandle = recordHandle;
Brad Bishop16eff862021-10-14 19:44:32 -0400263
264 if (recordHandle != 0)
265 {
266 // close the array
267 std::cout << ",";
268 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500269 } while (recordHandle != 0);
Brad Bishop16eff862021-10-14 19:44:32 -0400270
271 // close the array
272 std::cout << "]\n";
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500273 }
274 else
275 {
Potin Lai3e52d582024-06-13 11:03:46 +0800276 do
277 {
278 CommandInterface::exec();
279 } while (nextPartRequired);
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500280 }
George Liud6649362019-11-27 19:06:51 +0800281 }
282
283 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
284 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400285 std::vector<uint8_t> requestMsg(
286 sizeof(pldm_msg_hdr) + PLDM_GET_PDR_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530287 auto request = new (requestMsg.data()) pldm_msg;
George Liud6649362019-11-27 19:06:51 +0800288
Potin Lai3e52d582024-06-13 11:03:46 +0800289 auto rc = encode_get_pdr_req(
290 instanceId, recordHandle, dataTransferHandle, operationFlag,
291 requestCount, recordChangeNumber, request, PLDM_GET_PDR_REQ_BYTES);
George Liud6649362019-11-27 19:06:51 +0800292 return {rc, requestMsg};
293 }
294
295 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
296 {
297 uint8_t completionCode = 0;
Potin Lai3e52d582024-06-13 11:03:46 +0800298 uint8_t respRecordData[UINT16_MAX] = {0};
George Liud6649362019-11-27 19:06:51 +0800299 uint32_t nextRecordHndl = 0;
300 uint32_t nextDataTransferHndl = 0;
301 uint8_t transferFlag = 0;
302 uint16_t respCnt = 0;
303 uint8_t transferCRC = 0;
304
305 auto rc = decode_get_pdr_resp(
306 responsePtr, payloadLength, &completionCode, &nextRecordHndl,
Potin Lai3e52d582024-06-13 11:03:46 +0800307 &nextDataTransferHndl, &transferFlag, &respCnt, respRecordData,
308 sizeof(respRecordData), &transferCRC);
George Liud6649362019-11-27 19:06:51 +0800309
310 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
311 {
312 std::cerr << "Response Message Error: "
313 << "rc=" << rc << ",cc=" << (int)completionCode
314 << std::endl;
Potin Lai3e52d582024-06-13 11:03:46 +0800315 nextPartRequired = false;
George Liud6649362019-11-27 19:06:51 +0800316 return;
317 }
318
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600319 if (optTIDSet && !handleFound)
320 {
Potin Lai3e52d582024-06-13 11:03:46 +0800321 terminusHandle = getTerminusHandle(respRecordData, pdrTerminus);
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600322 if (terminusHandle.has_value())
323 {
324 recordHandle = 0;
325 return;
326 }
327 else
328 {
329 recordHandle = nextRecordHndl;
330 return;
331 }
332 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600333 else
334 {
Potin Lai3e52d582024-06-13 11:03:46 +0800335 recordData.insert(recordData.end(), respRecordData,
336 respRecordData + respCnt);
337
338 // End or StartAndEnd
339 if (transferFlag == PLDM_PLATFORM_TRANSFER_END ||
340 transferFlag == PLDM_PLATFORM_TRANSFER_START_AND_END)
341 {
342 printPDRMsg(nextRecordHndl, respCnt, recordData.data(),
343 terminusHandle);
344 nextPartRequired = false;
345 recordHandle = nextRecordHndl;
346 dataTransferHandle = 0;
347 recordChangeNumber = 0;
348 operationFlag = PLDM_GET_FIRSTPART;
349 recordData.clear();
350 }
351 else
352 {
353 nextPartRequired = true;
354 dataTransferHandle = nextDataTransferHndl;
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530355 struct pldm_pdr_hdr* pdr_hdr = new (respRecordData)
356 pldm_pdr_hdr;
Potin Lai3e52d582024-06-13 11:03:46 +0800357 recordChangeNumber = pdr_hdr->record_change_num;
358 operationFlag = PLDM_GET_NEXTPART;
359 }
Pavithra Barithayaa340eed2023-02-14 03:32:47 -0600360 }
George Liud6649362019-11-27 19:06:51 +0800361 }
362
363 private:
Tom Josepha65c0412020-07-03 21:14:44 +0530364 const std::map<pldm::pdr::EntityType, std::string> entityType = {
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530365 {PLDM_ENTITY_UNSPECIFIED, "Unspecified"},
366 {PLDM_ENTITY_OTHER, "Other"},
367 {PLDM_ENTITY_NETWORK, "Network"},
368 {PLDM_ENTITY_GROUP, "Group"},
369 {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE,
370 "Remote Management Communication Device"},
371 {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"},
372 {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"},
373 {PLDM_ENTITY_TERMINUS, "PLDM Terminus"},
374 {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"},
375 {PLDM_ENTITY_KEYPAD, "keypad"},
376 {PLDM_ENTITY_SWITCH, "Switch"},
377 {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"},
378 {PLDM_ENTITY_DISPLAY, "Display"},
379 {PLDM_ENTITY_INDICATOR, "Indicator"},
380 {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"},
Tom Josepha65c0412020-07-03 21:14:44 +0530381 {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530382 {PLDM_ENTITY_OPERATING_SYS, "Operating System"},
Tom Josepha65c0412020-07-03 21:14:44 +0530383 {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530384 {PLDM_ENTITY_OS_LOADER, "OS Loader"},
385 {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"},
386 {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"},
Tom Josepha65c0412020-07-03 21:14:44 +0530387 {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530388 {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"},
389 {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"},
390 {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"},
391 {PLDM_ENTITY_DEVICE_BAY, "Device bay"},
392 {PLDM_ENTITY_DOOR, "Door"},
393 {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"},
394 {PLDM_ENTITY_COVER, "Cover"},
395 {PLDM_ENTITY_BOARD, "Board"},
396 {PLDM_ENTITY_CARD, "Card"},
397 {PLDM_ENTITY_MODULE, "Module"},
398 {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"},
Tom Josepha65c0412020-07-03 21:14:44 +0530399 {PLDM_ENTITY_SYS_BOARD, "System Board"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530400 {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"},
Tom Josepha65c0412020-07-03 21:14:44 +0530401 {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"},
402 {PLDM_ENTITY_PROC_MODULE, "Processor Module"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530403 {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"},
Tom Josepha65c0412020-07-03 21:14:44 +0530404 {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD,
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530405 "Chassis front panel board(control panel)"},
406 {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"},
407 {PLDM_ENTITY_POWER_MGMT, "Power management board"},
408 {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"},
409 {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"},
410 {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD,
411 "System internal expansion board"},
412 {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"},
413 {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"},
414 {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"},
415 {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"},
416 {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"},
417 {PLDM_ENTITY_IO_MODULE, "I/O Module"},
418 {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"},
419 {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"},
420 {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"},
421 {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500422 {PLDM_ENTITY_FAN, "Fan"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530423 {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"},
424 {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"},
425 {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"},
426 {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"},
427 {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"},
428 {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"},
429 {PLDM_ENTITY_CD_DRIVE, "CD Drive"},
430 {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"},
431 {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE,
432 "Other Silicon Storage Device"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500433 {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530434 {PLDM_ENTITY_POWER_SUPPLY, "Power supply"},
435 {PLDM_ENTITY_BATTERY, "Battery"},
436 {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"},
437 {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"},
438 {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"},
439 {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"},
440 {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"},
441 {PLDM_ENTITY_PROC, "Processor"},
442 {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"},
443 {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"},
444 {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"},
445 {PLDM_ENTITY_SEEPROM, "SEEPROM"},
446 {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"},
447 {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"},
448 {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"},
449 {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"},
450 {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"},
451 {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"},
452 {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500453 {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530454 {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"},
455 {PLDM_ENTITY_OTHER_BUS, "Other Bus"},
456 {PLDM_ENTITY_SYS_BUS, "System Bus"},
457 {PLDM_ENTITY_I2C_BUS, "I2C Bus"},
458 {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"},
459 {PLDM_ENTITY_SPI_BUS, "SPI Bus"},
460 {PLDM_ENTITY_PCI_BUS, "PCI Bus"},
461 {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"},
462 {PLDM_ENTITY_PECI_BUS, "PECI Bus"},
463 {PLDM_ENTITY_LPC_BUS, "LPC Bus"},
464 {PLDM_ENTITY_USB_BUS, "USB Bus"},
465 {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"},
466 {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"},
467 {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"},
468 {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"},
469 {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"},
470 {PLDM_ENTITY_CONNECTOR, "Connector"},
Jayashankar Padath79175b42021-05-20 22:54:34 -0500471 {PLDM_ENTITY_SLOT, "Slot"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530472 {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"},
473 {PLDM_ENTITY_INTERCONNECT, "Interconnect"},
474 {PLDM_ENTITY_PLUG, "Plug"},
475 {PLDM_ENTITY_SOCKET, "Socket"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500476 };
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500477
Tom Josepha65c0412020-07-03 21:14:44 +0530478 const std::map<uint16_t, std::string> stateSet = {
479 {PLDM_STATE_SET_HEALTH_STATE, "Health State"},
480 {PLDM_STATE_SET_AVAILABILITY, "Availability"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530481 {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"},
482 {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"},
483 {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"},
484 {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"},
485 {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"},
Tom Josepha65c0412020-07-03 21:14:44 +0530486 {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530487 {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"},
488 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530489 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
490 "Operational Running Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530491 {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS,
492 "Operational Connection Status"},
Tom Josepha65c0412020-07-03 21:14:44 +0530493 {PLDM_STATE_SET_PRESENCE, "Presence"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530494 {PLDM_STATE_SET_PERFORMANCE, "Performance"},
Tom Josepha65c0412020-07-03 21:14:44 +0530495 {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530496 {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"},
497 {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"},
498 {PLDM_STATE_SET_VERSION, "Version"},
499 {PLDM_STATE_SET_ALARM_STATE, "Alarm State"},
500 {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"},
501 {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"},
502 {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"},
Tom Josepha65c0412020-07-03 21:14:44 +0530503 {PLDM_STATE_SET_LINK_STATE, "Link State"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530504 {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"},
505 {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"},
506 {PLDM_STATE_SET_DOOR_STATE, "Door State"},
507 {PLDM_STATE_SET_SWITCH_STATE, "Switch State"},
508 {PLDM_STATE_SET_LOCK_STATE, "Lock State"},
509 {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"},
510 {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"},
511 {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"},
512 {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION,
513 "Physical Communication Connection"},
514 {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"},
515 {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS,
516 "Foreign Network Detection Status"},
517 {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY,
518 "Password-Protected Access Security"},
519 {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL,
520 "Security Access –PrivilegeLevel"},
521 {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"},
Tom Josepha65c0412020-07-03 21:14:44 +0530522 {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530523 {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"},
Tom Josepha65c0412020-07-03 21:14:44 +0530524 {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530525 {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"},
526 {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"},
527 {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"},
Tom Josepha65c0412020-07-03 21:14:44 +0530528 {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"},
Manojkiran Edaafbdb6d2021-05-27 17:19:51 +0530529 {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"},
530 {PLDM_STATE_SET_POST_ERRORS, "POST Errors"},
531 {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"},
532 {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"},
533 {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"},
534 {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"},
535 {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"},
536 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED,
537 "Diagnostic Interrupt Requested"},
538 {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED,
539 "Diagnostic Interrupt Received"},
540 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED,
541 "I/O Channel Check NMI Requested"},
542 {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED,
543 "I/O Channel Check NMI Received"},
544 {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"},
545 {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"},
546 {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"},
547 {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"},
548 {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"},
549 {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"},
550 {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"},
551 {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"},
552 {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "},
553 {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"},
554 {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"},
555 {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"},
556 {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"},
557 {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"},
558 {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"},
559 {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"},
560 {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "},
561 {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"},
562 {PLDM_STATE_SET_BATTERY_STATE, "Battery State"},
563 {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"},
564 {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"},
565 {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"},
566 {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"},
567 {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"},
568 {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"},
569 {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"},
570 {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"},
571 {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"},
572 {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"},
573 {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"},
574 {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"},
575 {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS,
576 "Redundant Memory Activity Status"},
577 {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"},
578 {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"},
579 {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"},
580 {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500581 {PLDM_STATE_SET_SLOT_STATE, "Slot State"},
582 };
Tom Josepha65c0412020-07-03 21:14:44 +0530583
584 const std::array<std::string_view, 4> sensorInit = {
585 "noInit", "useInitPDR", "enableSensor", "disableSensor"};
586
Tom Joseph97a7a762020-07-06 10:37:18 +0530587 const std::array<std::string_view, 4> effecterInit = {
588 "noInit", "useInitPDR", "enableEffecter", "disableEffecter"};
589
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500590 const std::map<uint8_t, std::string> pdrType = {
591 {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"},
592 {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"},
593 {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR,
594 "Numeric Sensor Initialization PDR"},
595 {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"},
596 {PLDM_STATE_SENSOR_INITIALIZATION_PDR,
597 "State Sensor Initialization PDR"},
598 {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"},
599 {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"},
600 {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"},
601 {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"},
602 {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR,
603 "Numeric Effecter Initialization PDR"},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700604 {PLDM_COMPACT_NUMERIC_SENSOR_PDR, "Compact Numeric Sensor PDR"},
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500605 {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"},
606 {PLDM_STATE_EFFECTER_INITIALIZATION_PDR,
607 "State Effecter Initialization PDR"},
608 {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"},
609 {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"},
610 {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"},
611 {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"},
612 {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"},
613 {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"},
614 {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"},
615 {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"},
616 {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"},
617 {PLDM_OEM_PDR, "OEM PDR"},
618 };
619
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500620 static inline const std::map<uint8_t, std::string> setThermalTrip{
621 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"},
622 {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}};
623
624 static inline const std::map<uint8_t, std::string> setIdentifyState{
625 {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"},
626 {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}};
627
628 static inline const std::map<uint8_t, std::string> setBootProgressState{
629 {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"},
630 {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"},
631 {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION,
632 "Memory Initialization"},
633 {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION,
634 "Secondary Processor(s) Initialization"},
635 {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG,
636 "PCI Resource Configuration"},
637 {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS,
638 "Starting Operating System"},
639 {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION,
640 "Baseboard Initialization"},
641 {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION,
kamal00a076d2022-11-08 04:24:36 -0600642 "Primary Processor Initialization"},
643 {PLDM_STATE_SET_BOOT_PROG_STATE_OSSTART, "OSStart"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500644
645 static inline const std::map<uint8_t, std::string> setOpFaultStatus{
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -0500646 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"},
647 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_ERROR, "Error"},
648 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NON_RECOVERABLE_ERROR,
649 "Non Recoverable Error"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500650
651 static inline const std::map<uint8_t, std::string> setSysPowerState{
652 {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL,
653 "Off-Soft Graceful"}};
654
655 static inline const std::map<uint8_t, std::string> setSWTerminationStatus{
656 {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED,
657 "Graceful Restart Requested"}};
658
659 static inline const std::map<uint8_t, std::string> setAvailability{
660 {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}};
661
662 static inline const std::map<uint8_t, std::string> setHealthState{
663 {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530664 {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"},
665 {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"},
666 {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"},
667 {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"},
668 {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500669 {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530670 {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"},
671 {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"},
672 {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}};
673
674 static inline const std::map<uint8_t, std::string>
675 setOperationalRunningState{
676 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"},
677 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"},
678 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"},
679 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE,
680 "In Service"},
681 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"},
682 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500683
Riya Dixit43e33d22024-02-07 09:53:49 -0600684 static inline const std::map<uint8_t, std::string> setPowerDeviceState{
685 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_UNKNOWN, "Unknown"},
686 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_FULLY_ON, "Fully-On"},
687 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_1,
688 "Intermediate State-1"},
689 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_INTERMEDIATE_2,
690 "Intermediate State-2"},
691 {PLDM_STATE_SET_ACPI_DEVICE_POWER_STATE_OFF, "Off"}};
692
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500693 static inline const std::map<uint16_t, const std::map<uint8_t, std::string>>
694 populatePStateMaps{
695 {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip},
696 {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState},
697 {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState},
698 {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus},
699 {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState},
700 {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus},
701 {PLDM_STATE_SET_AVAILABILITY, setAvailability},
702 {PLDM_STATE_SET_HEALTH_STATE, setHealthState},
Manojkiran Eda5de3de52022-01-03 12:12:53 +0530703 {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS,
704 setOperationalRunningState},
Riya Dixit43e33d22024-02-07 09:53:49 -0600705 {PLDM_STATE_SET_DEVICE_POWER_STATE, setPowerDeviceState},
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500706 };
707
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500708 const std::map<std::string, uint8_t> strToPdrType = {
709 {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR},
710 {"statesensor", PLDM_STATE_SENSOR_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700711 {"sensorauxname", PLDM_SENSOR_AUXILIARY_NAMES_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500712 {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR},
Thu Nguyen846d38f2022-03-26 08:57:21 +0700713 {"efffecterauxname", PLDM_EFFECTER_AUXILIARY_NAMES_PDR},
nothingIIersonalcea52d92024-03-21 13:56:02 +0300714 {"numericsensor", PLDM_NUMERIC_SENSOR_PDR},
Thu Nguyen9d0e58c2021-12-09 13:53:00 +0700715 {"compactnumericsensor", PLDM_COMPACT_NUMERIC_SENSOR_PDR},
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -0500716 {"stateeffecter", PLDM_STATE_EFFECTER_PDR},
717 {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION},
718 {"frurecord", PLDM_PDR_FRU_RECORD_SET},
719 // Add other types
720 };
721
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530722 bool isLogicalBitSet(const uint16_t entity_type)
723 {
724 return entity_type & 0x8000;
725 }
726
727 uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type)
728 {
729 return logical_entity_type & 0x7FFF;
730 }
731
Tom Josepha65c0412020-07-03 21:14:44 +0530732 std::string getEntityName(pldm::pdr::EntityType type)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500733 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530734 uint16_t entityNumber = type;
735 std::string entityName = "[Physical] ";
736
737 if (isLogicalBitSet(type))
738 {
739 entityName = "[Logical] ";
740 entityNumber = getEntityTypeForLogicalEntity(type);
741 }
742
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500743 try
744 {
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530745 return entityName + entityType.at(entityNumber);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500746 }
747 catch (const std::out_of_range& e)
748 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500749 auto OemString =
750 std::to_string(static_cast<unsigned>(entityNumber));
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530751 if (type >= PLDM_OEM_ENTITY_TYPE_START &&
752 type <= PLDM_OEM_ENTITY_TYPE_END)
753 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500754#ifdef OEM_IBM
755 if (OemIBMEntityType.contains(entityNumber))
756 {
757 return entityName + OemIBMEntityType.at(entityNumber) +
758 "(OEM)";
759 }
760#endif
761 return entityName + OemString + "(OEM)";
Manojkiran Eda0c5d1ec2021-05-29 11:21:25 +0530762 }
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500763 return OemString;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500764 }
765 }
766
Tom Josepha65c0412020-07-03 21:14:44 +0530767 std::string getStateSetName(uint16_t id)
768 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500769 auto typeString = std::to_string(id);
Tom Josepha65c0412020-07-03 21:14:44 +0530770 try
771 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500772 return stateSet.at(id) + "(" + typeString + ")";
Tom Josepha65c0412020-07-03 21:14:44 +0530773 }
774 catch (const std::out_of_range& e)
775 {
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500776 return typeString;
777 }
778 }
779
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400780 std::vector<std::string> getStateSetPossibleStateNames(
781 uint16_t stateId, const std::vector<uint8_t>& value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500782 {
783 std::vector<std::string> data{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500784
Pavithra Barithaya15b94112024-04-10 02:42:12 -0500785 for (const auto& s : value)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500786 {
787 std::map<uint8_t, std::string> stateNameMaps;
788 auto pstr = std::to_string(s);
789
790#ifdef OEM_IBM
Manojkiran Edabe1a8572022-01-06 11:20:36 +0530791 if (stateId >= PLDM_OEM_STATE_SET_ID_START &&
792 stateId < PLDM_OEM_STATE_SET_ID_END)
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500793 {
794 if (populateOemIBMStateMaps.contains(stateId))
795 {
796 const std::map<uint8_t, std::string> stateNames =
797 populateOemIBMStateMaps.at(stateId);
798 stateNameMaps.insert(stateNames.begin(), stateNames.end());
799 }
800 }
801#endif
802 if (populatePStateMaps.contains(stateId))
803 {
804 const std::map<uint8_t, std::string> stateNames =
805 populatePStateMaps.at(stateId);
806 stateNameMaps.insert(stateNames.begin(), stateNames.end());
807 }
808 if (stateNameMaps.contains(s))
809 {
810 data.push_back(stateNameMaps.at(s) + "(" + pstr + ")");
811 }
812 else
813 {
814 data.push_back(pstr);
815 }
816 }
817 return data;
818 }
819
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500820 std::string getPDRType(uint8_t type)
821 {
822 auto typeString = std::to_string(type);
823 try
824 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500825 return pdrType.at(type);
Sridevi Ramesha1bfb782020-07-14 02:51:23 -0500826 }
827 catch (const std::out_of_range& e)
828 {
829 return typeString;
Tom Josepha65c0412020-07-03 21:14:44 +0530830 }
831 }
832
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500833 void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
Tom Joseph952abfa2020-07-03 12:25:15 +0530834 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500835 output["recordHandle"] = hdr->record_handle;
836 output["PDRHeaderVersion"] = unsigned(hdr->version);
837 output["PDRType"] = getPDRType(hdr->type);
838 output["recordChangeNumber"] = hdr->record_change_num;
839 output["dataLength"] = hdr->length;
Tom Joseph952abfa2020-07-03 12:25:15 +0530840 }
841
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500842 std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize,
843 const bitfield8_t* states)
Tom Josepha65c0412020-07-03 21:14:44 +0530844 {
845 uint8_t possibleStatesPos{};
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500846 std::vector<uint8_t> data{};
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500847 auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
848 std::stringstream pstates;
Tom Josepha65c0412020-07-03 21:14:44 +0530849 for (int i = 0; i < CHAR_BIT; i++)
850 {
851 if (val.byte & (1 << i))
852 {
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500853 pstates << (possibleStatesPos * CHAR_BIT + i);
854 data.push_back(
855 static_cast<uint8_t>(std::stoi(pstates.str())));
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600856 pstates.str("");
Tom Josepha65c0412020-07-03 21:14:44 +0530857 }
858 }
859 possibleStatesPos++;
860 };
861 std::for_each(states, states + possibleStatesSize, printStates);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500862 return data;
Tom Josepha65c0412020-07-03 21:14:44 +0530863 }
864
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500865 void printStateSensorPDR(const uint8_t* data, ordered_json& output)
Tom Josepha65c0412020-07-03 21:14:44 +0530866 {
867 auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500868 output["PLDMTerminusHandle"] = pdr->terminus_handle;
869 output["sensorID"] = pdr->sensor_id;
870 output["entityType"] = getEntityName(pdr->entity_type);
871 output["entityInstanceNumber"] = pdr->entity_instance;
872 output["containerID"] = pdr->container_id;
873 output["sensorInit"] = sensorInit[pdr->sensor_init];
874 output["sensorAuxiliaryNamesPDR"] =
875 (pdr->sensor_auxiliary_names_pdr ? true : false);
876 output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
Tom Josepha65c0412020-07-03 21:14:44 +0530877
878 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600879 auto compCount = pdr->composite_sensor_count;
Tom Josepha65c0412020-07-03 21:14:44 +0530880
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600881 while (compCount--)
Tom Josepha65c0412020-07-03 21:14:44 +0530882 {
883 auto state = reinterpret_cast<const state_sensor_possible_states*>(
884 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600885 output.emplace(("stateSetID[" + std::to_string(compCount) + "]"),
886 getStateSetName(state->state_set_id));
887 output.emplace(
888 ("possibleStatesSize[" + std::to_string(compCount) + "]"),
889 state->possible_states_size);
890 output.emplace(
891 ("possibleStates[" + std::to_string(compCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -0500892 getStateSetPossibleStateNames(
893 state->state_set_id,
894 printPossibleStates(state->possible_states_size,
895 state->states)));
Tom Josepha65c0412020-07-03 21:14:44 +0530896
Sridevi Ramesh148ccab2020-11-23 08:23:09 -0600897 if (compCount)
Tom Josepha65c0412020-07-03 21:14:44 +0530898 {
899 statesPtr += sizeof(state_sensor_possible_states) +
900 state->possible_states_size - 1;
901 }
902 }
903 }
904
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500905 void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500906 {
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -0600907 if (data == nullptr)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500908 {
909 return;
910 }
911
912 data += sizeof(pldm_pdr_hdr);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530913 pldm_pdr_fru_record_set* pdr = new (data) pldm_pdr_fru_record_set;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530914 if (!pdr)
915 {
916 std::cerr << "Failed to get the FRU record set PDR" << std::endl;
917 return;
918 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500919
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500920 output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
921 output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
922 output["entityType"] = getEntityName(pdr->entity_type);
Sagar Srinivasebf8bb52023-10-06 01:15:55 -0500923 output["entityInstanceNumber"] = unsigned(pdr->entity_instance);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500924 output["containerID"] = unsigned(pdr->container_id);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500925 }
926
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500927 void printPDREntityAssociation(uint8_t* data, ordered_json& output)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500928 {
929 const std::map<uint8_t, const char*> assocationType = {
930 {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
931 {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"},
932 };
933
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -0600934 if (data == nullptr)
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500935 {
936 return;
937 }
938
939 data += sizeof(pldm_pdr_hdr);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530940 pldm_pdr_entity_association* pdr = new (data)
941 pldm_pdr_entity_association;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +0530942 if (!pdr)
943 {
944 std::cerr << "Failed to get the PDR eneity association"
945 << std::endl;
946 return;
947 }
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500948
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500949 output["containerID"] = int(pdr->container_id);
George Liubd5e2ea2021-04-22 20:33:06 +0800950 if (assocationType.contains(pdr->association_type))
951 {
952 output["associationType"] =
953 assocationType.at(pdr->association_type);
954 }
955 else
956 {
957 std::cout << "Get associationType failed.\n";
958 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500959 output["containerEntityType"] =
960 getEntityName(pdr->container.entity_type);
961 output["containerEntityInstanceNumber"] =
962 int(pdr->container.entity_instance_num);
963 output["containerEntityContainerID"] =
964 int(pdr->container.entity_container_id);
965 output["containedEntityCount"] =
966 static_cast<unsigned>(pdr->num_children);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500967
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +0530968 pldm_entity* child = new (&pdr->children[0]) pldm_entity();
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500969 for (int i = 0; i < pdr->num_children; ++i)
970 {
Sridevi Ramesh27c512a2020-08-12 03:29:42 -0500971 output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
972 getEntityName(child->entity_type));
973 output.emplace("containedEntityInstanceNumber[" +
974 std::to_string(i + 1) + "]",
975 unsigned(child->entity_instance_num));
976 output.emplace("containedEntityContainerID[" +
977 std::to_string(i + 1) + "]",
978 unsigned(child->entity_container_id));
979
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -0500980 ++child;
981 }
982 }
983
Thu Nguyen846d38f2022-03-26 08:57:21 +0700984 /** @brief Format the Sensor/Effecter Aux Name PDR types to json output
985 *
986 * @param[in] data - reference to the Sensor/Effecter Aux Name PDR
987 * @param[out] output - PDRs data fields in Json format
988 */
989 void printAuxNamePDR(uint8_t* data, ordered_json& output)
990 {
991 constexpr uint8_t nullTerminator = 0;
992 struct pldm_effecter_aux_name_pdr* auxNamePdr =
993 (struct pldm_effecter_aux_name_pdr*)data;
994
995 if (!auxNamePdr)
996 {
997 std::cerr << "Failed to get Aux Name PDR" << std::endl;
998 return;
999 }
1000
1001 std::string sPrefix = "effecter";
1002 if (auxNamePdr->hdr.type == PLDM_SENSOR_AUXILIARY_NAMES_PDR)
1003 {
1004 sPrefix = "sensor";
1005 }
1006 output["terminusHandle"] = int(auxNamePdr->terminus_handle);
1007 output[sPrefix + "Id"] = int(auxNamePdr->effecter_id);
1008 output[sPrefix + "Count"] = int(auxNamePdr->effecter_count);
1009
1010 const uint8_t* ptr = auxNamePdr->effecter_names;
1011 for (auto i : std::views::iota(0, (int)auxNamePdr->effecter_count))
1012 {
1013 const uint8_t nameStringCount = static_cast<uint8_t>(*ptr);
1014 ptr += sizeof(uint8_t);
1015 for (auto j : std::views::iota(0, (int)nameStringCount))
1016 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001017 std::string nameLanguageTagKey =
1018 sPrefix + std::to_string(j) + "_nameLanguageTag" +
1019 std::to_string(i);
1020 std::string entityAuxNameKey =
1021 sPrefix + std::to_string(j) + "_entityAuxName" +
1022 std::to_string(i);
Thu Nguyen846d38f2022-03-26 08:57:21 +07001023 std::string nameLanguageTag(reinterpret_cast<const char*>(ptr),
1024 0, PLDM_STR_UTF_8_MAX_LEN);
1025 ptr += nameLanguageTag.size() + sizeof(nullTerminator);
1026 std::u16string u16NameString(
1027 reinterpret_cast<const char16_t*>(ptr), 0,
1028 PLDM_STR_UTF_16_MAX_LEN);
1029 ptr += (u16NameString.size() + sizeof(nullTerminator)) *
1030 sizeof(uint16_t);
1031 std::transform(u16NameString.cbegin(), u16NameString.cend(),
1032 u16NameString.begin(),
1033 [](uint16_t utf16) { return be16toh(utf16); });
Patrick Williams15d42c52025-07-03 16:46:40 -04001034#pragma GCC diagnostic push
1035#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Thu Nguyen846d38f2022-03-26 08:57:21 +07001036 std::string nameString =
1037 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
1038 char16_t>{}
1039 .to_bytes(u16NameString);
Patrick Williams15d42c52025-07-03 16:46:40 -04001040#pragma GCC diagnostic pop
Thu Nguyen846d38f2022-03-26 08:57:21 +07001041 output[nameLanguageTagKey] = nameLanguageTag;
1042 output[entityAuxNameKey] = nameString;
1043 }
1044 }
1045 }
1046
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001047 void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +08001048 {
1049 struct pldm_numeric_effecter_value_pdr* pdr =
1050 (struct pldm_numeric_effecter_value_pdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301051 if (!pdr)
1052 {
1053 std::cerr << "Failed to get numeric effecter PDR" << std::endl;
1054 return;
1055 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001056
1057 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
1058 output["effecterID"] = int(pdr->effecter_id);
1059 output["entityType"] = int(pdr->entity_type);
1060 output["entityInstanceNumber"] = int(pdr->entity_instance);
1061 output["containerID"] = int(pdr->container_id);
1062 output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
1063 output["effecterInit"] = unsigned(pdr->effecter_init);
1064 output["effecterAuxiliaryNames"] =
1065 (unsigned(pdr->effecter_auxiliary_names) ? true : false);
1066 output["baseUnit"] = unsigned(pdr->base_unit);
1067 output["unitModifier"] = unsigned(pdr->unit_modifier);
1068 output["rateUnit"] = unsigned(pdr->rate_unit);
1069 output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
1070 output["auxUnit"] = unsigned(pdr->aux_unit);
1071 output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
1072 output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
1073 output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
1074 output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
1075 output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
1076 output["resolution"] = unsigned(pdr->resolution);
1077 output["offset"] = unsigned(pdr->offset);
1078 output["accuracy"] = unsigned(pdr->accuracy);
1079 output["plusTolerance"] = unsigned(pdr->plus_tolerance);
1080 output["minusTolerance"] = unsigned(pdr->minus_tolerance);
1081 output["stateTransitionInterval"] =
1082 unsigned(pdr->state_transition_interval);
1083 output["TransitionInterval"] = unsigned(pdr->transition_interval);
1084
George Liu62d12ec2020-02-05 16:27:08 +08001085 switch (pdr->effecter_data_size)
1086 {
1087 case PLDM_EFFECTER_DATA_SIZE_UINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301088 output["maxSettable"] = unsigned(pdr->max_settable.value_u8);
1089 output["minSettable"] = unsigned(pdr->min_settable.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001090 break;
1091 case PLDM_EFFECTER_DATA_SIZE_SINT8:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301092 output["maxSettable"] = unsigned(pdr->max_settable.value_s8);
1093 output["minSettable"] = unsigned(pdr->min_settable.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001094 break;
1095 case PLDM_EFFECTER_DATA_SIZE_UINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301096 output["maxSettable"] = unsigned(pdr->max_settable.value_u16);
1097 output["minSettable"] = unsigned(pdr->min_settable.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001098 break;
1099 case PLDM_EFFECTER_DATA_SIZE_SINT16:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301100 output["maxSettable"] = unsigned(pdr->max_settable.value_s16);
1101 output["minSettable"] = unsigned(pdr->min_settable.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001102 break;
1103 case PLDM_EFFECTER_DATA_SIZE_UINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301104 output["maxSettable"] = unsigned(pdr->max_settable.value_u32);
1105 output["minSettable"] = unsigned(pdr->min_settable.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001106 break;
1107 case PLDM_EFFECTER_DATA_SIZE_SINT32:
Manojkiran Edafc0ce972022-06-25 09:38:28 +05301108 output["maxSettable"] = unsigned(pdr->max_settable.value_s32);
1109 output["minSettable"] = unsigned(pdr->min_settable.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001110 break;
1111 default:
1112 break;
1113 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001114
1115 output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
1116 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1117
George Liu62d12ec2020-02-05 16:27:08 +08001118 switch (pdr->range_field_format)
1119 {
1120 case PLDM_RANGE_FIELD_FORMAT_UINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001121 output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
1122 output["normalMax"] = unsigned(pdr->normal_max.value_u8);
1123 output["normalMin"] = unsigned(pdr->normal_min.value_u8);
1124 output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
1125 output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
George Liu62d12ec2020-02-05 16:27:08 +08001126 break;
1127 case PLDM_RANGE_FIELD_FORMAT_SINT8:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001128 output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
1129 output["normalMax"] = unsigned(pdr->normal_max.value_s8);
1130 output["normalMin"] = unsigned(pdr->normal_min.value_s8);
1131 output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
1132 output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
George Liu62d12ec2020-02-05 16:27:08 +08001133 break;
1134 case PLDM_RANGE_FIELD_FORMAT_UINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001135 output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
1136 output["normalMax"] = unsigned(pdr->normal_max.value_u16);
1137 output["normalMin"] = unsigned(pdr->normal_min.value_u16);
1138 output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
1139 output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
George Liu62d12ec2020-02-05 16:27:08 +08001140 break;
1141 case PLDM_RANGE_FIELD_FORMAT_SINT16:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001142 output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
1143 output["normalMax"] = unsigned(pdr->normal_max.value_s16);
1144 output["normalMin"] = unsigned(pdr->normal_min.value_s16);
1145 output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
1146 output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
George Liu62d12ec2020-02-05 16:27:08 +08001147 break;
1148 case PLDM_RANGE_FIELD_FORMAT_UINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001149 output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
1150 output["normalMax"] = unsigned(pdr->normal_max.value_u32);
1151 output["normalMin"] = unsigned(pdr->normal_min.value_u32);
1152 output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
1153 output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
George Liu62d12ec2020-02-05 16:27:08 +08001154 break;
1155 case PLDM_RANGE_FIELD_FORMAT_SINT32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001156 output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
1157 output["normalMax"] = unsigned(pdr->normal_max.value_s32);
1158 output["normalMin"] = unsigned(pdr->normal_min.value_s32);
1159 output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
1160 output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
George Liu62d12ec2020-02-05 16:27:08 +08001161 break;
1162 case PLDM_RANGE_FIELD_FORMAT_REAL32:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001163 output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
1164 output["normalMax"] = unsigned(pdr->normal_max.value_f32);
1165 output["normalMin"] = unsigned(pdr->normal_min.value_f32);
1166 output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
1167 output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
George Liu62d12ec2020-02-05 16:27:08 +08001168 break;
1169 default:
1170 break;
1171 }
1172 }
1173
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001174 void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
George Liu62d12ec2020-02-05 16:27:08 +08001175 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301176 auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
George Liu62d12ec2020-02-05 16:27:08 +08001177
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001178 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1179 output["effecterID"] = pdr->effecter_id;
1180 output["entityType"] = getEntityName(pdr->entity_type);
1181 output["entityInstanceNumber"] = pdr->entity_instance;
1182 output["containerID"] = pdr->container_id;
1183 output["effecterSemanticID"] = pdr->effecter_semantic_id;
1184 output["effecterInit"] = effecterInit[pdr->effecter_init];
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001185 output["effecterDescriptionPDR"] =
1186 (pdr->has_description_pdr ? true : false);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001187 output["compositeEffecterCount"] =
1188 unsigned(pdr->composite_effecter_count);
George Liud6649362019-11-27 19:06:51 +08001189
Tom Joseph97a7a762020-07-06 10:37:18 +05301190 auto statesPtr = pdr->possible_states;
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001191 auto compEffCount = pdr->composite_effecter_count;
Tom Joseph97a7a762020-07-06 10:37:18 +05301192
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001193 while (compEffCount--)
George Liud6649362019-11-27 19:06:51 +08001194 {
Tom Joseph97a7a762020-07-06 10:37:18 +05301195 auto state =
1196 reinterpret_cast<const state_effecter_possible_states*>(
1197 statesPtr);
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001198 output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"),
1199 getStateSetName(state->state_set_id));
1200 output.emplace(
1201 ("possibleStatesSize[" + std::to_string(compEffCount) + "]"),
1202 state->possible_states_size);
1203 output.emplace(
1204 ("possibleStates[" + std::to_string(compEffCount) + "]"),
Sridevi Rameshdcdcd3b2021-06-15 04:06:49 -05001205 getStateSetPossibleStateNames(
1206 state->state_set_id,
1207 printPossibleStates(state->possible_states_size,
1208 state->states)));
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001209
Sridevi Ramesh148ccab2020-11-23 08:23:09 -06001210 if (compEffCount)
Tom Joseph97a7a762020-07-06 10:37:18 +05301211 {
1212 statesPtr += sizeof(state_effecter_possible_states) +
1213 state->possible_states_size - 1;
1214 }
George Liud6649362019-11-27 19:06:51 +08001215 }
1216 }
1217
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001218 bool checkTerminusHandle(const uint8_t* data,
1219 std::optional<uint16_t> terminusHandle)
1220 {
1221 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1222
1223 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1224 {
1225 auto tlpdr =
1226 reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1227
1228 if (tlpdr->terminus_handle != terminusHandle)
1229 {
1230 return true;
1231 }
1232 }
1233 else if (pdr->type == PLDM_STATE_SENSOR_PDR)
1234 {
1235 auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
1236
1237 if (sensor->terminus_handle != terminusHandle)
1238 {
1239 return true;
1240 }
1241 }
1242 else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR)
1243 {
1244 auto numericEffecter =
1245 reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data);
1246
1247 if (numericEffecter->terminus_handle != terminusHandle)
1248 {
1249 return true;
1250 }
1251 }
1252
1253 else if (pdr->type == PLDM_STATE_EFFECTER_PDR)
1254 {
1255 auto stateEffecter =
1256 reinterpret_cast<const pldm_state_effecter_pdr*>(data);
1257 if (stateEffecter->terminus_handle != terminusHandle)
1258 {
1259 return true;
1260 }
1261 }
1262 else if (pdr->type == PLDM_PDR_FRU_RECORD_SET)
1263 {
1264 data += sizeof(pldm_pdr_hdr);
1265 auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data);
1266
1267 if (fru->terminus_handle != terminusHandle)
1268 {
1269 return true;
1270 }
1271 }
1272 else
1273 {
1274 // Entity association PDRs does not have terminus handle
1275 return true;
1276 }
1277
1278 return false;
1279 }
1280
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001281 void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
Sampa Misra12afe112020-05-25 11:40:44 -05001282 {
1283 const std::array<std::string_view, 4> terminusLocatorType = {
1284 "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
1285
1286 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1287
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001288 output["PLDMTerminusHandle"] = pdr->terminus_handle;
1289 output["validity"] = (pdr->validity ? "valid" : "notValid");
1290 output["TID"] = unsigned(pdr->tid);
1291 output["containerID"] = pdr->container_id;
1292 output["terminusLocatorType"] =
1293 terminusLocatorType[pdr->terminus_locator_type];
1294 output["terminusLocatorValueSize"] =
1295 unsigned(pdr->terminus_locator_value_size);
Sampa Misra12afe112020-05-25 11:40:44 -05001296
1297 if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
1298 {
1299 auto locatorValue =
1300 reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
1301 pdr->terminus_locator_value);
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001302 output["EID"] = unsigned(locatorValue->eid);
Sampa Misra12afe112020-05-25 11:40:44 -05001303 }
1304 }
1305
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001306 std::optional<uint16_t> getTerminusHandle(uint8_t* data,
1307 std::optional<uint8_t> tid)
1308 {
1309 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
1310 if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR)
1311 {
1312 auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
1313 if (pdr->tid == tid)
1314 {
1315 handleFound = true;
1316 return pdr->terminus_handle;
1317 }
1318 }
1319 return std::nullopt;
1320 }
1321
nothingIIersonalcea52d92024-03-21 13:56:02 +03001322 /** @brief Format the Numeric Sensor PDR types to json output
1323 *
1324 * @param[in] data - reference to the Numeric Sensor PDR
1325 * @param[in] data_length - number of PDR data bytes
1326 * @param[out] output - PDRs data fields in Json format
1327 */
1328 void printNumericSensorPDR(const uint8_t* data, const uint16_t data_length,
1329 ordered_json& output)
1330 {
1331 struct pldm_numeric_sensor_value_pdr pdr;
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001332 int rc =
1333 decode_numeric_sensor_pdr_data(data, (size_t)data_length, &pdr);
nothingIIersonalcea52d92024-03-21 13:56:02 +03001334 if (rc != PLDM_SUCCESS)
1335 {
1336 std::cerr << "Failed to get numeric sensor PDR" << std::endl;
1337 return;
1338 }
1339 output["PLDMTerminusHandle"] = pdr.terminus_handle;
1340 output["sensorID"] = pdr.sensor_id;
1341 output["entityType"] = getEntityName(pdr.entity_type);
1342 output["entityInstanceNumber"] = pdr.entity_instance_num;
1343 output["containerID"] = pdr.container_id;
1344 output["sensorInit"] = pdr.sensor_init;
1345 output["sensorAuxiliaryNamesPDR"] =
1346 (pdr.sensor_auxiliary_names_pdr) ? true : false;
1347 output["baseUnit"] = pdr.base_unit;
1348 output["unitModifier"] = pdr.unit_modifier;
1349 output["rateUnit"] = pdr.rate_unit;
1350 output["baseOEMUnitHandle"] = pdr.base_oem_unit_handle;
1351 output["auxUnit"] = pdr.aux_unit;
1352 output["auxUnitModifier"] = pdr.aux_unit_modifier;
1353 output["auxrateUnit"] = pdr.aux_rate_unit;
1354 output["rel"] = pdr.rel;
1355 output["auxOEMUnitHandle"] = pdr.aux_oem_unit_handle;
1356 output["isLinear"] = (pdr.is_linear) ? true : false;
1357 output["sensorDataSize"] = pdr.sensor_data_size;
1358 output["resolution"] = pdr.resolution;
1359 output["offset"] = pdr.offset;
1360 output["accuracy"] = pdr.accuracy;
1361 output["plusTolerance"] = pdr.plus_tolerance;
1362 output["minusTolerance"] = pdr.minus_tolerance;
1363
1364 switch (pdr.sensor_data_size)
1365 {
1366 case PLDM_SENSOR_DATA_SIZE_UINT8:
1367 output["hysteresis"] = pdr.hysteresis.value_u8;
1368 output["maxReadable"] = pdr.max_readable.value_u8;
1369 output["minReadable"] = pdr.min_readable.value_u8;
1370 break;
1371 case PLDM_SENSOR_DATA_SIZE_SINT8:
1372 output["hysteresis"] = pdr.hysteresis.value_s8;
1373 output["maxReadable"] = pdr.max_readable.value_s8;
1374 output["minReadable"] = pdr.min_readable.value_s8;
1375 break;
1376 case PLDM_SENSOR_DATA_SIZE_UINT16:
1377 output["hysteresis"] = pdr.hysteresis.value_u16;
1378 output["maxReadable"] = pdr.max_readable.value_u16;
1379 output["minReadable"] = pdr.min_readable.value_u16;
1380 break;
1381 case PLDM_SENSOR_DATA_SIZE_SINT16:
1382 output["hysteresis"] = pdr.hysteresis.value_s16;
1383 output["maxReadable"] = pdr.max_readable.value_s16;
1384 output["minReadable"] = pdr.min_readable.value_s16;
1385 break;
1386 case PLDM_SENSOR_DATA_SIZE_UINT32:
1387 output["hysteresis"] = pdr.hysteresis.value_u32;
1388 output["maxReadable"] = pdr.max_readable.value_u32;
1389 output["minReadable"] = pdr.min_readable.value_u32;
1390 break;
1391 case PLDM_SENSOR_DATA_SIZE_SINT32:
1392 output["hysteresis"] = pdr.hysteresis.value_s32;
1393 output["maxReadable"] = pdr.max_readable.value_s32;
1394 output["minReadable"] = pdr.min_readable.value_s32;
1395 break;
1396 default:
1397 break;
1398 }
1399
1400 output["supportedThresholds"] = pdr.supported_thresholds.byte;
1401 output["thresholAndHysteresisVolatility"] =
1402 pdr.threshold_and_hysteresis_volatility.byte;
1403 output["stateTransitionInterval"] = pdr.state_transition_interval;
1404 output["updateInterval"] = pdr.update_interval;
1405 output["rangeFieldFormat"] = pdr.range_field_format;
1406 output["rangeFieldSupport"] = pdr.range_field_support.byte;
1407
1408 switch (pdr.range_field_format)
1409 {
1410 case PLDM_RANGE_FIELD_FORMAT_UINT8:
1411 output["nominalValue"] = pdr.nominal_value.value_u8;
1412 output["normalMax"] = pdr.normal_max.value_u8;
1413 output["normalMin"] = pdr.normal_min.value_u8;
1414 output["warningHigh"] = pdr.warning_high.value_u8;
1415 output["warningLow"] = pdr.warning_low.value_u8;
1416 output["criticalHigh"] = pdr.critical_high.value_u8;
1417 output["criticalLow"] = pdr.critical_low.value_u8;
1418 output["fatalHigh"] = pdr.fatal_high.value_u8;
1419 output["fatalLeow"] = pdr.fatal_low.value_u8;
1420 break;
1421 case PLDM_RANGE_FIELD_FORMAT_SINT8:
1422 output["nominalValue"] = pdr.nominal_value.value_s8;
1423 output["normalMax"] = pdr.normal_max.value_s8;
1424 output["normalMin"] = pdr.normal_min.value_s8;
1425 output["warningHigh"] = pdr.warning_high.value_s8;
1426 output["warningLow"] = pdr.warning_low.value_s8;
1427 output["criticalHigh"] = pdr.critical_high.value_s8;
1428 output["criticalLow"] = pdr.critical_low.value_s8;
1429 output["fatalHigh"] = pdr.fatal_high.value_s8;
1430 output["fatalLeow"] = pdr.fatal_low.value_s8;
1431 break;
1432 case PLDM_RANGE_FIELD_FORMAT_UINT16:
1433 output["nominalValue"] = pdr.nominal_value.value_u16;
1434 output["normalMax"] = pdr.normal_max.value_u16;
1435 output["normalMin"] = pdr.normal_min.value_u16;
1436 output["warningHigh"] = pdr.warning_high.value_u16;
1437 output["warningLow"] = pdr.warning_low.value_u16;
1438 output["criticalHigh"] = pdr.critical_high.value_u16;
1439 output["criticalLow"] = pdr.critical_low.value_u16;
1440 output["fatalHigh"] = pdr.fatal_high.value_u16;
1441 output["fatalLeow"] = pdr.fatal_low.value_u16;
1442 break;
1443 case PLDM_RANGE_FIELD_FORMAT_SINT16:
1444 output["nominalValue"] = pdr.nominal_value.value_s16;
1445 output["normalMax"] = pdr.normal_max.value_s16;
1446 output["normalMin"] = pdr.normal_min.value_s16;
1447 output["warningHigh"] = pdr.warning_high.value_s16;
1448 output["warningLow"] = pdr.warning_low.value_s16;
1449 output["criticalHigh"] = pdr.critical_high.value_s16;
1450 output["criticalLow"] = pdr.critical_low.value_s16;
1451 output["fatalHigh"] = pdr.fatal_high.value_s16;
1452 output["fatalLeow"] = pdr.fatal_low.value_s16;
1453 break;
1454 case PLDM_RANGE_FIELD_FORMAT_UINT32:
1455 output["nominalValue"] = pdr.nominal_value.value_u32;
1456 output["normalMax"] = pdr.normal_max.value_u32;
1457 output["normalMin"] = pdr.normal_min.value_u32;
1458 output["warningHigh"] = pdr.warning_high.value_u32;
1459 output["warningLow"] = pdr.warning_low.value_u32;
1460 output["criticalHigh"] = pdr.critical_high.value_u32;
1461 output["criticalLow"] = pdr.critical_low.value_u32;
1462 output["fatalHigh"] = pdr.fatal_high.value_u32;
1463 output["fatalLeow"] = pdr.fatal_low.value_u32;
1464 break;
1465 case PLDM_RANGE_FIELD_FORMAT_SINT32:
1466 output["nominalValue"] = pdr.nominal_value.value_s32;
1467 output["normalMax"] = pdr.normal_max.value_s32;
1468 output["normalMin"] = pdr.normal_min.value_s32;
1469 output["warningHigh"] = pdr.warning_high.value_s32;
1470 output["warningLow"] = pdr.warning_low.value_s32;
1471 output["criticalHigh"] = pdr.critical_high.value_s32;
1472 output["criticalLow"] = pdr.critical_low.value_s32;
1473 output["fatalHigh"] = pdr.fatal_high.value_s32;
1474 output["fatalLeow"] = pdr.fatal_low.value_s32;
1475 break;
1476 case PLDM_RANGE_FIELD_FORMAT_REAL32:
1477 output["nominalValue"] = pdr.nominal_value.value_f32;
1478 output["normalMax"] = pdr.normal_max.value_f32;
1479 output["normalMin"] = pdr.normal_min.value_f32;
1480 output["warningHigh"] = pdr.warning_high.value_f32;
1481 output["warningLow"] = pdr.warning_low.value_f32;
1482 output["criticalHigh"] = pdr.critical_high.value_f32;
1483 output["criticalLow"] = pdr.critical_low.value_f32;
1484 output["fatalHigh"] = pdr.fatal_high.value_f32;
1485 output["fatalLeow"] = pdr.fatal_low.value_f32;
1486 break;
1487 default:
1488 break;
1489 }
1490 }
1491
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001492 /** @brief Format the Compact Numeric Sensor PDR types to json output
1493 *
1494 * @param[in] data - reference to the Compact Numeric Sensor PDR
1495 * @param[out] output - PDRs data fields in Json format
1496 */
1497 void printCompactNumericSensorPDR(const uint8_t* data, ordered_json& output)
1498 {
1499 struct pldm_compact_numeric_sensor_pdr* pdr =
1500 (struct pldm_compact_numeric_sensor_pdr*)data;
1501 if (!pdr)
1502 {
1503 std::cerr << "Failed to get compact numeric sensor PDR"
1504 << std::endl;
1505 return;
1506 }
1507 output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
1508 output["sensorID"] = int(pdr->sensor_id);
1509 output["entityType"] = getEntityName(pdr->entity_type);
1510 output["entityInstanceNumber"] = int(pdr->entity_instance);
1511 output["containerID"] = int(pdr->container_id);
1512 output["sensorNameStringByteLength"] = int(pdr->sensor_name_length);
1513 if (pdr->sensor_name_length == 0)
1514 {
1515 output["Name"] = std::format("PLDM_Device_TID{}_SensorId{}",
1516 unsigned(pdr->terminus_handle),
1517 unsigned(pdr->sensor_id));
1518 }
1519 else
1520 {
1521 std::string sTemp(reinterpret_cast<const char*>(pdr->sensor_name),
1522 pdr->sensor_name_length);
1523 output["Name"] = sTemp;
1524 }
1525 output["baseUnit"] = unsigned(pdr->base_unit);
1526 output["unitModifier"] = signed(pdr->unit_modifier);
1527 output["occurrenceRate"] = unsigned(pdr->occurrence_rate);
1528 output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
1529 if (pdr->range_field_support.bits.bit0)
1530 {
1531 output["warningHigh"] = int(pdr->warning_high);
1532 }
1533 if (pdr->range_field_support.bits.bit1)
1534 {
1535 output["warningLow"] = int(pdr->warning_low);
1536 }
1537 if (pdr->range_field_support.bits.bit2)
1538 {
1539 output["criticalHigh"] = int(pdr->critical_high);
1540 }
1541 if (pdr->range_field_support.bits.bit3)
1542 {
1543 output["criticalLow"] = int(pdr->critical_low);
1544 }
1545 if (pdr->range_field_support.bits.bit4)
1546 {
1547 output["fatalHigh"] = int(pdr->fatal_high);
1548 }
1549 if (pdr->range_field_support.bits.bit5)
1550 {
1551 output["fatalLow"] = int(pdr->fatal_low);
1552 }
1553 }
1554
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001555 void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt,
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001556 uint8_t* data, std::optional<uint16_t> terminusHandle)
George Liud6649362019-11-27 19:06:51 +08001557 {
Jayanth Othayoth7c14fc42024-12-17 10:24:47 -06001558 if (data == nullptr)
George Liud6649362019-11-27 19:06:51 +08001559 {
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301560 std::cerr << "Failed to get PDR message" << std::endl;
George Liud6649362019-11-27 19:06:51 +08001561 return;
1562 }
1563
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001564 ordered_json output;
1565 output["nextRecordHandle"] = nextRecordHndl;
1566 output["responseCount"] = respCnt;
George Liud6649362019-11-27 19:06:51 +08001567
1568 struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
Manojkiran Edabcf91ac2021-03-14 13:50:48 +05301569 if (!pdr)
1570 {
1571 return;
1572 }
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001573
1574 if (!pdrRecType.empty())
1575 {
1576 // Need to return if the requested PDR type
1577 // is not supported
1578 if (!strToPdrType.contains(pdrRecType))
1579 {
1580 std::cerr << "PDR type '" << pdrRecType
1581 << "' is not supported or invalid\n";
Pavithra Barithaya6e20f7c2023-08-22 00:50:47 -05001582 // PDR type not supported, setting next record handle to
1583 // 0 to avoid looping through all PDR records
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001584 nextRecordHndl = 0;
1585 return;
1586 }
1587
1588 // Do not print PDR record if the current record
1589 // PDR type does not match with requested type
1590 if (pdr->type != strToPdrType.at(pdrRecType))
1591 {
1592 return;
1593 }
1594 }
1595
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001596 if (pdrTerminus.has_value())
1597 {
1598 if (checkTerminusHandle(data, terminusHandle))
1599 {
1600 std::cerr << "The Terminus handle doesn't match return"
1601 << std::endl;
1602 return;
1603 }
1604 }
1605
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001606 printCommonPDRHeader(pdr, output);
1607
George Liud6649362019-11-27 19:06:51 +08001608 switch (pdr->type)
1609 {
Sampa Misra12afe112020-05-25 11:40:44 -05001610 case PLDM_TERMINUS_LOCATOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001611 printTerminusLocatorPDR(data, output);
Sampa Misra12afe112020-05-25 11:40:44 -05001612 break;
Tom Josepha65c0412020-07-03 21:14:44 +05301613 case PLDM_STATE_SENSOR_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001614 printStateSensorPDR(data, output);
Tom Josepha65c0412020-07-03 21:14:44 +05301615 break;
George Liu62d12ec2020-02-05 16:27:08 +08001616 case PLDM_NUMERIC_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001617 printNumericEffecterPDR(data, output);
George Liu62d12ec2020-02-05 16:27:08 +08001618 break;
nothingIIersonalcea52d92024-03-21 13:56:02 +03001619 case PLDM_NUMERIC_SENSOR_PDR:
1620 printNumericSensorPDR(data, respCnt, output);
1621 break;
Thu Nguyen846d38f2022-03-26 08:57:21 +07001622 case PLDM_SENSOR_AUXILIARY_NAMES_PDR:
Thu Nguyen846d38f2022-03-26 08:57:21 +07001623 case PLDM_EFFECTER_AUXILIARY_NAMES_PDR:
1624 printAuxNamePDR(data, output);
1625 break;
George Liud6649362019-11-27 19:06:51 +08001626 case PLDM_STATE_EFFECTER_PDR:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001627 printStateEffecterPDR(data, output);
George Liud6649362019-11-27 19:06:51 +08001628 break;
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001629 case PLDM_PDR_ENTITY_ASSOCIATION:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001630 printPDREntityAssociation(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001631 break;
1632 case PLDM_PDR_FRU_RECORD_SET:
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001633 printPDRFruRecordSet(data, output);
Deepak Kodihalli5544ccd2020-03-15 23:36:16 -05001634 break;
Thu Nguyen9d0e58c2021-12-09 13:53:00 +07001635 case PLDM_COMPACT_NUMERIC_SENSOR_PDR:
1636 printCompactNumericSensorPDR(data, output);
1637 break;
George Liud6649362019-11-27 19:06:51 +08001638 default:
1639 break;
1640 }
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001641 pldmtool::helper::DisplayInJson(output);
George Liud6649362019-11-27 19:06:51 +08001642 }
1643
1644 private:
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001645 bool optTIDSet = false;
George Liud6649362019-11-27 19:06:51 +08001646 uint32_t recordHandle;
Shantappa Teekappanavar3ddbe432021-06-29 15:46:06 -05001647 bool allPDRs;
1648 std::string pdrRecType;
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06001649 std::optional<uint8_t> pdrTerminus;
1650 std::optional<uint16_t> terminusHandle;
1651 bool handleFound = false;
1652 CLI::Option* getPDRGroupOption = nullptr;
Potin Lai3e52d582024-06-13 11:03:46 +08001653 uint32_t dataTransferHandle;
1654 uint8_t operationFlag;
1655 uint16_t requestCount;
1656 uint16_t recordChangeNumber;
1657 std::vector<uint8_t> recordData;
1658 bool nextPartRequired;
George Liud6649362019-11-27 19:06:51 +08001659};
1660
1661class SetStateEffecter : public CommandInterface
1662{
1663 public:
1664 ~SetStateEffecter() = default;
1665 SetStateEffecter() = delete;
1666 SetStateEffecter(const SetStateEffecter&) = delete;
1667 SetStateEffecter(SetStateEffecter&&) = default;
1668 SetStateEffecter& operator=(const SetStateEffecter&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001669 SetStateEffecter& operator=(SetStateEffecter&&) = delete;
George Liud6649362019-11-27 19:06:51 +08001670
George Liuba4c1fb2020-02-05 14:13:30 +08001671 // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2)
1672 static constexpr auto maxEffecterDataSize = 16;
1673
1674 // compositeEffecterCount(value: 0x01 to 0x08)
1675 static constexpr auto minEffecterCount = 1;
1676 static constexpr auto maxEffecterCount = 8;
George Liud6649362019-11-27 19:06:51 +08001677 explicit SetStateEffecter(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001678 CLI::App* app) : CommandInterface(type, name, app)
George Liud6649362019-11-27 19:06:51 +08001679 {
1680 app->add_option(
George Liuba4c1fb2020-02-05 14:13:30 +08001681 "-i, --id", effecterId,
1682 "A handle that is used to identify and access the effecter")
1683 ->required();
1684 app->add_option("-c, --count", effecterCount,
1685 "The number of individual sets of effecter information")
1686 ->required();
1687 app->add_option(
George Liud6649362019-11-27 19:06:51 +08001688 "-d,--data", effecterData,
George Liuba4c1fb2020-02-05 14:13:30 +08001689 "Set effecter state data\n"
1690 "eg: requestSet0 effecterState0 noChange1 dummyState1 ...")
1691 ->required();
George Liud6649362019-11-27 19:06:51 +08001692 }
1693
1694 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1695 {
1696 std::vector<uint8_t> requestMsg(
1697 sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301698 auto request = new (requestMsg.data()) pldm_msg;
George Liud6649362019-11-27 19:06:51 +08001699
George Liuba4c1fb2020-02-05 14:13:30 +08001700 if (effecterCount > maxEffecterCount ||
1701 effecterCount < minEffecterCount)
George Liud6649362019-11-27 19:06:51 +08001702 {
George Liuba4c1fb2020-02-05 14:13:30 +08001703 std::cerr << "Request Message Error: effecterCount size "
1704 << effecterCount << "is invalid\n";
George Liud6649362019-11-27 19:06:51 +08001705 auto rc = PLDM_ERROR_INVALID_DATA;
1706 return {rc, requestMsg};
1707 }
1708
George Liuba4c1fb2020-02-05 14:13:30 +08001709 if (effecterData.size() > maxEffecterDataSize)
George Liud6649362019-11-27 19:06:51 +08001710 {
George Liuba4c1fb2020-02-05 14:13:30 +08001711 std::cerr << "Request Message Error: effecterData size "
1712 << effecterData.size() << "is invalid\n";
1713 auto rc = PLDM_ERROR_INVALID_DATA;
1714 return {rc, requestMsg};
1715 }
1716
1717 auto stateField = parseEffecterData(effecterData, effecterCount);
1718 if (!stateField)
1719 {
1720 std::cerr << "Failed to parse effecter data, effecterCount size "
1721 << effecterCount << "\n";
George Liud6649362019-11-27 19:06:51 +08001722 auto rc = PLDM_ERROR_INVALID_DATA;
1723 return {rc, requestMsg};
1724 }
1725
1726 auto rc = encode_set_state_effecter_states_req(
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -06001727 instanceId, effecterId, effecterCount, stateField->data(), request);
George Liud6649362019-11-27 19:06:51 +08001728 return {rc, requestMsg};
1729 }
1730
1731 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1732 {
1733 uint8_t completionCode = 0;
1734 auto rc = decode_set_state_effecter_states_resp(
1735 responsePtr, payloadLength, &completionCode);
1736
1737 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1738 {
1739 std::cerr << "Response Message Error: "
George Liuba4c1fb2020-02-05 14:13:30 +08001740 << "rc=" << rc << ",cc=" << (int)completionCode << "\n";
George Liud6649362019-11-27 19:06:51 +08001741 return;
1742 }
1743
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001744 ordered_json data;
1745 data["Response"] = "SUCCESS";
1746 pldmtool::helper::DisplayInJson(data);
George Liud6649362019-11-27 19:06:51 +08001747 }
1748
1749 private:
George Liuba4c1fb2020-02-05 14:13:30 +08001750 uint16_t effecterId;
1751 uint8_t effecterCount;
George Liud6649362019-11-27 19:06:51 +08001752 std::vector<uint8_t> effecterData;
1753};
1754
George Liucc9c20d2020-02-05 10:24:11 +08001755class SetNumericEffecterValue : public CommandInterface
1756{
1757 public:
1758 ~SetNumericEffecterValue() = default;
1759 SetNumericEffecterValue() = delete;
1760 SetNumericEffecterValue(const SetNumericEffecterValue&) = delete;
1761 SetNumericEffecterValue(SetNumericEffecterValue&&) = default;
1762 SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001763 SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete;
George Liucc9c20d2020-02-05 10:24:11 +08001764
1765 explicit SetNumericEffecterValue(const char* type, const char* name,
1766 CLI::App* app) :
1767 CommandInterface(type, name, app)
1768 {
1769 app->add_option(
1770 "-i, --id", effecterId,
1771 "A handle that is used to identify and access the effecter")
1772 ->required();
1773 app->add_option("-s, --size", effecterDataSize,
1774 "The bit width and format of the setting value for the "
1775 "effecter. enum value: {uint8, sint8, uint16, sint16, "
1776 "uint32, sint32}\n")
1777 ->required();
1778 app->add_option("-d,--data", maxEffecterValue,
1779 "The setting value of numeric effecter being "
1780 "requested\n")
1781 ->required();
1782 }
1783
1784 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1785 {
1786 std::vector<uint8_t> requestMsg(
1787 sizeof(pldm_msg_hdr) +
1788 PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3);
1789
1790 uint8_t* effecterValue = (uint8_t*)&maxEffecterValue;
1791
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301792 auto request = new (requestMsg.data()) pldm_msg;
1793
George Liucc9c20d2020-02-05 10:24:11 +08001794 size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES;
1795
1796 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
1797 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16)
1798 {
1799 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1;
1800 }
1801 if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
1802 effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32)
1803 {
1804 payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3;
1805 }
1806 auto rc = encode_set_numeric_effecter_value_req(
1807 0, effecterId, effecterDataSize, effecterValue, request,
1808 payload_length);
1809
1810 return {rc, requestMsg};
1811 }
1812
1813 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1814 {
1815 uint8_t completionCode = 0;
1816 auto rc = decode_set_numeric_effecter_value_resp(
1817 responsePtr, payloadLength, &completionCode);
1818
1819 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1820 {
1821 std::cerr << "Response Message Error: "
1822 << "rc=" << rc << ",cc=" << (int)completionCode
1823 << std::endl;
1824 return;
1825 }
1826
Sridevi Ramesh27c512a2020-08-12 03:29:42 -05001827 ordered_json data;
1828 data["Response"] = "SUCCESS";
1829 pldmtool::helper::DisplayInJson(data);
George Liucc9c20d2020-02-05 10:24:11 +08001830 }
1831
1832 private:
1833 uint16_t effecterId;
1834 uint8_t effecterDataSize;
1835 uint64_t maxEffecterValue;
1836};
1837
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001838class GetStateSensorReadings : public CommandInterface
1839{
1840 public:
1841 ~GetStateSensorReadings() = default;
1842 GetStateSensorReadings() = delete;
1843 GetStateSensorReadings(const GetStateSensorReadings&) = delete;
1844 GetStateSensorReadings(GetStateSensorReadings&&) = default;
1845 GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -05001846 GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001847
1848 explicit GetStateSensorReadings(const char* type, const char* name,
1849 CLI::App* app) :
1850 CommandInterface(type, name, app)
1851 {
1852 app->add_option(
1853 "-i, --sensor_id", sensorId,
1854 "Sensor ID that is used to identify and access the sensor")
1855 ->required();
1856 app->add_option("-r, --rearm", sensorRearm,
1857 "Each bit location in this field corresponds to a "
1858 "particular sensor")
1859 ->required();
1860 }
1861
1862 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1863 {
1864 std::vector<uint8_t> requestMsg(
1865 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301866 auto request = new (requestMsg.data()) pldm_msg;
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001867
1868 uint8_t reserved = 0;
1869 bitfield8_t bf;
1870 bf.byte = sensorRearm;
1871 auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf,
1872 reserved, request);
1873
1874 return {rc, requestMsg};
1875 }
1876
1877 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1878 {
1879 uint8_t completionCode = 0;
1880 uint8_t compSensorCount = 0;
1881 std::array<get_sensor_state_field, 8> stateField{};
1882 auto rc = decode_get_state_sensor_readings_resp(
1883 responsePtr, payloadLength, &completionCode, &compSensorCount,
1884 stateField.data());
1885
1886 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1887 {
1888 std::cerr << "Response Message Error: "
1889 << "rc=" << rc << ",cc=" << (int)completionCode
1890 << std::endl;
1891 return;
1892 }
1893 ordered_json output;
1894 output["compositeSensorCount"] = (int)compSensorCount;
1895
1896 for (size_t i = 0; i < compSensorCount; i++)
1897 {
George Liubd5e2ea2021-04-22 20:33:06 +08001898 if (sensorOpState.contains(stateField[i].sensor_op_state))
1899 {
1900 output.emplace(("sensorOpState[" + std::to_string(i) + "]"),
1901 sensorOpState.at(stateField[i].sensor_op_state));
1902 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001903
George Liubd5e2ea2021-04-22 20:33:06 +08001904 if (sensorPresState.contains(stateField[i].present_state))
1905 {
1906 output.emplace(("presentState[" + std::to_string(i) + "]"),
1907 sensorPresState.at(stateField[i].present_state));
1908 }
1909
1910 if (sensorPresState.contains(stateField[i].previous_state))
1911 {
1912 output.emplace(
1913 ("previousState[" + std::to_string(i) + "]"),
1914 sensorPresState.at(stateField[i].previous_state));
1915 }
1916
1917 if (sensorPresState.contains(stateField[i].event_state))
1918 {
1919 output.emplace(("eventState[" + std::to_string(i) + "]"),
1920 sensorPresState.at(stateField[i].event_state));
1921 }
Sridevi Rameshf31b5042021-01-22 05:42:07 -06001922 }
1923
1924 pldmtool::helper::DisplayInJson(output);
1925 }
1926
1927 private:
1928 uint16_t sensorId;
1929 uint8_t sensorRearm;
1930};
1931
nothingIIersonal83e068a2024-03-21 13:55:06 +03001932class GetSensorReading : public CommandInterface
1933{
1934 public:
1935 ~GetSensorReading() = default;
1936 GetSensorReading() = delete;
1937 GetSensorReading(const GetSensorReading&) = delete;
1938 GetSensorReading(GetSensorReading&&) = default;
1939 GetSensorReading& operator=(const GetSensorReading&) = delete;
1940 GetSensorReading& operator=(GetSensorReading&&) = delete;
1941
1942 explicit GetSensorReading(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001943 CLI::App* app) : CommandInterface(type, name, app)
nothingIIersonal83e068a2024-03-21 13:55:06 +03001944 {
1945 app->add_option(
1946 "-i, --sensor_id", sensorId,
1947 "Sensor ID that is used to identify and access the sensor")
1948 ->required();
1949 app->add_option("-r, --rearm", rearm,
1950 "Manually re-arm EventState after "
1951 "responding to this request")
1952 ->required();
1953 }
1954
1955 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
1956 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001957 std::vector<uint8_t> requestMsg(
1958 sizeof(pldm_msg_hdr) + PLDM_GET_SENSOR_READING_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05301959 auto request = new (requestMsg.data()) pldm_msg;
nothingIIersonal83e068a2024-03-21 13:55:06 +03001960
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001961 auto rc =
1962 encode_get_sensor_reading_req(instanceId, sensorId, rearm, request);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001963
1964 return {rc, requestMsg};
1965 }
1966
1967 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
1968 {
1969 uint8_t completionCode = 0;
1970 uint8_t sensorDataSize = 0;
1971 uint8_t sensorOperationalState = 0;
1972 uint8_t sensorEventMessageEnable = 0;
1973 uint8_t presentState = 0;
1974 uint8_t previousState = 0;
1975 uint8_t eventState = 0;
1976 std::array<uint8_t, sizeof(uint32_t)>
1977 presentReading{}; // maximum size for the present Value is uint32
1978 // according to spec DSP0248
1979
1980 auto rc = decode_get_sensor_reading_resp(
1981 responsePtr, payloadLength, &completionCode, &sensorDataSize,
1982 &sensorOperationalState, &sensorEventMessageEnable, &presentState,
1983 &previousState, &eventState, presentReading.data());
1984
1985 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
1986 {
1987 std::cerr << "Response Message Error: "
1988 << "rc=" << rc << ",cc=" << (int)completionCode
1989 << std::endl;
1990 return;
1991 }
1992
1993 ordered_json output;
Patrick Williams16c2a0a2024-08-16 15:20:59 -04001994 output["sensorDataSize"] =
1995 getSensorState(sensorDataSize, &sensorDataSz);
nothingIIersonal83e068a2024-03-21 13:55:06 +03001996 output["sensorOperationalState"] =
1997 getSensorState(sensorOperationalState, &sensorOpState);
1998 output["sensorEventMessageEnable"] =
1999 getSensorState(sensorEventMessageEnable, &sensorEventMsgEnable);
2000 output["presentState"] = getSensorState(presentState, &sensorPresState);
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002001 output["previousState"] =
2002 getSensorState(previousState, &sensorPresState);
nothingIIersonal83e068a2024-03-21 13:55:06 +03002003 output["eventState"] = getSensorState(eventState, &sensorPresState);
2004
2005 switch (sensorDataSize)
2006 {
2007 case PLDM_SENSOR_DATA_SIZE_UINT8:
2008 {
2009 output["presentReading"] =
2010 *(reinterpret_cast<uint8_t*>(presentReading.data()));
2011 break;
2012 }
2013 case PLDM_SENSOR_DATA_SIZE_SINT8:
2014 {
2015 output["presentReading"] =
2016 *(reinterpret_cast<int8_t*>(presentReading.data()));
2017 break;
2018 }
2019 case PLDM_SENSOR_DATA_SIZE_UINT16:
2020 {
2021 output["presentReading"] =
2022 *(reinterpret_cast<uint16_t*>(presentReading.data()));
2023 break;
2024 }
2025 case PLDM_SENSOR_DATA_SIZE_SINT16:
2026 {
2027 output["presentReading"] =
2028 *(reinterpret_cast<int16_t*>(presentReading.data()));
2029 break;
2030 }
2031 case PLDM_SENSOR_DATA_SIZE_UINT32:
2032 {
2033 output["presentReading"] =
2034 *(reinterpret_cast<uint32_t*>(presentReading.data()));
2035 break;
2036 }
2037 case PLDM_SENSOR_DATA_SIZE_SINT32:
2038 {
2039 output["presentReading"] =
2040 *(reinterpret_cast<int32_t*>(presentReading.data()));
2041 break;
2042 }
2043 default:
2044 {
2045 std::cerr << "Unknown Sensor Data Size : "
2046 << static_cast<int>(sensorDataSize) << std::endl;
2047 break;
2048 }
2049 }
2050
2051 pldmtool::helper::DisplayInJson(output);
2052 }
2053
2054 private:
2055 uint16_t sensorId;
2056 uint8_t rearm;
2057
2058 const std::map<uint8_t, std::string> sensorDataSz = {
2059 {PLDM_SENSOR_DATA_SIZE_UINT8, "uint8"},
2060 {PLDM_SENSOR_DATA_SIZE_SINT8, "uint8"},
2061 {PLDM_SENSOR_DATA_SIZE_UINT16, "uint16"},
2062 {PLDM_SENSOR_DATA_SIZE_SINT16, "uint16"},
2063 {PLDM_SENSOR_DATA_SIZE_UINT32, "uint32"},
2064 {PLDM_SENSOR_DATA_SIZE_SINT32, "uint32"}};
2065
2066 static inline const std::map<uint8_t, std::string> sensorEventMsgEnable{
2067 {PLDM_NO_EVENT_GENERATION, "Sensor No Event Generation"},
2068 {PLDM_EVENTS_DISABLED, "Sensor Events Disabled"},
2069 {PLDM_EVENTS_ENABLED, "Sensor Events Enabled"},
2070 {PLDM_OP_EVENTS_ONLY_ENABLED, "Sensor Op Events Only Enabled"},
2071 {PLDM_STATE_EVENTS_ONLY_ENABLED, "Sensor State Events Only Enabled"}};
2072
2073 std::string getSensorState(uint8_t state,
2074 const std::map<uint8_t, std::string>* cont)
2075 {
2076 auto typeString = std::to_string(state);
2077 try
2078 {
2079 return cont->at(state);
2080 }
2081 catch (const std::out_of_range& e)
2082 {
2083 return typeString;
2084 }
2085 }
2086};
2087
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002088class GetStateEffecterStates : public CommandInterface
2089{
2090 public:
2091 ~GetStateEffecterStates() = default;
2092 GetStateEffecterStates() = delete;
2093 GetStateEffecterStates(const GetStateEffecterStates&) = delete;
2094 GetStateEffecterStates(GetStateEffecterStates&&) = default;
2095 GetStateEffecterStates& operator=(const GetStateEffecterStates&) = delete;
2096 GetStateEffecterStates& operator=(GetStateEffecterStates&&) = delete;
2097
2098 explicit GetStateEffecterStates(const char* type, const char* name,
2099 CLI::App* app) :
2100 CommandInterface(type, name, app)
2101 {
2102 app->add_option(
2103 "-i, --effecter_id", effecter_id,
2104 "Effecter ID that is used to identify and access the effecter")
2105 ->required();
2106 }
2107
2108 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2109 {
2110 std::vector<uint8_t> requestMsg(
2111 sizeof(pldm_msg_hdr) + PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05302112 auto request = new (requestMsg.data()) pldm_msg;
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002113
2114 auto rc = encode_get_state_effecter_states_req(
2115 instanceId, effecter_id, request,
2116 PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES);
2117
2118 return {rc, requestMsg};
2119 }
2120
2121 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2122 {
2123 struct pldm_get_state_effecter_states_resp resp;
2124 auto rc = decode_get_state_effecter_states_resp(responsePtr,
2125 payloadLength, &resp);
2126
2127 if (rc || resp.completion_code != PLDM_SUCCESS)
2128 {
2129 std::cerr << "Response Message Error: "
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002130 << "rc=" << rc << ",cc="
2131 << static_cast<int>(resp.completion_code) << std::endl;
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002132 return;
2133 }
2134 ordered_json output;
2135 auto comp_effecter_count = static_cast<int>(resp.comp_effecter_count);
2136 output["compositeEffecterCount"] = comp_effecter_count;
2137
Tal Yacobi92af05e2024-07-28 14:18:07 +03002138 for (auto i : std::views::iota(0, comp_effecter_count))
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002139 {
2140 output[std::format("effecterOpState[{}])", i)] =
2141 getEffecterOpState(resp.field[i].effecter_op_state);
2142
2143 output[std::format("pendingState[{}]", i)] =
2144 resp.field[i].pending_state;
2145
2146 output[std::format("presentState[{}]", i)] =
2147 resp.field[i].present_state;
2148 }
2149
2150 pldmtool::helper::DisplayInJson(output);
2151 }
2152
2153 private:
2154 uint16_t effecter_id;
2155};
2156
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002157class GetNumericEffecterValue : public CommandInterface
2158{
2159 public:
2160 ~GetNumericEffecterValue() = default;
2161 GetNumericEffecterValue() = delete;
2162 GetNumericEffecterValue(const GetNumericEffecterValue&) = delete;
2163 GetNumericEffecterValue(GetNumericEffecterValue&&) = default;
2164 GetNumericEffecterValue& operator=(const GetNumericEffecterValue&) = delete;
Pavithra Barithayaae088dc2023-11-09 01:14:05 -06002165 GetNumericEffecterValue& operator=(GetNumericEffecterValue&&) = delete;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002166
2167 explicit GetNumericEffecterValue(const char* type, const char* name,
2168 CLI::App* app) :
2169 CommandInterface(type, name, app)
2170 {
2171 app->add_option(
2172 "-i, --effecter_id", effecterId,
2173 "A handle that is used to identify and access the effecter")
2174 ->required();
2175 }
2176
2177 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
2178 {
2179 std::vector<uint8_t> requestMsg(
2180 sizeof(pldm_msg_hdr) + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES);
Pavithra Barithaya5c3f0d12025-01-30 14:05:49 +05302181 auto request = new (requestMsg.data()) pldm_msg;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002182
2183 auto rc = encode_get_numeric_effecter_value_req(instanceId, effecterId,
2184 request);
2185
2186 return {rc, requestMsg};
2187 }
2188
2189 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
2190 {
2191 uint8_t completionCode = 0;
2192 uint8_t effecterDataSize = 0;
2193 uint8_t effecterOperationalState = 0;
2194 std::array<uint8_t, sizeof(uint32_t)>
2195 pendingValue{}; // maximum size for the pending Value is uint32
2196 // according to spec DSP0248
2197 std::array<uint8_t, sizeof(uint32_t)>
2198 presentValue{}; // maximum size for the present Value is uint32
2199 // according to spec DSP0248
2200
2201 auto rc = decode_get_numeric_effecter_value_resp(
2202 responsePtr, payloadLength, &completionCode, &effecterDataSize,
2203 &effecterOperationalState, pendingValue.data(),
2204 presentValue.data());
2205
2206 if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS)
2207 {
2208 std::cerr << "Response Message Error: "
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002209 << "rc=" << rc << ",cc="
2210 << static_cast<int>(completionCode) << std::endl;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002211 return;
2212 }
2213
2214 ordered_json output;
2215 output["effecterDataSize"] = static_cast<int>(effecterDataSize);
2216 output["effecterOperationalState"] =
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002217 getEffecterOpState(effecterOperationalState);
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002218
2219 switch (effecterDataSize)
2220 {
2221 case PLDM_EFFECTER_DATA_SIZE_UINT8:
2222 {
2223 output["pendingValue"] =
2224 *(reinterpret_cast<uint8_t*>(pendingValue.data()));
2225 output["presentValue"] =
2226 *(reinterpret_cast<uint8_t*>(presentValue.data()));
2227 break;
2228 }
2229 case PLDM_EFFECTER_DATA_SIZE_SINT8:
2230 {
2231 output["pendingValue"] =
2232 *(reinterpret_cast<int8_t*>(pendingValue.data()));
2233 output["presentValue"] =
2234 *(reinterpret_cast<int8_t*>(presentValue.data()));
2235 break;
2236 }
2237 case PLDM_EFFECTER_DATA_SIZE_UINT16:
2238 {
2239 output["pendingValue"] =
2240 *(reinterpret_cast<uint16_t*>(pendingValue.data()));
2241 output["presentValue"] =
2242 *(reinterpret_cast<uint16_t*>(presentValue.data()));
2243 break;
2244 }
2245 case PLDM_EFFECTER_DATA_SIZE_SINT16:
2246 {
2247 output["pendingValue"] =
2248 *(reinterpret_cast<int16_t*>(pendingValue.data()));
2249 output["presentValue"] =
2250 *(reinterpret_cast<int16_t*>(presentValue.data()));
2251 break;
2252 }
2253 case PLDM_EFFECTER_DATA_SIZE_UINT32:
2254 {
2255 output["pendingValue"] =
2256 *(reinterpret_cast<uint32_t*>(pendingValue.data()));
2257 output["presentValue"] =
2258 *(reinterpret_cast<uint32_t*>(presentValue.data()));
2259 break;
2260 }
2261 case PLDM_EFFECTER_DATA_SIZE_SINT32:
2262 {
2263 output["pendingValue"] =
2264 *(reinterpret_cast<int32_t*>(pendingValue.data()));
2265 output["presentValue"] =
2266 *(reinterpret_cast<int32_t*>(presentValue.data()));
2267 break;
2268 }
2269 default:
2270 {
2271 std::cerr << "Unknown Effecter Data Size : "
2272 << static_cast<int>(effecterDataSize) << std::endl;
2273 break;
2274 }
2275 }
2276
2277 pldmtool::helper::DisplayInJson(output);
2278 }
2279
2280 private:
2281 uint16_t effecterId;
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002282};
2283
George Liud6649362019-11-27 19:06:51 +08002284void registerCommand(CLI::App& app)
2285{
2286 auto platform = app.add_subcommand("platform", "platform type command");
2287 platform->require_subcommand(1);
2288
Roger G. Coscojuela4aea4bd2025-03-18 15:51:55 +01002289 auto getEventReceiver = platform->add_subcommand(
2290 "GetEventReceiver",
2291 "Get the configured event receiver from a terminus");
2292 commands.push_back(std::make_unique<GetEventReceiver>(
2293 "platform", "getEventReceiver", getEventReceiver));
2294
Patrick Williams16c2a0a2024-08-16 15:20:59 -04002295 auto getPDR =
2296 platform->add_subcommand("GetPDR", "get platform descriptor records");
George Liud6649362019-11-27 19:06:51 +08002297 commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR));
2298
2299 auto setStateEffecterStates = platform->add_subcommand(
2300 "SetStateEffecterStates", "set effecter states");
2301 commands.push_back(std::make_unique<SetStateEffecter>(
2302 "platform", "setStateEffecterStates", setStateEffecterStates));
George Liucc9c20d2020-02-05 10:24:11 +08002303
2304 auto setNumericEffecterValue = platform->add_subcommand(
2305 "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter");
2306 commands.push_back(std::make_unique<SetNumericEffecterValue>(
2307 "platform", "setNumericEffecterValue", setNumericEffecterValue));
Sridevi Rameshf31b5042021-01-22 05:42:07 -06002308
2309 auto getStateSensorReadings = platform->add_subcommand(
2310 "GetStateSensorReadings", "get the state sensor readings");
2311 commands.push_back(std::make_unique<GetStateSensorReadings>(
2312 "platform", "getStateSensorReadings", getStateSensorReadings));
Pavithra Barithaya8c15e002023-10-17 04:14:21 -05002313
2314 auto getNumericEffecterValue = platform->add_subcommand(
2315 "GetNumericEffecterValue", "get the numeric effecter value");
2316 commands.push_back(std::make_unique<GetNumericEffecterValue>(
2317 "platform", "getNumericEffecterValue", getNumericEffecterValue));
nothingIIersonal83e068a2024-03-21 13:55:06 +03002318
2319 auto getSensorReading = platform->add_subcommand(
2320 "GetSensorReading", "get the numeric sensor reading");
2321 commands.push_back(std::make_unique<GetSensorReading>(
2322 "platform", "getSensorReading", getSensorReading));
Tal Yacobi8570fcc2024-05-28 11:11:23 +03002323
2324 auto getStateEffecterStates = platform->add_subcommand(
2325 "GetStateEffecterStates", "get the state effecter states");
2326 commands.push_back(std::make_unique<GetStateEffecterStates>(
2327 "platform", "getStateEffecterStates", getStateEffecterStates));
George Liud6649362019-11-27 19:06:51 +08002328}
2329
Pavithra Barithayaa340eed2023-02-14 03:32:47 -06002330void parseGetPDROption()
2331{
2332 for (const auto& command : commands)
2333 {
2334 if (command.get()->getPLDMType() == "platform" &&
2335 command.get()->getCommandName() == "getPDR")
2336 {
2337 auto getPDR = dynamic_cast<GetPDR*>(command.get());
2338 getPDR->parseGetPDROptions();
2339 }
2340 }
2341}
2342
George Liud6649362019-11-27 19:06:51 +08002343} // namespace platform
2344} // namespace pldmtool