Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 1 | #include "common/types.hpp" |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 2 | #include "pldm_cmd_helper.hpp" |
| 3 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 4 | #include <libpldm/entity.h> |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 5 | #include <libpldm/platform.h> |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/state_set.h> |
| 7 | |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 8 | #include <algorithm> |
Brad Bishop | 02d7114 | 2021-10-14 19:00:17 -0400 | [diff] [blame] | 9 | #include <cstddef> |
| 10 | #include <map> |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 11 | #include <ranges> |
Brad Bishop | 02d7114 | 2021-10-14 19:00:17 -0400 | [diff] [blame] | 12 | |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 13 | #ifdef OEM_IBM |
| 14 | #include "oem/ibm/oem_ibm_state_set.hpp" |
| 15 | #endif |
| 16 | |
Brad Bishop | 5079ac4 | 2021-08-19 18:35:06 -0400 | [diff] [blame] | 17 | using namespace pldm::utils; |
| 18 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 19 | namespace pldmtool |
| 20 | { |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 21 | namespace platform |
| 22 | { |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 23 | namespace |
| 24 | { |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 25 | using namespace pldmtool::helper; |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 26 | |
| 27 | static const std::map<uint8_t, std::string> sensorPresState{ |
| 28 | {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"}, |
| 29 | {PLDM_SENSOR_NORMAL, "Sensor Normal"}, |
| 30 | {PLDM_SENSOR_WARNING, "Sensor Warning"}, |
| 31 | {PLDM_SENSOR_CRITICAL, "Sensor Critical"}, |
| 32 | {PLDM_SENSOR_FATAL, "Sensor Fatal"}, |
| 33 | {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"}, |
| 34 | {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"}, |
| 35 | {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"}, |
| 36 | {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"}, |
| 37 | {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"}, |
| 38 | {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}}; |
| 39 | |
| 40 | static const std::map<uint8_t, std::string> sensorOpState{ |
| 41 | {PLDM_SENSOR_ENABLED, "Sensor Enabled"}, |
| 42 | {PLDM_SENSOR_DISABLED, "Sensor Disabled"}, |
| 43 | {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"}, |
| 44 | {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"}, |
| 45 | {PLDM_SENSOR_FAILED, "Sensor Failed"}, |
| 46 | {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Intializing"}, |
| 47 | {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"}, |
| 48 | {PLDM_SENSOR_INTEST, "Sensor Intest"}}; |
| 49 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 50 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 51 | |
| 52 | } // namespace |
| 53 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 54 | using ordered_json = nlohmann::ordered_json; |
| 55 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 56 | class GetPDR : public CommandInterface |
| 57 | { |
| 58 | public: |
| 59 | ~GetPDR() = default; |
| 60 | GetPDR() = delete; |
| 61 | GetPDR(const GetPDR&) = delete; |
| 62 | GetPDR(GetPDR&&) = default; |
| 63 | GetPDR& operator=(const GetPDR&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 64 | GetPDR& operator=(GetPDR&&) = delete; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 65 | |
| 66 | using CommandInterface::CommandInterface; |
| 67 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 68 | explicit GetPDR(const char* type, const char* name, CLI::App* app) : |
| 69 | CommandInterface(type, name, app) |
| 70 | { |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 71 | auto pdrOptionGroup = app->add_option_group( |
| 72 | "Required Option", |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 73 | "Retrieve individual PDR, all PDRs, PDRs of a requested type or retrieve all PDRs of the requested terminusID"); |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 74 | pdrOptionGroup->add_option( |
| 75 | "-d,--data", recordHandle, |
| 76 | "retrieve individual PDRs from a PDR Repository\n" |
| 77 | "eg: The recordHandle value for the PDR to be retrieved and 0 " |
| 78 | "means get first PDR in the repository."); |
| 79 | pdrRecType = ""; |
| 80 | pdrOptionGroup->add_option("-t, --type", pdrRecType, |
| 81 | "retrieve all PDRs of the requested type\n" |
| 82 | "supported types:\n" |
| 83 | "[terminusLocator, stateSensor, " |
| 84 | "numericEffecter, stateEffecter, " |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 85 | "compactNumericSensor, sensorauxname, " |
| 86 | "efffecterAuxName, " |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 87 | "EntityAssociation, fruRecord, ... ]"); |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 88 | |
| 89 | getPDRGroupOption = pdrOptionGroup->add_option( |
| 90 | "-i, --terminusID", pdrTerminus, |
| 91 | "retrieve all PDRs of the requested terminusID\n" |
| 92 | "supported IDs:\n [1, 2, 208...]"); |
| 93 | |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 94 | allPDRs = false; |
| 95 | pdrOptionGroup->add_flag("-a, --all", allPDRs, |
| 96 | "retrieve all PDRs from a PDR repository"); |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 97 | |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 98 | pdrOptionGroup->require_option(1); |
| 99 | } |
| 100 | |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 101 | void parseGetPDROptions() |
| 102 | { |
| 103 | optTIDSet = false; |
| 104 | if (getPDRGroupOption->count() > 0) |
| 105 | { |
| 106 | optTIDSet = true; |
| 107 | getPDRs(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | void getPDRs() |
| 112 | { |
| 113 | // start the array |
| 114 | std::cout << "["; |
| 115 | |
| 116 | recordHandle = 0; |
| 117 | do |
| 118 | { |
| 119 | CommandInterface::exec(); |
| 120 | } while (recordHandle != 0); |
| 121 | |
| 122 | // close the array |
| 123 | std::cout << "]\n"; |
| 124 | |
| 125 | if (handleFound) |
| 126 | { |
| 127 | recordHandle = 0; |
| 128 | uint32_t prevRecordHandle = 0; |
| 129 | do |
| 130 | { |
| 131 | CommandInterface::exec(); |
| 132 | if (recordHandle == prevRecordHandle) |
| 133 | { |
| 134 | return; |
| 135 | } |
| 136 | prevRecordHandle = recordHandle; |
| 137 | } while (recordHandle != 0); |
| 138 | } |
| 139 | } |
| 140 | |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 141 | void exec() override |
| 142 | { |
| 143 | if (allPDRs || !pdrRecType.empty()) |
| 144 | { |
| 145 | if (!pdrRecType.empty()) |
| 146 | { |
| 147 | std::transform(pdrRecType.begin(), pdrRecType.end(), |
| 148 | pdrRecType.begin(), tolower); |
| 149 | } |
| 150 | |
Brad Bishop | 16eff86 | 2021-10-14 19:44:32 -0400 | [diff] [blame] | 151 | // start the array |
| 152 | std::cout << "[\n"; |
| 153 | |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 154 | // Retrieve all PDR records starting from the first |
| 155 | recordHandle = 0; |
| 156 | uint32_t prevRecordHandle = 0; |
Brad Bishop | 02d7114 | 2021-10-14 19:00:17 -0400 | [diff] [blame] | 157 | std::map<uint32_t, uint32_t> recordsSeen; |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 158 | do |
| 159 | { |
| 160 | CommandInterface::exec(); |
| 161 | // recordHandle is updated to nextRecord when |
| 162 | // CommandInterface::exec() is successful. |
| 163 | // In case of any error, return. |
| 164 | if (recordHandle == prevRecordHandle) |
| 165 | { |
| 166 | return; |
| 167 | } |
Brad Bishop | 02d7114 | 2021-10-14 19:00:17 -0400 | [diff] [blame] | 168 | |
| 169 | // check for circular references. |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 170 | auto result = recordsSeen.emplace(recordHandle, |
| 171 | prevRecordHandle); |
Brad Bishop | 02d7114 | 2021-10-14 19:00:17 -0400 | [diff] [blame] | 172 | if (!result.second) |
| 173 | { |
| 174 | std::cerr |
| 175 | << "Record handle " << recordHandle |
| 176 | << " has multiple references: " << result.first->second |
| 177 | << ", " << prevRecordHandle << "\n"; |
| 178 | return; |
| 179 | } |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 180 | prevRecordHandle = recordHandle; |
Brad Bishop | 16eff86 | 2021-10-14 19:44:32 -0400 | [diff] [blame] | 181 | |
| 182 | if (recordHandle != 0) |
| 183 | { |
| 184 | // close the array |
| 185 | std::cout << ","; |
| 186 | } |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 187 | } while (recordHandle != 0); |
Brad Bishop | 16eff86 | 2021-10-14 19:44:32 -0400 | [diff] [blame] | 188 | |
| 189 | // close the array |
| 190 | std::cout << "]\n"; |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 191 | } |
| 192 | else |
| 193 | { |
| 194 | CommandInterface::exec(); |
| 195 | } |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 199 | { |
| 200 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 201 | PLDM_GET_PDR_REQ_BYTES); |
| 202 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 203 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 204 | auto rc = encode_get_pdr_req(instanceId, recordHandle, 0, |
| 205 | PLDM_GET_FIRSTPART, UINT16_MAX, 0, request, |
| 206 | PLDM_GET_PDR_REQ_BYTES); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 207 | return {rc, requestMsg}; |
| 208 | } |
| 209 | |
| 210 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 211 | { |
| 212 | uint8_t completionCode = 0; |
Deepak Kodihalli | a59cdc6 | 2020-07-14 05:11:33 -0500 | [diff] [blame] | 213 | uint8_t recordData[UINT16_MAX] = {0}; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 214 | uint32_t nextRecordHndl = 0; |
| 215 | uint32_t nextDataTransferHndl = 0; |
| 216 | uint8_t transferFlag = 0; |
| 217 | uint16_t respCnt = 0; |
| 218 | uint8_t transferCRC = 0; |
| 219 | |
| 220 | auto rc = decode_get_pdr_resp( |
| 221 | responsePtr, payloadLength, &completionCode, &nextRecordHndl, |
| 222 | &nextDataTransferHndl, &transferFlag, &respCnt, recordData, |
| 223 | sizeof(recordData), &transferCRC); |
| 224 | |
| 225 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 226 | { |
| 227 | std::cerr << "Response Message Error: " |
| 228 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 229 | << std::endl; |
| 230 | return; |
| 231 | } |
| 232 | |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 233 | if (optTIDSet && !handleFound) |
| 234 | { |
| 235 | terminusHandle = getTerminusHandle(recordData, pdrTerminus); |
| 236 | if (terminusHandle.has_value()) |
| 237 | { |
| 238 | recordHandle = 0; |
| 239 | return; |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | recordHandle = nextRecordHndl; |
| 244 | return; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | else |
| 249 | { |
| 250 | printPDRMsg(nextRecordHndl, respCnt, recordData, terminusHandle); |
| 251 | recordHandle = nextRecordHndl; |
| 252 | } |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | private: |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 256 | const std::map<pldm::pdr::EntityType, std::string> entityType = { |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 257 | {PLDM_ENTITY_UNSPECIFIED, "Unspecified"}, |
| 258 | {PLDM_ENTITY_OTHER, "Other"}, |
| 259 | {PLDM_ENTITY_NETWORK, "Network"}, |
| 260 | {PLDM_ENTITY_GROUP, "Group"}, |
| 261 | {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE, |
| 262 | "Remote Management Communication Device"}, |
| 263 | {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"}, |
| 264 | {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"}, |
| 265 | {PLDM_ENTITY_TERMINUS, "PLDM Terminus"}, |
| 266 | {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"}, |
| 267 | {PLDM_ENTITY_KEYPAD, "keypad"}, |
| 268 | {PLDM_ENTITY_SWITCH, "Switch"}, |
| 269 | {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"}, |
| 270 | {PLDM_ENTITY_DISPLAY, "Display"}, |
| 271 | {PLDM_ENTITY_INDICATOR, "Indicator"}, |
| 272 | {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 273 | {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 274 | {PLDM_ENTITY_OPERATING_SYS, "Operating System"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 275 | {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 276 | {PLDM_ENTITY_OS_LOADER, "OS Loader"}, |
| 277 | {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"}, |
| 278 | {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 279 | {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 280 | {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"}, |
| 281 | {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"}, |
| 282 | {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"}, |
| 283 | {PLDM_ENTITY_DEVICE_BAY, "Device bay"}, |
| 284 | {PLDM_ENTITY_DOOR, "Door"}, |
| 285 | {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"}, |
| 286 | {PLDM_ENTITY_COVER, "Cover"}, |
| 287 | {PLDM_ENTITY_BOARD, "Board"}, |
| 288 | {PLDM_ENTITY_CARD, "Card"}, |
| 289 | {PLDM_ENTITY_MODULE, "Module"}, |
| 290 | {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 291 | {PLDM_ENTITY_SYS_BOARD, "System Board"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 292 | {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 293 | {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"}, |
| 294 | {PLDM_ENTITY_PROC_MODULE, "Processor Module"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 295 | {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 296 | {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 297 | "Chassis front panel board(control panel)"}, |
| 298 | {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"}, |
| 299 | {PLDM_ENTITY_POWER_MGMT, "Power management board"}, |
| 300 | {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"}, |
| 301 | {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"}, |
| 302 | {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD, |
| 303 | "System internal expansion board"}, |
| 304 | {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"}, |
| 305 | {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"}, |
| 306 | {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"}, |
| 307 | {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"}, |
| 308 | {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"}, |
| 309 | {PLDM_ENTITY_IO_MODULE, "I/O Module"}, |
| 310 | {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"}, |
| 311 | {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"}, |
| 312 | {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"}, |
| 313 | {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 314 | {PLDM_ENTITY_FAN, "Fan"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 315 | {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"}, |
| 316 | {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"}, |
| 317 | {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"}, |
| 318 | {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"}, |
| 319 | {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"}, |
| 320 | {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"}, |
| 321 | {PLDM_ENTITY_CD_DRIVE, "CD Drive"}, |
| 322 | {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"}, |
| 323 | {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE, |
| 324 | "Other Silicon Storage Device"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 325 | {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 326 | {PLDM_ENTITY_POWER_SUPPLY, "Power supply"}, |
| 327 | {PLDM_ENTITY_BATTERY, "Battery"}, |
| 328 | {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"}, |
| 329 | {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"}, |
| 330 | {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"}, |
| 331 | {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"}, |
| 332 | {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"}, |
| 333 | {PLDM_ENTITY_PROC, "Processor"}, |
| 334 | {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"}, |
| 335 | {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"}, |
| 336 | {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"}, |
| 337 | {PLDM_ENTITY_SEEPROM, "SEEPROM"}, |
| 338 | {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"}, |
| 339 | {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"}, |
| 340 | {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"}, |
| 341 | {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"}, |
| 342 | {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"}, |
| 343 | {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"}, |
| 344 | {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 345 | {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 346 | {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"}, |
| 347 | {PLDM_ENTITY_OTHER_BUS, "Other Bus"}, |
| 348 | {PLDM_ENTITY_SYS_BUS, "System Bus"}, |
| 349 | {PLDM_ENTITY_I2C_BUS, "I2C Bus"}, |
| 350 | {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"}, |
| 351 | {PLDM_ENTITY_SPI_BUS, "SPI Bus"}, |
| 352 | {PLDM_ENTITY_PCI_BUS, "PCI Bus"}, |
| 353 | {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"}, |
| 354 | {PLDM_ENTITY_PECI_BUS, "PECI Bus"}, |
| 355 | {PLDM_ENTITY_LPC_BUS, "LPC Bus"}, |
| 356 | {PLDM_ENTITY_USB_BUS, "USB Bus"}, |
| 357 | {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"}, |
| 358 | {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"}, |
| 359 | {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"}, |
| 360 | {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"}, |
| 361 | {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"}, |
| 362 | {PLDM_ENTITY_CONNECTOR, "Connector"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 363 | {PLDM_ENTITY_SLOT, "Slot"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 364 | {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"}, |
| 365 | {PLDM_ENTITY_INTERCONNECT, "Interconnect"}, |
| 366 | {PLDM_ENTITY_PLUG, "Plug"}, |
| 367 | {PLDM_ENTITY_SOCKET, "Socket"}, |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 368 | }; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 369 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 370 | const std::map<uint16_t, std::string> stateSet = { |
| 371 | {PLDM_STATE_SET_HEALTH_STATE, "Health State"}, |
| 372 | {PLDM_STATE_SET_AVAILABILITY, "Availability"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 373 | {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"}, |
| 374 | {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"}, |
| 375 | {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"}, |
| 376 | {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"}, |
| 377 | {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 378 | {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 379 | {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"}, |
| 380 | {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 381 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 382 | "Operational Running Status"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 383 | {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS, |
| 384 | "Operational Connection Status"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 385 | {PLDM_STATE_SET_PRESENCE, "Presence"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 386 | {PLDM_STATE_SET_PERFORMANCE, "Performance"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 387 | {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 388 | {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"}, |
| 389 | {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"}, |
| 390 | {PLDM_STATE_SET_VERSION, "Version"}, |
| 391 | {PLDM_STATE_SET_ALARM_STATE, "Alarm State"}, |
| 392 | {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"}, |
| 393 | {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"}, |
| 394 | {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 395 | {PLDM_STATE_SET_LINK_STATE, "Link State"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 396 | {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"}, |
| 397 | {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"}, |
| 398 | {PLDM_STATE_SET_DOOR_STATE, "Door State"}, |
| 399 | {PLDM_STATE_SET_SWITCH_STATE, "Switch State"}, |
| 400 | {PLDM_STATE_SET_LOCK_STATE, "Lock State"}, |
| 401 | {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"}, |
| 402 | {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"}, |
| 403 | {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"}, |
| 404 | {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION, |
| 405 | "Physical Communication Connection"}, |
| 406 | {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"}, |
| 407 | {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS, |
| 408 | "Foreign Network Detection Status"}, |
| 409 | {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY, |
| 410 | "Password-Protected Access Security"}, |
| 411 | {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL, |
| 412 | "Security Access –PrivilegeLevel"}, |
| 413 | {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 414 | {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 415 | {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 416 | {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 417 | {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"}, |
| 418 | {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"}, |
| 419 | {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 420 | {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 421 | {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"}, |
| 422 | {PLDM_STATE_SET_POST_ERRORS, "POST Errors"}, |
| 423 | {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"}, |
| 424 | {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"}, |
| 425 | {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"}, |
| 426 | {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"}, |
| 427 | {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"}, |
| 428 | {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED, |
| 429 | "Diagnostic Interrupt Requested"}, |
| 430 | {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED, |
| 431 | "Diagnostic Interrupt Received"}, |
| 432 | {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED, |
| 433 | "I/O Channel Check NMI Requested"}, |
| 434 | {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED, |
| 435 | "I/O Channel Check NMI Received"}, |
| 436 | {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"}, |
| 437 | {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"}, |
| 438 | {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"}, |
| 439 | {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"}, |
| 440 | {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"}, |
| 441 | {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"}, |
| 442 | {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"}, |
| 443 | {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"}, |
| 444 | {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "}, |
| 445 | {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"}, |
| 446 | {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"}, |
| 447 | {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"}, |
| 448 | {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"}, |
| 449 | {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"}, |
| 450 | {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"}, |
| 451 | {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"}, |
| 452 | {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "}, |
| 453 | {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"}, |
| 454 | {PLDM_STATE_SET_BATTERY_STATE, "Battery State"}, |
| 455 | {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"}, |
| 456 | {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"}, |
| 457 | {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"}, |
| 458 | {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"}, |
| 459 | {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"}, |
| 460 | {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"}, |
| 461 | {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"}, |
| 462 | {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"}, |
| 463 | {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"}, |
| 464 | {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"}, |
| 465 | {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"}, |
| 466 | {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"}, |
| 467 | {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS, |
| 468 | "Redundant Memory Activity Status"}, |
| 469 | {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"}, |
| 470 | {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"}, |
| 471 | {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"}, |
| 472 | {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"}, |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 473 | {PLDM_STATE_SET_SLOT_STATE, "Slot State"}, |
| 474 | }; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 475 | |
| 476 | const std::array<std::string_view, 4> sensorInit = { |
| 477 | "noInit", "useInitPDR", "enableSensor", "disableSensor"}; |
| 478 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 479 | const std::array<std::string_view, 4> effecterInit = { |
| 480 | "noInit", "useInitPDR", "enableEffecter", "disableEffecter"}; |
| 481 | |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 482 | const std::map<uint8_t, std::string> pdrType = { |
| 483 | {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"}, |
| 484 | {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"}, |
| 485 | {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR, |
| 486 | "Numeric Sensor Initialization PDR"}, |
| 487 | {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"}, |
| 488 | {PLDM_STATE_SENSOR_INITIALIZATION_PDR, |
| 489 | "State Sensor Initialization PDR"}, |
| 490 | {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"}, |
| 491 | {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"}, |
| 492 | {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"}, |
| 493 | {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"}, |
| 494 | {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR, |
| 495 | "Numeric Effecter Initialization PDR"}, |
Thu Nguyen | 9d0e58c | 2021-12-09 13:53:00 +0700 | [diff] [blame] | 496 | {PLDM_COMPACT_NUMERIC_SENSOR_PDR, "Compact Numeric Sensor PDR"}, |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 497 | {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"}, |
| 498 | {PLDM_STATE_EFFECTER_INITIALIZATION_PDR, |
| 499 | "State Effecter Initialization PDR"}, |
| 500 | {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"}, |
| 501 | {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"}, |
| 502 | {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"}, |
| 503 | {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"}, |
| 504 | {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"}, |
| 505 | {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"}, |
| 506 | {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"}, |
| 507 | {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"}, |
| 508 | {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"}, |
| 509 | {PLDM_OEM_PDR, "OEM PDR"}, |
| 510 | }; |
| 511 | |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 512 | static inline const std::map<uint8_t, std::string> setThermalTrip{ |
| 513 | {PLDM_STATE_SET_THERMAL_TRIP_STATUS_NORMAL, "Normal"}, |
| 514 | {PLDM_STATE_SET_THERMAL_TRIP_STATUS_THERMAL_TRIP, "Thermal Trip"}}; |
| 515 | |
| 516 | static inline const std::map<uint8_t, std::string> setIdentifyState{ |
| 517 | {PLDM_STATE_SET_IDENTIFY_STATE_UNASSERTED, "Identify State Unasserted"}, |
| 518 | {PLDM_STATE_SET_IDENTIFY_STATE_ASSERTED, "Identify State Asserted"}}; |
| 519 | |
| 520 | static inline const std::map<uint8_t, std::string> setBootProgressState{ |
| 521 | {PLDM_STATE_SET_BOOT_PROG_STATE_NOT_ACTIVE, "Boot Not Active"}, |
| 522 | {PLDM_STATE_SET_BOOT_PROG_STATE_COMPLETED, "Boot Completed"}, |
| 523 | {PLDM_STATE_SET_BOOT_PROG_STATE_MEM_INITIALIZATION, |
| 524 | "Memory Initialization"}, |
| 525 | {PLDM_STATE_SET_BOOT_PROG_STATE_SEC_PROC_INITIALIZATION, |
| 526 | "Secondary Processor(s) Initialization"}, |
| 527 | {PLDM_STATE_SET_BOOT_PROG_STATE_PCI_RESORUCE_CONFIG, |
| 528 | "PCI Resource Configuration"}, |
| 529 | {PLDM_STATE_SET_BOOT_PROG_STATE_STARTING_OP_SYS, |
| 530 | "Starting Operating System"}, |
| 531 | {PLDM_STATE_SET_BOOT_PROG_STATE_BASE_BOARD_INITIALIZATION, |
| 532 | "Baseboard Initialization"}, |
| 533 | {PLDM_STATE_SET_BOOT_PROG_STATE_PRIMARY_PROC_INITIALIZATION, |
kamal | 00a076d | 2022-11-08 04:24:36 -0600 | [diff] [blame] | 534 | "Primary Processor Initialization"}, |
| 535 | {PLDM_STATE_SET_BOOT_PROG_STATE_OSSTART, "OSStart"}}; |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 536 | |
| 537 | static inline const std::map<uint8_t, std::string> setOpFaultStatus{ |
Pavithra Barithaya | 6e20f7c | 2023-08-22 00:50:47 -0500 | [diff] [blame] | 538 | {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NORMAL, "Normal"}, |
| 539 | {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_ERROR, "Error"}, |
| 540 | {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS_NON_RECOVERABLE_ERROR, |
| 541 | "Non Recoverable Error"}}; |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 542 | |
| 543 | static inline const std::map<uint8_t, std::string> setSysPowerState{ |
| 544 | {PLDM_STATE_SET_SYS_POWER_STATE_OFF_SOFT_GRACEFUL, |
| 545 | "Off-Soft Graceful"}}; |
| 546 | |
| 547 | static inline const std::map<uint8_t, std::string> setSWTerminationStatus{ |
| 548 | {PLDM_SW_TERM_GRACEFUL_RESTART_REQUESTED, |
| 549 | "Graceful Restart Requested"}}; |
| 550 | |
| 551 | static inline const std::map<uint8_t, std::string> setAvailability{ |
| 552 | {PLDM_STATE_SET_AVAILABILITY_REBOOTING, "Rebooting"}}; |
| 553 | |
| 554 | static inline const std::map<uint8_t, std::string> setHealthState{ |
| 555 | {PLDM_STATE_SET_HEALTH_STATE_NORMAL, "Normal"}, |
Manojkiran Eda | 5de3de5 | 2022-01-03 12:12:53 +0530 | [diff] [blame] | 556 | {PLDM_STATE_SET_HEALTH_STATE_NON_CRITICAL, "Non-Critical"}, |
| 557 | {PLDM_STATE_SET_HEALTH_STATE_CRITICAL, "Critical"}, |
| 558 | {PLDM_STATE_SET_HEALTH_STATE_FATAL, "Fatal"}, |
| 559 | {PLDM_STATE_SET_HEALTH_STATE_UPPER_NON_CRITICAL, "Upper Non-Critical"}, |
| 560 | {PLDM_STATE_SET_HEALTH_STATE_LOWER_NON_CRITICAL, "Lower Non-Critical"}, |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 561 | {PLDM_STATE_SET_HEALTH_STATE_UPPER_CRITICAL, "Upper Critical"}, |
Manojkiran Eda | 5de3de5 | 2022-01-03 12:12:53 +0530 | [diff] [blame] | 562 | {PLDM_STATE_SET_HEALTH_STATE_LOWER_CRITICAL, "Lower Critical"}, |
| 563 | {PLDM_STATE_SET_HEALTH_STATE_UPPER_FATAL, "Upper Fatal"}, |
| 564 | {PLDM_STATE_SET_HEALTH_STATE_LOWER_FATAL, "Lower Fatal"}}; |
| 565 | |
| 566 | static inline const std::map<uint8_t, std::string> |
| 567 | setOperationalRunningState{ |
| 568 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STARTING, "Starting"}, |
| 569 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPING, "Stopping"}, |
| 570 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_STOPPED, "Stopped"}, |
| 571 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_IN_SERVICE, |
| 572 | "In Service"}, |
| 573 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_ABORTED, "Aborted"}, |
| 574 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS_DORMANT, "Dormant"}}; |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 575 | |
| 576 | static inline const std::map<uint16_t, const std::map<uint8_t, std::string>> |
| 577 | populatePStateMaps{ |
| 578 | {PLDM_STATE_SET_THERMAL_TRIP, setThermalTrip}, |
| 579 | {PLDM_STATE_SET_IDENTIFY_STATE, setIdentifyState}, |
| 580 | {PLDM_STATE_SET_BOOT_PROGRESS, setBootProgressState}, |
| 581 | {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, setOpFaultStatus}, |
| 582 | {PLDM_STATE_SET_SYSTEM_POWER_STATE, setSysPowerState}, |
| 583 | {PLDM_STATE_SET_SW_TERMINATION_STATUS, setSWTerminationStatus}, |
| 584 | {PLDM_STATE_SET_AVAILABILITY, setAvailability}, |
| 585 | {PLDM_STATE_SET_HEALTH_STATE, setHealthState}, |
Manojkiran Eda | 5de3de5 | 2022-01-03 12:12:53 +0530 | [diff] [blame] | 586 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 587 | setOperationalRunningState}, |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 588 | }; |
| 589 | |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 590 | const std::map<std::string, uint8_t> strToPdrType = { |
| 591 | {"terminuslocator", PLDM_TERMINUS_LOCATOR_PDR}, |
| 592 | {"statesensor", PLDM_STATE_SENSOR_PDR}, |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 593 | {"sensorauxname", PLDM_SENSOR_AUXILIARY_NAMES_PDR}, |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 594 | {"numericeffecter", PLDM_NUMERIC_EFFECTER_PDR}, |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 595 | {"efffecterauxname", PLDM_EFFECTER_AUXILIARY_NAMES_PDR}, |
Thu Nguyen | 9d0e58c | 2021-12-09 13:53:00 +0700 | [diff] [blame] | 596 | {"compactnumericsensor", PLDM_COMPACT_NUMERIC_SENSOR_PDR}, |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 597 | {"stateeffecter", PLDM_STATE_EFFECTER_PDR}, |
| 598 | {"entityassociation", PLDM_PDR_ENTITY_ASSOCIATION}, |
| 599 | {"frurecord", PLDM_PDR_FRU_RECORD_SET}, |
| 600 | // Add other types |
| 601 | }; |
| 602 | |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame] | 603 | bool isLogicalBitSet(const uint16_t entity_type) |
| 604 | { |
| 605 | return entity_type & 0x8000; |
| 606 | } |
| 607 | |
| 608 | uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type) |
| 609 | { |
| 610 | return logical_entity_type & 0x7FFF; |
| 611 | } |
| 612 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 613 | std::string getEntityName(pldm::pdr::EntityType type) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 614 | { |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame] | 615 | uint16_t entityNumber = type; |
| 616 | std::string entityName = "[Physical] "; |
| 617 | |
| 618 | if (isLogicalBitSet(type)) |
| 619 | { |
| 620 | entityName = "[Logical] "; |
| 621 | entityNumber = getEntityTypeForLogicalEntity(type); |
| 622 | } |
| 623 | |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 624 | try |
| 625 | { |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame] | 626 | return entityName + entityType.at(entityNumber); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 627 | } |
| 628 | catch (const std::out_of_range& e) |
| 629 | { |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 630 | auto OemString = |
| 631 | std::to_string(static_cast<unsigned>(entityNumber)); |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame] | 632 | if (type >= PLDM_OEM_ENTITY_TYPE_START && |
| 633 | type <= PLDM_OEM_ENTITY_TYPE_END) |
| 634 | { |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 635 | #ifdef OEM_IBM |
| 636 | if (OemIBMEntityType.contains(entityNumber)) |
| 637 | { |
| 638 | return entityName + OemIBMEntityType.at(entityNumber) + |
| 639 | "(OEM)"; |
| 640 | } |
| 641 | #endif |
| 642 | return entityName + OemString + "(OEM)"; |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame] | 643 | } |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 644 | return OemString; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 648 | std::string getStateSetName(uint16_t id) |
| 649 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 650 | auto typeString = std::to_string(id); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 651 | try |
| 652 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 653 | return stateSet.at(id) + "(" + typeString + ")"; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 654 | } |
| 655 | catch (const std::out_of_range& e) |
| 656 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 657 | return typeString; |
| 658 | } |
| 659 | } |
| 660 | |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 661 | std::vector<std::string> |
| 662 | getStateSetPossibleStateNames(uint16_t stateId, |
| 663 | const std::vector<uint8_t>& value) |
| 664 | { |
| 665 | std::vector<std::string> data{}; |
| 666 | std::map<uint8_t, std::string> stateNameMaps; |
| 667 | |
| 668 | for (auto& s : value) |
| 669 | { |
| 670 | std::map<uint8_t, std::string> stateNameMaps; |
| 671 | auto pstr = std::to_string(s); |
| 672 | |
| 673 | #ifdef OEM_IBM |
Manojkiran Eda | be1a857 | 2022-01-06 11:20:36 +0530 | [diff] [blame] | 674 | if (stateId >= PLDM_OEM_STATE_SET_ID_START && |
| 675 | stateId < PLDM_OEM_STATE_SET_ID_END) |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 676 | { |
| 677 | if (populateOemIBMStateMaps.contains(stateId)) |
| 678 | { |
| 679 | const std::map<uint8_t, std::string> stateNames = |
| 680 | populateOemIBMStateMaps.at(stateId); |
| 681 | stateNameMaps.insert(stateNames.begin(), stateNames.end()); |
| 682 | } |
| 683 | } |
| 684 | #endif |
| 685 | if (populatePStateMaps.contains(stateId)) |
| 686 | { |
| 687 | const std::map<uint8_t, std::string> stateNames = |
| 688 | populatePStateMaps.at(stateId); |
| 689 | stateNameMaps.insert(stateNames.begin(), stateNames.end()); |
| 690 | } |
| 691 | if (stateNameMaps.contains(s)) |
| 692 | { |
| 693 | data.push_back(stateNameMaps.at(s) + "(" + pstr + ")"); |
| 694 | } |
| 695 | else |
| 696 | { |
| 697 | data.push_back(pstr); |
| 698 | } |
| 699 | } |
| 700 | return data; |
| 701 | } |
| 702 | |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 703 | std::string getPDRType(uint8_t type) |
| 704 | { |
| 705 | auto typeString = std::to_string(type); |
| 706 | try |
| 707 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 708 | return pdrType.at(type); |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 709 | } |
| 710 | catch (const std::out_of_range& e) |
| 711 | { |
| 712 | return typeString; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 716 | void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output) |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 717 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 718 | output["recordHandle"] = hdr->record_handle; |
| 719 | output["PDRHeaderVersion"] = unsigned(hdr->version); |
| 720 | output["PDRType"] = getPDRType(hdr->type); |
| 721 | output["recordChangeNumber"] = hdr->record_change_num; |
| 722 | output["dataLength"] = hdr->length; |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 723 | } |
| 724 | |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 725 | std::vector<uint8_t> printPossibleStates(uint8_t possibleStatesSize, |
| 726 | const bitfield8_t* states) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 727 | { |
| 728 | uint8_t possibleStatesPos{}; |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 729 | std::vector<uint8_t> data{}; |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 730 | auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) { |
| 731 | std::stringstream pstates; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 732 | for (int i = 0; i < CHAR_BIT; i++) |
| 733 | { |
| 734 | if (val.byte & (1 << i)) |
| 735 | { |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 736 | pstates << (possibleStatesPos * CHAR_BIT + i); |
| 737 | data.push_back( |
| 738 | static_cast<uint8_t>(std::stoi(pstates.str()))); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 739 | pstates.str(""); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | possibleStatesPos++; |
| 743 | }; |
| 744 | std::for_each(states, states + possibleStatesSize, printStates); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 745 | return data; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 746 | } |
| 747 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 748 | void printStateSensorPDR(const uint8_t* data, ordered_json& output) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 749 | { |
| 750 | auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 751 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 752 | output["sensorID"] = pdr->sensor_id; |
| 753 | output["entityType"] = getEntityName(pdr->entity_type); |
| 754 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 755 | output["containerID"] = pdr->container_id; |
| 756 | output["sensorInit"] = sensorInit[pdr->sensor_init]; |
| 757 | output["sensorAuxiliaryNamesPDR"] = |
| 758 | (pdr->sensor_auxiliary_names_pdr ? true : false); |
| 759 | output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 760 | |
| 761 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 762 | auto compCount = pdr->composite_sensor_count; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 763 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 764 | while (compCount--) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 765 | { |
| 766 | auto state = reinterpret_cast<const state_sensor_possible_states*>( |
| 767 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 768 | output.emplace(("stateSetID[" + std::to_string(compCount) + "]"), |
| 769 | getStateSetName(state->state_set_id)); |
| 770 | output.emplace( |
| 771 | ("possibleStatesSize[" + std::to_string(compCount) + "]"), |
| 772 | state->possible_states_size); |
| 773 | output.emplace( |
| 774 | ("possibleStates[" + std::to_string(compCount) + "]"), |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 775 | getStateSetPossibleStateNames( |
| 776 | state->state_set_id, |
| 777 | printPossibleStates(state->possible_states_size, |
| 778 | state->states))); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 779 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 780 | if (compCount) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 781 | { |
| 782 | statesPtr += sizeof(state_sensor_possible_states) + |
| 783 | state->possible_states_size - 1; |
| 784 | } |
| 785 | } |
| 786 | } |
| 787 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 788 | void printPDRFruRecordSet(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 789 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 790 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 791 | { |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | data += sizeof(pldm_pdr_hdr); |
| 796 | pldm_pdr_fru_record_set* pdr = |
| 797 | reinterpret_cast<pldm_pdr_fru_record_set*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 798 | if (!pdr) |
| 799 | { |
| 800 | std::cerr << "Failed to get the FRU record set PDR" << std::endl; |
| 801 | return; |
| 802 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 803 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 804 | output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle); |
| 805 | output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi); |
| 806 | output["entityType"] = getEntityName(pdr->entity_type); |
Sagar Srinivas | ebf8bb5 | 2023-10-06 01:15:55 -0500 | [diff] [blame] | 807 | output["entityInstanceNumber"] = unsigned(pdr->entity_instance); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 808 | output["containerID"] = unsigned(pdr->container_id); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 809 | } |
| 810 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 811 | void printPDREntityAssociation(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 812 | { |
| 813 | const std::map<uint8_t, const char*> assocationType = { |
| 814 | {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"}, |
| 815 | {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"}, |
| 816 | }; |
| 817 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 818 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 819 | { |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | data += sizeof(pldm_pdr_hdr); |
| 824 | pldm_pdr_entity_association* pdr = |
| 825 | reinterpret_cast<pldm_pdr_entity_association*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 826 | if (!pdr) |
| 827 | { |
| 828 | std::cerr << "Failed to get the PDR eneity association" |
| 829 | << std::endl; |
| 830 | return; |
| 831 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 832 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 833 | output["containerID"] = int(pdr->container_id); |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 834 | if (assocationType.contains(pdr->association_type)) |
| 835 | { |
| 836 | output["associationType"] = |
| 837 | assocationType.at(pdr->association_type); |
| 838 | } |
| 839 | else |
| 840 | { |
| 841 | std::cout << "Get associationType failed.\n"; |
| 842 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 843 | output["containerEntityType"] = |
| 844 | getEntityName(pdr->container.entity_type); |
| 845 | output["containerEntityInstanceNumber"] = |
| 846 | int(pdr->container.entity_instance_num); |
| 847 | output["containerEntityContainerID"] = |
| 848 | int(pdr->container.entity_container_id); |
| 849 | output["containedEntityCount"] = |
| 850 | static_cast<unsigned>(pdr->num_children); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 851 | |
| 852 | auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]); |
| 853 | for (int i = 0; i < pdr->num_children; ++i) |
| 854 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 855 | output.emplace("containedEntityType[" + std::to_string(i + 1) + "]", |
| 856 | getEntityName(child->entity_type)); |
| 857 | output.emplace("containedEntityInstanceNumber[" + |
| 858 | std::to_string(i + 1) + "]", |
| 859 | unsigned(child->entity_instance_num)); |
| 860 | output.emplace("containedEntityContainerID[" + |
| 861 | std::to_string(i + 1) + "]", |
| 862 | unsigned(child->entity_container_id)); |
| 863 | |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 864 | ++child; |
| 865 | } |
| 866 | } |
| 867 | |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 868 | /** @brief Format the Sensor/Effecter Aux Name PDR types to json output |
| 869 | * |
| 870 | * @param[in] data - reference to the Sensor/Effecter Aux Name PDR |
| 871 | * @param[out] output - PDRs data fields in Json format |
| 872 | */ |
| 873 | void printAuxNamePDR(uint8_t* data, ordered_json& output) |
| 874 | { |
| 875 | constexpr uint8_t nullTerminator = 0; |
| 876 | struct pldm_effecter_aux_name_pdr* auxNamePdr = |
| 877 | (struct pldm_effecter_aux_name_pdr*)data; |
| 878 | |
| 879 | if (!auxNamePdr) |
| 880 | { |
| 881 | std::cerr << "Failed to get Aux Name PDR" << std::endl; |
| 882 | return; |
| 883 | } |
| 884 | |
| 885 | std::string sPrefix = "effecter"; |
| 886 | if (auxNamePdr->hdr.type == PLDM_SENSOR_AUXILIARY_NAMES_PDR) |
| 887 | { |
| 888 | sPrefix = "sensor"; |
| 889 | } |
| 890 | output["terminusHandle"] = int(auxNamePdr->terminus_handle); |
| 891 | output[sPrefix + "Id"] = int(auxNamePdr->effecter_id); |
| 892 | output[sPrefix + "Count"] = int(auxNamePdr->effecter_count); |
| 893 | |
| 894 | const uint8_t* ptr = auxNamePdr->effecter_names; |
| 895 | for (auto i : std::views::iota(0, (int)auxNamePdr->effecter_count)) |
| 896 | { |
| 897 | const uint8_t nameStringCount = static_cast<uint8_t>(*ptr); |
| 898 | ptr += sizeof(uint8_t); |
| 899 | for (auto j : std::views::iota(0, (int)nameStringCount)) |
| 900 | { |
| 901 | std::string nameLanguageTagKey = sPrefix + std::to_string(j) + |
| 902 | "_nameLanguageTag" + |
| 903 | std::to_string(i); |
| 904 | std::string entityAuxNameKey = sPrefix + std::to_string(j) + |
| 905 | "_entityAuxName" + |
| 906 | std::to_string(i); |
| 907 | std::string nameLanguageTag(reinterpret_cast<const char*>(ptr), |
| 908 | 0, PLDM_STR_UTF_8_MAX_LEN); |
| 909 | ptr += nameLanguageTag.size() + sizeof(nullTerminator); |
| 910 | std::u16string u16NameString( |
| 911 | reinterpret_cast<const char16_t*>(ptr), 0, |
| 912 | PLDM_STR_UTF_16_MAX_LEN); |
| 913 | ptr += (u16NameString.size() + sizeof(nullTerminator)) * |
| 914 | sizeof(uint16_t); |
| 915 | std::transform(u16NameString.cbegin(), u16NameString.cend(), |
| 916 | u16NameString.begin(), |
| 917 | [](uint16_t utf16) { return be16toh(utf16); }); |
| 918 | std::string nameString = |
| 919 | std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, |
| 920 | char16_t>{} |
| 921 | .to_bytes(u16NameString); |
| 922 | output[nameLanguageTagKey] = nameLanguageTag; |
| 923 | output[entityAuxNameKey] = nameString; |
| 924 | } |
| 925 | } |
| 926 | } |
| 927 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 928 | void printNumericEffecterPDR(uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 929 | { |
| 930 | struct pldm_numeric_effecter_value_pdr* pdr = |
| 931 | (struct pldm_numeric_effecter_value_pdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 932 | if (!pdr) |
| 933 | { |
| 934 | std::cerr << "Failed to get numeric effecter PDR" << std::endl; |
| 935 | return; |
| 936 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 937 | |
| 938 | output["PLDMTerminusHandle"] = int(pdr->terminus_handle); |
| 939 | output["effecterID"] = int(pdr->effecter_id); |
| 940 | output["entityType"] = int(pdr->entity_type); |
| 941 | output["entityInstanceNumber"] = int(pdr->entity_instance); |
| 942 | output["containerID"] = int(pdr->container_id); |
| 943 | output["effecterSemanticID"] = int(pdr->effecter_semantic_id); |
| 944 | output["effecterInit"] = unsigned(pdr->effecter_init); |
| 945 | output["effecterAuxiliaryNames"] = |
| 946 | (unsigned(pdr->effecter_auxiliary_names) ? true : false); |
| 947 | output["baseUnit"] = unsigned(pdr->base_unit); |
| 948 | output["unitModifier"] = unsigned(pdr->unit_modifier); |
| 949 | output["rateUnit"] = unsigned(pdr->rate_unit); |
| 950 | output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle); |
| 951 | output["auxUnit"] = unsigned(pdr->aux_unit); |
| 952 | output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier); |
| 953 | output["auxrateUnit"] = unsigned(pdr->aux_rate_unit); |
| 954 | output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle); |
| 955 | output["isLinear"] = (unsigned(pdr->is_linear) ? true : false); |
| 956 | output["effecterDataSize"] = unsigned(pdr->effecter_data_size); |
| 957 | output["resolution"] = unsigned(pdr->resolution); |
| 958 | output["offset"] = unsigned(pdr->offset); |
| 959 | output["accuracy"] = unsigned(pdr->accuracy); |
| 960 | output["plusTolerance"] = unsigned(pdr->plus_tolerance); |
| 961 | output["minusTolerance"] = unsigned(pdr->minus_tolerance); |
| 962 | output["stateTransitionInterval"] = |
| 963 | unsigned(pdr->state_transition_interval); |
| 964 | output["TransitionInterval"] = unsigned(pdr->transition_interval); |
| 965 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 966 | switch (pdr->effecter_data_size) |
| 967 | { |
| 968 | case PLDM_EFFECTER_DATA_SIZE_UINT8: |
Manojkiran Eda | fc0ce97 | 2022-06-25 09:38:28 +0530 | [diff] [blame] | 969 | output["maxSettable"] = unsigned(pdr->max_settable.value_u8); |
| 970 | output["minSettable"] = unsigned(pdr->min_settable.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 971 | break; |
| 972 | case PLDM_EFFECTER_DATA_SIZE_SINT8: |
Manojkiran Eda | fc0ce97 | 2022-06-25 09:38:28 +0530 | [diff] [blame] | 973 | output["maxSettable"] = unsigned(pdr->max_settable.value_s8); |
| 974 | output["minSettable"] = unsigned(pdr->min_settable.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 975 | break; |
| 976 | case PLDM_EFFECTER_DATA_SIZE_UINT16: |
Manojkiran Eda | fc0ce97 | 2022-06-25 09:38:28 +0530 | [diff] [blame] | 977 | output["maxSettable"] = unsigned(pdr->max_settable.value_u16); |
| 978 | output["minSettable"] = unsigned(pdr->min_settable.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 979 | break; |
| 980 | case PLDM_EFFECTER_DATA_SIZE_SINT16: |
Manojkiran Eda | fc0ce97 | 2022-06-25 09:38:28 +0530 | [diff] [blame] | 981 | output["maxSettable"] = unsigned(pdr->max_settable.value_s16); |
| 982 | output["minSettable"] = unsigned(pdr->min_settable.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 983 | break; |
| 984 | case PLDM_EFFECTER_DATA_SIZE_UINT32: |
Manojkiran Eda | fc0ce97 | 2022-06-25 09:38:28 +0530 | [diff] [blame] | 985 | output["maxSettable"] = unsigned(pdr->max_settable.value_u32); |
| 986 | output["minSettable"] = unsigned(pdr->min_settable.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 987 | break; |
| 988 | case PLDM_EFFECTER_DATA_SIZE_SINT32: |
Manojkiran Eda | fc0ce97 | 2022-06-25 09:38:28 +0530 | [diff] [blame] | 989 | output["maxSettable"] = unsigned(pdr->max_settable.value_s32); |
| 990 | output["minSettable"] = unsigned(pdr->min_settable.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 991 | break; |
| 992 | default: |
| 993 | break; |
| 994 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 995 | |
| 996 | output["rangeFieldFormat"] = unsigned(pdr->range_field_format); |
| 997 | output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte); |
| 998 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 999 | switch (pdr->range_field_format) |
| 1000 | { |
| 1001 | case PLDM_RANGE_FIELD_FORMAT_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1002 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u8); |
| 1003 | output["normalMax"] = unsigned(pdr->normal_max.value_u8); |
| 1004 | output["normalMin"] = unsigned(pdr->normal_min.value_u8); |
| 1005 | output["ratedMax"] = unsigned(pdr->rated_max.value_u8); |
| 1006 | output["ratedMin"] = unsigned(pdr->rated_min.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1007 | break; |
| 1008 | case PLDM_RANGE_FIELD_FORMAT_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1009 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s8); |
| 1010 | output["normalMax"] = unsigned(pdr->normal_max.value_s8); |
| 1011 | output["normalMin"] = unsigned(pdr->normal_min.value_s8); |
| 1012 | output["ratedMax"] = unsigned(pdr->rated_max.value_s8); |
| 1013 | output["ratedMin"] = unsigned(pdr->rated_min.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1014 | break; |
| 1015 | case PLDM_RANGE_FIELD_FORMAT_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1016 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u16); |
| 1017 | output["normalMax"] = unsigned(pdr->normal_max.value_u16); |
| 1018 | output["normalMin"] = unsigned(pdr->normal_min.value_u16); |
| 1019 | output["ratedMax"] = unsigned(pdr->rated_max.value_u16); |
| 1020 | output["ratedMin"] = unsigned(pdr->rated_min.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1021 | break; |
| 1022 | case PLDM_RANGE_FIELD_FORMAT_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1023 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s16); |
| 1024 | output["normalMax"] = unsigned(pdr->normal_max.value_s16); |
| 1025 | output["normalMin"] = unsigned(pdr->normal_min.value_s16); |
| 1026 | output["ratedMax"] = unsigned(pdr->rated_max.value_s16); |
| 1027 | output["ratedMin"] = unsigned(pdr->rated_min.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1028 | break; |
| 1029 | case PLDM_RANGE_FIELD_FORMAT_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1030 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u32); |
| 1031 | output["normalMax"] = unsigned(pdr->normal_max.value_u32); |
| 1032 | output["normalMin"] = unsigned(pdr->normal_min.value_u32); |
| 1033 | output["ratedMax"] = unsigned(pdr->rated_max.value_u32); |
| 1034 | output["ratedMin"] = unsigned(pdr->rated_min.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1035 | break; |
| 1036 | case PLDM_RANGE_FIELD_FORMAT_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1037 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s32); |
| 1038 | output["normalMax"] = unsigned(pdr->normal_max.value_s32); |
| 1039 | output["normalMin"] = unsigned(pdr->normal_min.value_s32); |
| 1040 | output["ratedMax"] = unsigned(pdr->rated_max.value_s32); |
| 1041 | output["ratedMin"] = unsigned(pdr->rated_min.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1042 | break; |
| 1043 | case PLDM_RANGE_FIELD_FORMAT_REAL32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1044 | output["nominalValue"] = unsigned(pdr->nominal_value.value_f32); |
| 1045 | output["normalMax"] = unsigned(pdr->normal_max.value_f32); |
| 1046 | output["normalMin"] = unsigned(pdr->normal_min.value_f32); |
| 1047 | output["ratedMax"] = unsigned(pdr->rated_max.value_f32); |
| 1048 | output["ratedMin"] = unsigned(pdr->rated_min.value_f32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1049 | break; |
| 1050 | default: |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1055 | void printStateEffecterPDR(const uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1056 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 1057 | auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1058 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1059 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 1060 | output["effecterID"] = pdr->effecter_id; |
| 1061 | output["entityType"] = getEntityName(pdr->entity_type); |
| 1062 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 1063 | output["containerID"] = pdr->container_id; |
| 1064 | output["effecterSemanticID"] = pdr->effecter_semantic_id; |
| 1065 | output["effecterInit"] = effecterInit[pdr->effecter_init]; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1066 | output["effecterDescriptionPDR"] = (pdr->has_description_pdr ? true |
| 1067 | : false); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1068 | output["compositeEffecterCount"] = |
| 1069 | unsigned(pdr->composite_effecter_count); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1070 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 1071 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 1072 | auto compEffCount = pdr->composite_effecter_count; |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 1073 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 1074 | while (compEffCount--) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1075 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 1076 | auto state = |
| 1077 | reinterpret_cast<const state_effecter_possible_states*>( |
| 1078 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 1079 | output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"), |
| 1080 | getStateSetName(state->state_set_id)); |
| 1081 | output.emplace( |
| 1082 | ("possibleStatesSize[" + std::to_string(compEffCount) + "]"), |
| 1083 | state->possible_states_size); |
| 1084 | output.emplace( |
| 1085 | ("possibleStates[" + std::to_string(compEffCount) + "]"), |
Sridevi Ramesh | dcdcd3b | 2021-06-15 04:06:49 -0500 | [diff] [blame] | 1086 | getStateSetPossibleStateNames( |
| 1087 | state->state_set_id, |
| 1088 | printPossibleStates(state->possible_states_size, |
| 1089 | state->states))); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1090 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 1091 | if (compEffCount) |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 1092 | { |
| 1093 | statesPtr += sizeof(state_effecter_possible_states) + |
| 1094 | state->possible_states_size - 1; |
| 1095 | } |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1099 | bool checkTerminusHandle(const uint8_t* data, |
| 1100 | std::optional<uint16_t> terminusHandle) |
| 1101 | { |
| 1102 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
| 1103 | |
| 1104 | if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR) |
| 1105 | { |
| 1106 | auto tlpdr = |
| 1107 | reinterpret_cast<const pldm_terminus_locator_pdr*>(data); |
| 1108 | |
| 1109 | if (tlpdr->terminus_handle != terminusHandle) |
| 1110 | { |
| 1111 | return true; |
| 1112 | } |
| 1113 | } |
| 1114 | else if (pdr->type == PLDM_STATE_SENSOR_PDR) |
| 1115 | { |
| 1116 | auto sensor = reinterpret_cast<const pldm_state_sensor_pdr*>(data); |
| 1117 | |
| 1118 | if (sensor->terminus_handle != terminusHandle) |
| 1119 | { |
| 1120 | return true; |
| 1121 | } |
| 1122 | } |
| 1123 | else if (pdr->type == PLDM_NUMERIC_EFFECTER_PDR) |
| 1124 | { |
| 1125 | auto numericEffecter = |
| 1126 | reinterpret_cast<const pldm_numeric_effecter_value_pdr*>(data); |
| 1127 | |
| 1128 | if (numericEffecter->terminus_handle != terminusHandle) |
| 1129 | { |
| 1130 | return true; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | else if (pdr->type == PLDM_STATE_EFFECTER_PDR) |
| 1135 | { |
| 1136 | auto stateEffecter = |
| 1137 | reinterpret_cast<const pldm_state_effecter_pdr*>(data); |
| 1138 | if (stateEffecter->terminus_handle != terminusHandle) |
| 1139 | { |
| 1140 | return true; |
| 1141 | } |
| 1142 | } |
| 1143 | else if (pdr->type == PLDM_PDR_FRU_RECORD_SET) |
| 1144 | { |
| 1145 | data += sizeof(pldm_pdr_hdr); |
| 1146 | auto fru = reinterpret_cast<const pldm_pdr_fru_record_set*>(data); |
| 1147 | |
| 1148 | if (fru->terminus_handle != terminusHandle) |
| 1149 | { |
| 1150 | return true; |
| 1151 | } |
| 1152 | } |
| 1153 | else |
| 1154 | { |
| 1155 | // Entity association PDRs does not have terminus handle |
| 1156 | return true; |
| 1157 | } |
| 1158 | |
| 1159 | return false; |
| 1160 | } |
| 1161 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1162 | void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output) |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 1163 | { |
| 1164 | const std::array<std::string_view, 4> terminusLocatorType = { |
| 1165 | "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"}; |
| 1166 | |
| 1167 | auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data); |
| 1168 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1169 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 1170 | output["validity"] = (pdr->validity ? "valid" : "notValid"); |
| 1171 | output["TID"] = unsigned(pdr->tid); |
| 1172 | output["containerID"] = pdr->container_id; |
| 1173 | output["terminusLocatorType"] = |
| 1174 | terminusLocatorType[pdr->terminus_locator_type]; |
| 1175 | output["terminusLocatorValueSize"] = |
| 1176 | unsigned(pdr->terminus_locator_value_size); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 1177 | |
| 1178 | if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID) |
| 1179 | { |
| 1180 | auto locatorValue = |
| 1181 | reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>( |
| 1182 | pdr->terminus_locator_value); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1183 | output["EID"] = unsigned(locatorValue->eid); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 1184 | } |
| 1185 | } |
| 1186 | |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1187 | std::optional<uint16_t> getTerminusHandle(uint8_t* data, |
| 1188 | std::optional<uint8_t> tid) |
| 1189 | { |
| 1190 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
| 1191 | if (pdr->type == PLDM_TERMINUS_LOCATOR_PDR) |
| 1192 | { |
| 1193 | auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data); |
| 1194 | if (pdr->tid == tid) |
| 1195 | { |
| 1196 | handleFound = true; |
| 1197 | return pdr->terminus_handle; |
| 1198 | } |
| 1199 | } |
| 1200 | return std::nullopt; |
| 1201 | } |
| 1202 | |
Thu Nguyen | 9d0e58c | 2021-12-09 13:53:00 +0700 | [diff] [blame] | 1203 | /** @brief Format the Compact Numeric Sensor PDR types to json output |
| 1204 | * |
| 1205 | * @param[in] data - reference to the Compact Numeric Sensor PDR |
| 1206 | * @param[out] output - PDRs data fields in Json format |
| 1207 | */ |
| 1208 | void printCompactNumericSensorPDR(const uint8_t* data, ordered_json& output) |
| 1209 | { |
| 1210 | struct pldm_compact_numeric_sensor_pdr* pdr = |
| 1211 | (struct pldm_compact_numeric_sensor_pdr*)data; |
| 1212 | if (!pdr) |
| 1213 | { |
| 1214 | std::cerr << "Failed to get compact numeric sensor PDR" |
| 1215 | << std::endl; |
| 1216 | return; |
| 1217 | } |
| 1218 | output["PLDMTerminusHandle"] = int(pdr->terminus_handle); |
| 1219 | output["sensorID"] = int(pdr->sensor_id); |
| 1220 | output["entityType"] = getEntityName(pdr->entity_type); |
| 1221 | output["entityInstanceNumber"] = int(pdr->entity_instance); |
| 1222 | output["containerID"] = int(pdr->container_id); |
| 1223 | output["sensorNameStringByteLength"] = int(pdr->sensor_name_length); |
| 1224 | if (pdr->sensor_name_length == 0) |
| 1225 | { |
| 1226 | output["Name"] = std::format("PLDM_Device_TID{}_SensorId{}", |
| 1227 | unsigned(pdr->terminus_handle), |
| 1228 | unsigned(pdr->sensor_id)); |
| 1229 | } |
| 1230 | else |
| 1231 | { |
| 1232 | std::string sTemp(reinterpret_cast<const char*>(pdr->sensor_name), |
| 1233 | pdr->sensor_name_length); |
| 1234 | output["Name"] = sTemp; |
| 1235 | } |
| 1236 | output["baseUnit"] = unsigned(pdr->base_unit); |
| 1237 | output["unitModifier"] = signed(pdr->unit_modifier); |
| 1238 | output["occurrenceRate"] = unsigned(pdr->occurrence_rate); |
| 1239 | output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte); |
| 1240 | if (pdr->range_field_support.bits.bit0) |
| 1241 | { |
| 1242 | output["warningHigh"] = int(pdr->warning_high); |
| 1243 | } |
| 1244 | if (pdr->range_field_support.bits.bit1) |
| 1245 | { |
| 1246 | output["warningLow"] = int(pdr->warning_low); |
| 1247 | } |
| 1248 | if (pdr->range_field_support.bits.bit2) |
| 1249 | { |
| 1250 | output["criticalHigh"] = int(pdr->critical_high); |
| 1251 | } |
| 1252 | if (pdr->range_field_support.bits.bit3) |
| 1253 | { |
| 1254 | output["criticalLow"] = int(pdr->critical_low); |
| 1255 | } |
| 1256 | if (pdr->range_field_support.bits.bit4) |
| 1257 | { |
| 1258 | output["fatalHigh"] = int(pdr->fatal_high); |
| 1259 | } |
| 1260 | if (pdr->range_field_support.bits.bit5) |
| 1261 | { |
| 1262 | output["fatalLow"] = int(pdr->fatal_low); |
| 1263 | } |
| 1264 | } |
| 1265 | |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 1266 | void printPDRMsg(uint32_t& nextRecordHndl, const uint16_t respCnt, |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1267 | uint8_t* data, std::optional<uint16_t> terminusHandle) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1268 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1269 | if (data == NULL) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1270 | { |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 1271 | std::cerr << "Failed to get PDR message" << std::endl; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1272 | return; |
| 1273 | } |
| 1274 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1275 | ordered_json output; |
| 1276 | output["nextRecordHandle"] = nextRecordHndl; |
| 1277 | output["responseCount"] = respCnt; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1278 | |
| 1279 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 1280 | if (!pdr) |
| 1281 | { |
| 1282 | return; |
| 1283 | } |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 1284 | |
| 1285 | if (!pdrRecType.empty()) |
| 1286 | { |
| 1287 | // Need to return if the requested PDR type |
| 1288 | // is not supported |
| 1289 | if (!strToPdrType.contains(pdrRecType)) |
| 1290 | { |
| 1291 | std::cerr << "PDR type '" << pdrRecType |
| 1292 | << "' is not supported or invalid\n"; |
Pavithra Barithaya | 6e20f7c | 2023-08-22 00:50:47 -0500 | [diff] [blame] | 1293 | // PDR type not supported, setting next record handle to |
| 1294 | // 0 to avoid looping through all PDR records |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 1295 | nextRecordHndl = 0; |
| 1296 | return; |
| 1297 | } |
| 1298 | |
| 1299 | // Do not print PDR record if the current record |
| 1300 | // PDR type does not match with requested type |
| 1301 | if (pdr->type != strToPdrType.at(pdrRecType)) |
| 1302 | { |
| 1303 | return; |
| 1304 | } |
| 1305 | } |
| 1306 | |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1307 | if (pdrTerminus.has_value()) |
| 1308 | { |
| 1309 | if (checkTerminusHandle(data, terminusHandle)) |
| 1310 | { |
| 1311 | std::cerr << "The Terminus handle doesn't match return" |
| 1312 | << std::endl; |
| 1313 | return; |
| 1314 | } |
| 1315 | } |
| 1316 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1317 | printCommonPDRHeader(pdr, output); |
| 1318 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1319 | switch (pdr->type) |
| 1320 | { |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 1321 | case PLDM_TERMINUS_LOCATOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1322 | printTerminusLocatorPDR(data, output); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 1323 | break; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 1324 | case PLDM_STATE_SENSOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1325 | printStateSensorPDR(data, output); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 1326 | break; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1327 | case PLDM_NUMERIC_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1328 | printNumericEffecterPDR(data, output); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 1329 | break; |
Thu Nguyen | 846d38f | 2022-03-26 08:57:21 +0700 | [diff] [blame] | 1330 | case PLDM_SENSOR_AUXILIARY_NAMES_PDR: |
| 1331 | printAuxNamePDR(data, output); |
| 1332 | break; |
| 1333 | case PLDM_EFFECTER_AUXILIARY_NAMES_PDR: |
| 1334 | printAuxNamePDR(data, output); |
| 1335 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1336 | case PLDM_STATE_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1337 | printStateEffecterPDR(data, output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1338 | break; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 1339 | case PLDM_PDR_ENTITY_ASSOCIATION: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1340 | printPDREntityAssociation(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 1341 | break; |
| 1342 | case PLDM_PDR_FRU_RECORD_SET: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1343 | printPDRFruRecordSet(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 1344 | break; |
Thu Nguyen | 9d0e58c | 2021-12-09 13:53:00 +0700 | [diff] [blame] | 1345 | case PLDM_COMPACT_NUMERIC_SENSOR_PDR: |
| 1346 | printCompactNumericSensorPDR(data, output); |
| 1347 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1348 | default: |
| 1349 | break; |
| 1350 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1351 | pldmtool::helper::DisplayInJson(output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | private: |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1355 | bool optTIDSet = false; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1356 | uint32_t recordHandle; |
Shantappa Teekappanavar | 3ddbe43 | 2021-06-29 15:46:06 -0500 | [diff] [blame] | 1357 | bool allPDRs; |
| 1358 | std::string pdrRecType; |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1359 | std::optional<uint8_t> pdrTerminus; |
| 1360 | std::optional<uint16_t> terminusHandle; |
| 1361 | bool handleFound = false; |
| 1362 | CLI::Option* getPDRGroupOption = nullptr; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1363 | }; |
| 1364 | |
| 1365 | class SetStateEffecter : public CommandInterface |
| 1366 | { |
| 1367 | public: |
| 1368 | ~SetStateEffecter() = default; |
| 1369 | SetStateEffecter() = delete; |
| 1370 | SetStateEffecter(const SetStateEffecter&) = delete; |
| 1371 | SetStateEffecter(SetStateEffecter&&) = default; |
| 1372 | SetStateEffecter& operator=(const SetStateEffecter&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 1373 | SetStateEffecter& operator=(SetStateEffecter&&) = delete; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1374 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1375 | // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2) |
| 1376 | static constexpr auto maxEffecterDataSize = 16; |
| 1377 | |
| 1378 | // compositeEffecterCount(value: 0x01 to 0x08) |
| 1379 | static constexpr auto minEffecterCount = 1; |
| 1380 | static constexpr auto maxEffecterCount = 8; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1381 | explicit SetStateEffecter(const char* type, const char* name, |
| 1382 | CLI::App* app) : |
| 1383 | CommandInterface(type, name, app) |
| 1384 | { |
| 1385 | app->add_option( |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1386 | "-i, --id", effecterId, |
| 1387 | "A handle that is used to identify and access the effecter") |
| 1388 | ->required(); |
| 1389 | app->add_option("-c, --count", effecterCount, |
| 1390 | "The number of individual sets of effecter information") |
| 1391 | ->required(); |
| 1392 | app->add_option( |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1393 | "-d,--data", effecterData, |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1394 | "Set effecter state data\n" |
| 1395 | "eg: requestSet0 effecterState0 noChange1 dummyState1 ...") |
| 1396 | ->required(); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 1400 | { |
| 1401 | std::vector<uint8_t> requestMsg( |
| 1402 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES); |
| 1403 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1404 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1405 | if (effecterCount > maxEffecterCount || |
| 1406 | effecterCount < minEffecterCount) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1407 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1408 | std::cerr << "Request Message Error: effecterCount size " |
| 1409 | << effecterCount << "is invalid\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1410 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 1411 | return {rc, requestMsg}; |
| 1412 | } |
| 1413 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1414 | if (effecterData.size() > maxEffecterDataSize) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1415 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1416 | std::cerr << "Request Message Error: effecterData size " |
| 1417 | << effecterData.size() << "is invalid\n"; |
| 1418 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 1419 | return {rc, requestMsg}; |
| 1420 | } |
| 1421 | |
| 1422 | auto stateField = parseEffecterData(effecterData, effecterCount); |
| 1423 | if (!stateField) |
| 1424 | { |
| 1425 | std::cerr << "Failed to parse effecter data, effecterCount size " |
| 1426 | << effecterCount << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1427 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 1428 | return {rc, requestMsg}; |
| 1429 | } |
| 1430 | |
| 1431 | auto rc = encode_set_state_effecter_states_req( |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 1432 | instanceId, effecterId, effecterCount, stateField->data(), request); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1433 | return {rc, requestMsg}; |
| 1434 | } |
| 1435 | |
| 1436 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 1437 | { |
| 1438 | uint8_t completionCode = 0; |
| 1439 | auto rc = decode_set_state_effecter_states_resp( |
| 1440 | responsePtr, payloadLength, &completionCode); |
| 1441 | |
| 1442 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 1443 | { |
| 1444 | std::cerr << "Response Message Error: " |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1445 | << "rc=" << rc << ",cc=" << (int)completionCode << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1446 | return; |
| 1447 | } |
| 1448 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1449 | ordered_json data; |
| 1450 | data["Response"] = "SUCCESS"; |
| 1451 | pldmtool::helper::DisplayInJson(data); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | private: |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 1455 | uint16_t effecterId; |
| 1456 | uint8_t effecterCount; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1457 | std::vector<uint8_t> effecterData; |
| 1458 | }; |
| 1459 | |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 1460 | class SetNumericEffecterValue : public CommandInterface |
| 1461 | { |
| 1462 | public: |
| 1463 | ~SetNumericEffecterValue() = default; |
| 1464 | SetNumericEffecterValue() = delete; |
| 1465 | SetNumericEffecterValue(const SetNumericEffecterValue&) = delete; |
| 1466 | SetNumericEffecterValue(SetNumericEffecterValue&&) = default; |
| 1467 | SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 1468 | SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = delete; |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 1469 | |
| 1470 | explicit SetNumericEffecterValue(const char* type, const char* name, |
| 1471 | CLI::App* app) : |
| 1472 | CommandInterface(type, name, app) |
| 1473 | { |
| 1474 | app->add_option( |
| 1475 | "-i, --id", effecterId, |
| 1476 | "A handle that is used to identify and access the effecter") |
| 1477 | ->required(); |
| 1478 | app->add_option("-s, --size", effecterDataSize, |
| 1479 | "The bit width and format of the setting value for the " |
| 1480 | "effecter. enum value: {uint8, sint8, uint16, sint16, " |
| 1481 | "uint32, sint32}\n") |
| 1482 | ->required(); |
| 1483 | app->add_option("-d,--data", maxEffecterValue, |
| 1484 | "The setting value of numeric effecter being " |
| 1485 | "requested\n") |
| 1486 | ->required(); |
| 1487 | } |
| 1488 | |
| 1489 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 1490 | { |
| 1491 | std::vector<uint8_t> requestMsg( |
| 1492 | sizeof(pldm_msg_hdr) + |
| 1493 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3); |
| 1494 | |
| 1495 | uint8_t* effecterValue = (uint8_t*)&maxEffecterValue; |
| 1496 | |
| 1497 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1498 | size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES; |
| 1499 | |
| 1500 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1501 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16) |
| 1502 | { |
| 1503 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1; |
| 1504 | } |
| 1505 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1506 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32) |
| 1507 | { |
| 1508 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3; |
| 1509 | } |
| 1510 | auto rc = encode_set_numeric_effecter_value_req( |
| 1511 | 0, effecterId, effecterDataSize, effecterValue, request, |
| 1512 | payload_length); |
| 1513 | |
| 1514 | return {rc, requestMsg}; |
| 1515 | } |
| 1516 | |
| 1517 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 1518 | { |
| 1519 | uint8_t completionCode = 0; |
| 1520 | auto rc = decode_set_numeric_effecter_value_resp( |
| 1521 | responsePtr, payloadLength, &completionCode); |
| 1522 | |
| 1523 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 1524 | { |
| 1525 | std::cerr << "Response Message Error: " |
| 1526 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 1527 | << std::endl; |
| 1528 | return; |
| 1529 | } |
| 1530 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 1531 | ordered_json data; |
| 1532 | data["Response"] = "SUCCESS"; |
| 1533 | pldmtool::helper::DisplayInJson(data); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | private: |
| 1537 | uint16_t effecterId; |
| 1538 | uint8_t effecterDataSize; |
| 1539 | uint64_t maxEffecterValue; |
| 1540 | }; |
| 1541 | |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1542 | class GetStateSensorReadings : public CommandInterface |
| 1543 | { |
| 1544 | public: |
| 1545 | ~GetStateSensorReadings() = default; |
| 1546 | GetStateSensorReadings() = delete; |
| 1547 | GetStateSensorReadings(const GetStateSensorReadings&) = delete; |
| 1548 | GetStateSensorReadings(GetStateSensorReadings&&) = default; |
| 1549 | GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 1550 | GetStateSensorReadings& operator=(GetStateSensorReadings&&) = delete; |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1551 | |
| 1552 | explicit GetStateSensorReadings(const char* type, const char* name, |
| 1553 | CLI::App* app) : |
| 1554 | CommandInterface(type, name, app) |
| 1555 | { |
| 1556 | app->add_option( |
| 1557 | "-i, --sensor_id", sensorId, |
| 1558 | "Sensor ID that is used to identify and access the sensor") |
| 1559 | ->required(); |
| 1560 | app->add_option("-r, --rearm", sensorRearm, |
| 1561 | "Each bit location in this field corresponds to a " |
| 1562 | "particular sensor") |
| 1563 | ->required(); |
| 1564 | } |
| 1565 | |
| 1566 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 1567 | { |
| 1568 | std::vector<uint8_t> requestMsg( |
| 1569 | sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES); |
| 1570 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1571 | |
| 1572 | uint8_t reserved = 0; |
| 1573 | bitfield8_t bf; |
| 1574 | bf.byte = sensorRearm; |
| 1575 | auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf, |
| 1576 | reserved, request); |
| 1577 | |
| 1578 | return {rc, requestMsg}; |
| 1579 | } |
| 1580 | |
| 1581 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 1582 | { |
| 1583 | uint8_t completionCode = 0; |
| 1584 | uint8_t compSensorCount = 0; |
| 1585 | std::array<get_sensor_state_field, 8> stateField{}; |
| 1586 | auto rc = decode_get_state_sensor_readings_resp( |
| 1587 | responsePtr, payloadLength, &completionCode, &compSensorCount, |
| 1588 | stateField.data()); |
| 1589 | |
| 1590 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 1591 | { |
| 1592 | std::cerr << "Response Message Error: " |
| 1593 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 1594 | << std::endl; |
| 1595 | return; |
| 1596 | } |
| 1597 | ordered_json output; |
| 1598 | output["compositeSensorCount"] = (int)compSensorCount; |
| 1599 | |
| 1600 | for (size_t i = 0; i < compSensorCount; i++) |
| 1601 | { |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 1602 | if (sensorOpState.contains(stateField[i].sensor_op_state)) |
| 1603 | { |
| 1604 | output.emplace(("sensorOpState[" + std::to_string(i) + "]"), |
| 1605 | sensorOpState.at(stateField[i].sensor_op_state)); |
| 1606 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1607 | |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 1608 | if (sensorPresState.contains(stateField[i].present_state)) |
| 1609 | { |
| 1610 | output.emplace(("presentState[" + std::to_string(i) + "]"), |
| 1611 | sensorPresState.at(stateField[i].present_state)); |
| 1612 | } |
| 1613 | |
| 1614 | if (sensorPresState.contains(stateField[i].previous_state)) |
| 1615 | { |
| 1616 | output.emplace( |
| 1617 | ("previousState[" + std::to_string(i) + "]"), |
| 1618 | sensorPresState.at(stateField[i].previous_state)); |
| 1619 | } |
| 1620 | |
| 1621 | if (sensorPresState.contains(stateField[i].event_state)) |
| 1622 | { |
| 1623 | output.emplace(("eventState[" + std::to_string(i) + "]"), |
| 1624 | sensorPresState.at(stateField[i].event_state)); |
| 1625 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | pldmtool::helper::DisplayInJson(output); |
| 1629 | } |
| 1630 | |
| 1631 | private: |
| 1632 | uint16_t sensorId; |
| 1633 | uint8_t sensorRearm; |
| 1634 | }; |
| 1635 | |
Pavithra Barithaya | 8c15e00 | 2023-10-17 04:14:21 -0500 | [diff] [blame] | 1636 | class GetNumericEffecterValue : public CommandInterface |
| 1637 | { |
| 1638 | public: |
| 1639 | ~GetNumericEffecterValue() = default; |
| 1640 | GetNumericEffecterValue() = delete; |
| 1641 | GetNumericEffecterValue(const GetNumericEffecterValue&) = delete; |
| 1642 | GetNumericEffecterValue(GetNumericEffecterValue&&) = default; |
| 1643 | GetNumericEffecterValue& operator=(const GetNumericEffecterValue&) = delete; |
| 1644 | GetNumericEffecterValue& operator=(GetNumericEffecterValue&&) = default; |
| 1645 | |
| 1646 | explicit GetNumericEffecterValue(const char* type, const char* name, |
| 1647 | CLI::App* app) : |
| 1648 | CommandInterface(type, name, app) |
| 1649 | { |
| 1650 | app->add_option( |
| 1651 | "-i, --effecter_id", effecterId, |
| 1652 | "A handle that is used to identify and access the effecter") |
| 1653 | ->required(); |
| 1654 | } |
| 1655 | |
| 1656 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 1657 | { |
| 1658 | std::vector<uint8_t> requestMsg( |
| 1659 | sizeof(pldm_msg_hdr) + PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES); |
| 1660 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1661 | |
| 1662 | auto rc = encode_get_numeric_effecter_value_req(instanceId, effecterId, |
| 1663 | request); |
| 1664 | |
| 1665 | return {rc, requestMsg}; |
| 1666 | } |
| 1667 | |
| 1668 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 1669 | { |
| 1670 | uint8_t completionCode = 0; |
| 1671 | uint8_t effecterDataSize = 0; |
| 1672 | uint8_t effecterOperationalState = 0; |
| 1673 | std::array<uint8_t, sizeof(uint32_t)> |
| 1674 | pendingValue{}; // maximum size for the pending Value is uint32 |
| 1675 | // according to spec DSP0248 |
| 1676 | std::array<uint8_t, sizeof(uint32_t)> |
| 1677 | presentValue{}; // maximum size for the present Value is uint32 |
| 1678 | // according to spec DSP0248 |
| 1679 | |
| 1680 | auto rc = decode_get_numeric_effecter_value_resp( |
| 1681 | responsePtr, payloadLength, &completionCode, &effecterDataSize, |
| 1682 | &effecterOperationalState, pendingValue.data(), |
| 1683 | presentValue.data()); |
| 1684 | |
| 1685 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 1686 | { |
| 1687 | std::cerr << "Response Message Error: " |
| 1688 | << "rc=" << rc |
| 1689 | << ",cc=" << static_cast<int>(completionCode) |
| 1690 | << std::endl; |
| 1691 | return; |
| 1692 | } |
| 1693 | |
| 1694 | ordered_json output; |
| 1695 | output["effecterDataSize"] = static_cast<int>(effecterDataSize); |
| 1696 | output["effecterOperationalState"] = |
| 1697 | getOpState(effecterOperationalState); |
| 1698 | |
| 1699 | switch (effecterDataSize) |
| 1700 | { |
| 1701 | case PLDM_EFFECTER_DATA_SIZE_UINT8: |
| 1702 | { |
| 1703 | output["pendingValue"] = |
| 1704 | *(reinterpret_cast<uint8_t*>(pendingValue.data())); |
| 1705 | output["presentValue"] = |
| 1706 | *(reinterpret_cast<uint8_t*>(presentValue.data())); |
| 1707 | break; |
| 1708 | } |
| 1709 | case PLDM_EFFECTER_DATA_SIZE_SINT8: |
| 1710 | { |
| 1711 | output["pendingValue"] = |
| 1712 | *(reinterpret_cast<int8_t*>(pendingValue.data())); |
| 1713 | output["presentValue"] = |
| 1714 | *(reinterpret_cast<int8_t*>(presentValue.data())); |
| 1715 | break; |
| 1716 | } |
| 1717 | case PLDM_EFFECTER_DATA_SIZE_UINT16: |
| 1718 | { |
| 1719 | output["pendingValue"] = |
| 1720 | *(reinterpret_cast<uint16_t*>(pendingValue.data())); |
| 1721 | output["presentValue"] = |
| 1722 | *(reinterpret_cast<uint16_t*>(presentValue.data())); |
| 1723 | break; |
| 1724 | } |
| 1725 | case PLDM_EFFECTER_DATA_SIZE_SINT16: |
| 1726 | { |
| 1727 | output["pendingValue"] = |
| 1728 | *(reinterpret_cast<int16_t*>(pendingValue.data())); |
| 1729 | output["presentValue"] = |
| 1730 | *(reinterpret_cast<int16_t*>(presentValue.data())); |
| 1731 | break; |
| 1732 | } |
| 1733 | case PLDM_EFFECTER_DATA_SIZE_UINT32: |
| 1734 | { |
| 1735 | output["pendingValue"] = |
| 1736 | *(reinterpret_cast<uint32_t*>(pendingValue.data())); |
| 1737 | output["presentValue"] = |
| 1738 | *(reinterpret_cast<uint32_t*>(presentValue.data())); |
| 1739 | break; |
| 1740 | } |
| 1741 | case PLDM_EFFECTER_DATA_SIZE_SINT32: |
| 1742 | { |
| 1743 | output["pendingValue"] = |
| 1744 | *(reinterpret_cast<int32_t*>(pendingValue.data())); |
| 1745 | output["presentValue"] = |
| 1746 | *(reinterpret_cast<int32_t*>(presentValue.data())); |
| 1747 | break; |
| 1748 | } |
| 1749 | default: |
| 1750 | { |
| 1751 | std::cerr << "Unknown Effecter Data Size : " |
| 1752 | << static_cast<int>(effecterDataSize) << std::endl; |
| 1753 | break; |
| 1754 | } |
| 1755 | } |
| 1756 | |
| 1757 | pldmtool::helper::DisplayInJson(output); |
| 1758 | } |
| 1759 | |
| 1760 | private: |
| 1761 | uint16_t effecterId; |
| 1762 | |
| 1763 | static inline const std::map<uint8_t, std::string> numericEffecterOpState{ |
| 1764 | {EFFECTER_OPER_STATE_ENABLED_UPDATEPENDING, |
| 1765 | "Effecter Enabled Update Pending"}, |
| 1766 | {EFFECTER_OPER_STATE_ENABLED_NOUPDATEPENDING, |
| 1767 | "Effecter Enabled No Update Pending"}, |
| 1768 | {EFFECTER_OPER_STATE_DISABLED, "Effecter Disabled"}, |
| 1769 | {EFFECTER_OPER_STATE_UNAVAILABLE, "Effecter Unavailable"}, |
| 1770 | {EFFECTER_OPER_STATE_STATUSUNKNOWN, "Effecter Status Unknown"}, |
| 1771 | {EFFECTER_OPER_STATE_FAILED, "Effecter Failed"}, |
| 1772 | {EFFECTER_OPER_STATE_INITIALIZING, "Effecter Initializing"}, |
| 1773 | {EFFECTER_OPER_STATE_SHUTTINGDOWN, "Effecter Shutting Down"}, |
| 1774 | {EFFECTER_OPER_STATE_INTEST, "Effecter In Test"}}; |
| 1775 | |
| 1776 | std::string getOpState(uint8_t state) |
| 1777 | { |
| 1778 | auto typeString = std::to_string(state); |
| 1779 | try |
| 1780 | { |
| 1781 | return numericEffecterOpState.at(state); |
| 1782 | } |
| 1783 | catch (const std::out_of_range& e) |
| 1784 | { |
| 1785 | return typeString; |
| 1786 | } |
| 1787 | } |
| 1788 | }; |
| 1789 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1790 | void registerCommand(CLI::App& app) |
| 1791 | { |
| 1792 | auto platform = app.add_subcommand("platform", "platform type command"); |
| 1793 | platform->require_subcommand(1); |
| 1794 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 1795 | auto getPDR = platform->add_subcommand("GetPDR", |
| 1796 | "get platform descriptor records"); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1797 | commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR)); |
| 1798 | |
| 1799 | auto setStateEffecterStates = platform->add_subcommand( |
| 1800 | "SetStateEffecterStates", "set effecter states"); |
| 1801 | commands.push_back(std::make_unique<SetStateEffecter>( |
| 1802 | "platform", "setStateEffecterStates", setStateEffecterStates)); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 1803 | |
| 1804 | auto setNumericEffecterValue = platform->add_subcommand( |
| 1805 | "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter"); |
| 1806 | commands.push_back(std::make_unique<SetNumericEffecterValue>( |
| 1807 | "platform", "setNumericEffecterValue", setNumericEffecterValue)); |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1808 | |
| 1809 | auto getStateSensorReadings = platform->add_subcommand( |
| 1810 | "GetStateSensorReadings", "get the state sensor readings"); |
| 1811 | commands.push_back(std::make_unique<GetStateSensorReadings>( |
| 1812 | "platform", "getStateSensorReadings", getStateSensorReadings)); |
Pavithra Barithaya | 8c15e00 | 2023-10-17 04:14:21 -0500 | [diff] [blame] | 1813 | |
| 1814 | auto getNumericEffecterValue = platform->add_subcommand( |
| 1815 | "GetNumericEffecterValue", "get the numeric effecter value"); |
| 1816 | commands.push_back(std::make_unique<GetNumericEffecterValue>( |
| 1817 | "platform", "getNumericEffecterValue", getNumericEffecterValue)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1818 | } |
| 1819 | |
Pavithra Barithaya | a340eed | 2023-02-14 03:32:47 -0600 | [diff] [blame] | 1820 | void parseGetPDROption() |
| 1821 | { |
| 1822 | for (const auto& command : commands) |
| 1823 | { |
| 1824 | if (command.get()->getPLDMType() == "platform" && |
| 1825 | command.get()->getCommandName() == "getPDR") |
| 1826 | { |
| 1827 | auto getPDR = dynamic_cast<GetPDR*>(command.get()); |
| 1828 | getPDR->parseGetPDROptions(); |
| 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1833 | } // namespace platform |
| 1834 | } // namespace pldmtool |