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