Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 1 | #include "libpldm/entity.h" |
| 2 | #include "libpldm/state_set.h" |
| 3 | |
| 4 | #include "common/types.hpp" |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 5 | #include "pldm_cmd_helper.hpp" |
| 6 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 7 | namespace pldmtool |
| 8 | { |
| 9 | |
| 10 | namespace platform |
| 11 | { |
| 12 | |
| 13 | namespace |
| 14 | { |
| 15 | |
| 16 | using namespace pldmtool::helper; |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 17 | |
| 18 | static const std::map<uint8_t, std::string> sensorPresState{ |
| 19 | {PLDM_SENSOR_UNKNOWN, "Sensor Unknown"}, |
| 20 | {PLDM_SENSOR_NORMAL, "Sensor Normal"}, |
| 21 | {PLDM_SENSOR_WARNING, "Sensor Warning"}, |
| 22 | {PLDM_SENSOR_CRITICAL, "Sensor Critical"}, |
| 23 | {PLDM_SENSOR_FATAL, "Sensor Fatal"}, |
| 24 | {PLDM_SENSOR_LOWERWARNING, "Sensor Lower Warning"}, |
| 25 | {PLDM_SENSOR_LOWERCRITICAL, "Sensor Lower Critical"}, |
| 26 | {PLDM_SENSOR_LOWERFATAL, "Sensor Lower Fatal"}, |
| 27 | {PLDM_SENSOR_UPPERWARNING, "Sensor Upper Warning"}, |
| 28 | {PLDM_SENSOR_UPPERCRITICAL, "Sensor Upper Critical"}, |
| 29 | {PLDM_SENSOR_UPPERFATAL, "Sensor Upper Fatal"}}; |
| 30 | |
| 31 | static const std::map<uint8_t, std::string> sensorOpState{ |
| 32 | {PLDM_SENSOR_ENABLED, "Sensor Enabled"}, |
| 33 | {PLDM_SENSOR_DISABLED, "Sensor Disabled"}, |
| 34 | {PLDM_SENSOR_UNAVAILABLE, "Sensor Unavailable"}, |
| 35 | {PLDM_SENSOR_STATUSUNKOWN, "Sensor Status Unknown"}, |
| 36 | {PLDM_SENSOR_FAILED, "Sensor Failed"}, |
| 37 | {PLDM_SENSOR_INITIALIZING, "Sensor Sensor Intializing"}, |
| 38 | {PLDM_SENSOR_SHUTTINGDOWN, "Sensor Shutting down"}, |
| 39 | {PLDM_SENSOR_INTEST, "Sensor Intest"}}; |
| 40 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 41 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 42 | |
| 43 | } // namespace |
| 44 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 45 | using ordered_json = nlohmann::ordered_json; |
| 46 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 47 | class GetPDR : public CommandInterface |
| 48 | { |
| 49 | public: |
| 50 | ~GetPDR() = default; |
| 51 | GetPDR() = delete; |
| 52 | GetPDR(const GetPDR&) = delete; |
| 53 | GetPDR(GetPDR&&) = default; |
| 54 | GetPDR& operator=(const GetPDR&) = delete; |
| 55 | GetPDR& operator=(GetPDR&&) = default; |
| 56 | |
| 57 | using CommandInterface::CommandInterface; |
| 58 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 59 | explicit GetPDR(const char* type, const char* name, CLI::App* app) : |
| 60 | CommandInterface(type, name, app) |
| 61 | { |
| 62 | app->add_option( |
| 63 | "-d,--data", recordHandle, |
| 64 | "retrieve individual PDRs from a PDR Repository\n" |
| 65 | "eg: The recordHandle value for the PDR to be retrieved and 0 " |
| 66 | "means get first PDR in the repository.") |
| 67 | ->required(); |
| 68 | } |
| 69 | |
| 70 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 71 | { |
| 72 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 73 | PLDM_GET_PDR_REQ_BYTES); |
| 74 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 75 | |
Deepak Kodihalli | a59cdc6 | 2020-07-14 05:11:33 -0500 | [diff] [blame] | 76 | auto rc = |
| 77 | encode_get_pdr_req(instanceId, recordHandle, 0, PLDM_GET_FIRSTPART, |
| 78 | UINT16_MAX, 0, request, PLDM_GET_PDR_REQ_BYTES); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 79 | return {rc, requestMsg}; |
| 80 | } |
| 81 | |
| 82 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 83 | { |
| 84 | uint8_t completionCode = 0; |
Deepak Kodihalli | a59cdc6 | 2020-07-14 05:11:33 -0500 | [diff] [blame] | 85 | uint8_t recordData[UINT16_MAX] = {0}; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 86 | uint32_t nextRecordHndl = 0; |
| 87 | uint32_t nextDataTransferHndl = 0; |
| 88 | uint8_t transferFlag = 0; |
| 89 | uint16_t respCnt = 0; |
| 90 | uint8_t transferCRC = 0; |
| 91 | |
| 92 | auto rc = decode_get_pdr_resp( |
| 93 | responsePtr, payloadLength, &completionCode, &nextRecordHndl, |
| 94 | &nextDataTransferHndl, &transferFlag, &respCnt, recordData, |
| 95 | sizeof(recordData), &transferCRC); |
| 96 | |
| 97 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 98 | { |
| 99 | std::cerr << "Response Message Error: " |
| 100 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 101 | << std::endl; |
| 102 | return; |
| 103 | } |
| 104 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 105 | printPDRMsg(nextRecordHndl, respCnt, recordData); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | private: |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 109 | const std::map<pldm::pdr::EntityType, std::string> entityType = { |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 110 | {PLDM_ENTITY_UNSPECIFIED, "Unspecified"}, |
| 111 | {PLDM_ENTITY_OTHER, "Other"}, |
| 112 | {PLDM_ENTITY_NETWORK, "Network"}, |
| 113 | {PLDM_ENTITY_GROUP, "Group"}, |
| 114 | {PLDM_ENTITY_REMOTE_MGMT_COMM_DEVICE, |
| 115 | "Remote Management Communication Device"}, |
| 116 | {PLDM_ENTITY_EXTERNAL_ENVIRONMENT, "External Environment"}, |
| 117 | {PLDM_ENTITY_COMM_CHANNEL, " Communication Channel"}, |
| 118 | {PLDM_ENTITY_TERMINUS, "PLDM Terminus"}, |
| 119 | {PLDM_ENTITY_PLATFORM_EVENT_LOG, " Platform Event Log"}, |
| 120 | {PLDM_ENTITY_KEYPAD, "keypad"}, |
| 121 | {PLDM_ENTITY_SWITCH, "Switch"}, |
| 122 | {PLDM_ENTITY_PUSHBUTTON, "Pushbutton"}, |
| 123 | {PLDM_ENTITY_DISPLAY, "Display"}, |
| 124 | {PLDM_ENTITY_INDICATOR, "Indicator"}, |
| 125 | {PLDM_ENTITY_SYS_MGMT_SW, "System Management Software"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 126 | {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 127 | {PLDM_ENTITY_OPERATING_SYS, "Operating System"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 128 | {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 129 | {PLDM_ENTITY_OS_LOADER, "OS Loader"}, |
| 130 | {PLDM_ENTITY_DEVICE_DRIVER, "Device Driver"}, |
| 131 | {PLDM_ENTITY_MGMT_CONTROLLER_FW, "Management Controller Firmware"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 132 | {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 133 | {PLDM_ENTITY_SUB_CHASSIS, "Sub-chassis"}, |
| 134 | {PLDM_ENTITY_DISK_DRIVE_BAY, "Disk Drive Bay"}, |
| 135 | {PLDM_ENTITY_PERIPHERAL_BAY, "Peripheral Bay"}, |
| 136 | {PLDM_ENTITY_DEVICE_BAY, "Device bay"}, |
| 137 | {PLDM_ENTITY_DOOR, "Door"}, |
| 138 | {PLDM_ENTITY_ACCESS_PANEL, "Access Panel"}, |
| 139 | {PLDM_ENTITY_COVER, "Cover"}, |
| 140 | {PLDM_ENTITY_BOARD, "Board"}, |
| 141 | {PLDM_ENTITY_CARD, "Card"}, |
| 142 | {PLDM_ENTITY_MODULE, "Module"}, |
| 143 | {PLDM_ENTITY_SYS_MGMT_MODULE, "System management module"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 144 | {PLDM_ENTITY_SYS_BOARD, "System Board"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 145 | {PLDM_ENTITY_MEMORY_BOARD, "Memory Board"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 146 | {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"}, |
| 147 | {PLDM_ENTITY_PROC_MODULE, "Processor Module"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 148 | {PLDM_ENTITY_ADD_IN_CARD, "Add-in Card"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 149 | {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 150 | "Chassis front panel board(control panel)"}, |
| 151 | {PLDM_ENTITY_BACK_PANEL_BOARD, "Back panel board"}, |
| 152 | {PLDM_ENTITY_POWER_MGMT, "Power management board"}, |
| 153 | {PLDM_ENTITY_POWER_SYS_BOARD, "Power system board"}, |
| 154 | {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"}, |
| 155 | {PLDM_ENTITY_SYS_INTERNAL_EXPANSION_BOARD, |
| 156 | "System internal expansion board"}, |
| 157 | {PLDM_ENTITY_OTHER_SYS_BOARD, "Other system board"}, |
| 158 | {PLDM_ENTITY_CHASSIS_BACK_PANEL_BOARD, "Chassis back panel board"}, |
| 159 | {PLDM_ENTITY_PROCESSING_BLADE, "Processing blade"}, |
| 160 | {PLDM_ENTITY_CONNECTIVITY_SWITCH, "Connectivity switch"}, |
| 161 | {PLDM_ENTITY_PROC_MEMORY_MODULE, "Processor/Memory Module"}, |
| 162 | {PLDM_ENTITY_IO_MODULE, "I/O Module"}, |
| 163 | {PLDM_ENTITY_PROC_IO_MODULE, "Processor I/O Module"}, |
| 164 | {PLDM_ENTITY_COOLING_DEVICE, "Cooling device"}, |
| 165 | {PLDM_ENTITY_COOLING_SUBSYSTEM, "Cooling subsystem"}, |
| 166 | {PLDM_ENTITY_COOLING_UNIT, "Cooling Unit"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 167 | {PLDM_ENTITY_FAN, "Fan"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 168 | {PLDM_ENTITY_PELTIER_COOLING_DEVICE, "Peltier Cooling Device"}, |
| 169 | {PLDM_ENTITY_LIQUID_COOLING_DEVICE, "Liquid Cooling Device"}, |
| 170 | {PLDM_ENTITY_LIQUID_COOLING_SUBSYSTEM, "Liquid Colling Subsystem"}, |
| 171 | {PLDM_ENTITY_OTHER_STORAGE_DEVICE, "Other Storage Device"}, |
| 172 | {PLDM_ENTITY_FLOPPY_DRIVE, "Floppy Drive"}, |
| 173 | {PLDM_ENTITY_FIXED_DISK_HARD_DRIVE, "Hard Drive"}, |
| 174 | {PLDM_ENTITY_CD_DRIVE, "CD Drive"}, |
| 175 | {PLDM_ENTITY_CD_DVD_DRIVE, "CD/DVD Drive"}, |
| 176 | {PLDM_ENTITY_OTHER_SILICON_STORAGE_DEVICE, |
| 177 | "Other Silicon Storage Device"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 178 | {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 179 | {PLDM_ENTITY_POWER_SUPPLY, "Power supply"}, |
| 180 | {PLDM_ENTITY_BATTERY, "Battery"}, |
| 181 | {PLDM_ENTITY_SUPER_CAPACITOR, "Super Capacitor"}, |
| 182 | {PLDM_ENTITY_POWER_CONVERTER, "Power Converter"}, |
| 183 | {PLDM_ENTITY_DC_DC_CONVERTER, "DC-DC Converter"}, |
| 184 | {PLDM_ENTITY_AC_MAINS_POWER_SUPPLY, "AC mains power supply"}, |
| 185 | {PLDM_ENTITY_DC_MAINS_POWER_SUPPLY, "DC mains power supply"}, |
| 186 | {PLDM_ENTITY_PROC, "Processor"}, |
| 187 | {PLDM_ENTITY_CHIPSET_COMPONENT, "Chipset Component"}, |
| 188 | {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"}, |
| 189 | {PLDM_ENTITY_PERIPHERAL_CONTROLLER, "Peripheral Controller"}, |
| 190 | {PLDM_ENTITY_SEEPROM, "SEEPROM"}, |
| 191 | {PLDM_ENTITY_NVRAM_CHIP, "NVRAM Chip"}, |
| 192 | {PLDM_ENTITY_FLASH_MEMORY_CHIP, "FLASH Memory chip"}, |
| 193 | {PLDM_ENTITY_MEMORY_CHIP, "Memory Chip"}, |
| 194 | {PLDM_ENTITY_MEMORY_CONTROLLER, "Memory Controller"}, |
| 195 | {PLDM_ENTITY_NETWORK_CONTROLLER, "Network Controller"}, |
| 196 | {PLDM_ENTITY_IO_CONTROLLER, "I/O Controller"}, |
| 197 | {PLDM_ENTITY_SOUTH_BRIDGE, "South Bridge"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 198 | {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 199 | {PLDM_ENTITY_FPGA_CPLD_DEVICE, "FPGA/CPLD Configurable Logic Device"}, |
| 200 | {PLDM_ENTITY_OTHER_BUS, "Other Bus"}, |
| 201 | {PLDM_ENTITY_SYS_BUS, "System Bus"}, |
| 202 | {PLDM_ENTITY_I2C_BUS, "I2C Bus"}, |
| 203 | {PLDM_ENTITY_SMBUS_BUS, "SMBus Bus"}, |
| 204 | {PLDM_ENTITY_SPI_BUS, "SPI Bus"}, |
| 205 | {PLDM_ENTITY_PCI_BUS, "PCI Bus"}, |
| 206 | {PLDM_ENTITY_PCI_EXPRESS_BUS, "PCI Express Bus"}, |
| 207 | {PLDM_ENTITY_PECI_BUS, "PECI Bus"}, |
| 208 | {PLDM_ENTITY_LPC_BUS, "LPC Bus"}, |
| 209 | {PLDM_ENTITY_USB_BUS, "USB Bus"}, |
| 210 | {PLDM_ENTITY_FIREWIRE_BUS, "FireWire Bus"}, |
| 211 | {PLDM_ENTITY_SCSI_BUS, "SCSI Bus"}, |
| 212 | {PLDM_ENTITY_SATA_SAS_BUS, "SATA/SAS Bus"}, |
| 213 | {PLDM_ENTITY_PROC_FRONT_SIDE_BUS, "Processor/Front-side Bus"}, |
| 214 | {PLDM_ENTITY_INTER_PROC_BUS, "Inter-processor Bus"}, |
| 215 | {PLDM_ENTITY_CONNECTOR, "Connector"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 216 | {PLDM_ENTITY_SLOT, "Slot"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 217 | {PLDM_ENTITY_CABLE, "Cable(electrical or optical)"}, |
| 218 | {PLDM_ENTITY_INTERCONNECT, "Interconnect"}, |
| 219 | {PLDM_ENTITY_PLUG, "Plug"}, |
| 220 | {PLDM_ENTITY_SOCKET, "Socket"}, |
| 221 | {PLDM_ENTITY_SYSTEM_LOGICAL, "System (Logical)"}}; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 222 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 223 | const std::map<uint16_t, std::string> stateSet = { |
| 224 | {PLDM_STATE_SET_HEALTH_STATE, "Health State"}, |
| 225 | {PLDM_STATE_SET_AVAILABILITY, "Availability"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 226 | {PLDM_STATE_SET_PREDICTIVE_CONDITION, "Predictive Condition"}, |
| 227 | {PLDM_STATE_SET_REDUNDANCY_STATUS, "Redundancy Status"}, |
| 228 | {PLDM_STATE_SET_HEALTH_REDUNDANCY_TREND, "Health/Redundancy Trend"}, |
| 229 | {PLDM_STATE_SET_GROUP_RESOURCE_LEVEL, "Group Resource Level"}, |
| 230 | {PLDM_STATE_SET_REDUNDANCY_ENTITY_ROLE, "Redundancy Entity Role"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 231 | {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 232 | {PLDM_STATE_SET_OPERATIONAL_STRESS_STATUS, "Operational Stress Status"}, |
| 233 | {PLDM_STATE_SET_OPERATIONAL_FAULT_STATUS, "Operational Fault Status"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 234 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 235 | "Operational Running Status"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 236 | {PLDM_STATE_SET_OPERATIONAL_CONNECTION_STATUS, |
| 237 | "Operational Connection Status"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 238 | {PLDM_STATE_SET_PRESENCE, "Presence"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 239 | {PLDM_STATE_SET_PERFORMANCE, "Performance"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 240 | {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 241 | {PLDM_STATE_SET_CHANGED_CONFIGURATION, "Changed Configuration"}, |
| 242 | {PLDM_STATE_SET_IDENTIFY_STATE, "Identify State"}, |
| 243 | {PLDM_STATE_SET_VERSION, "Version"}, |
| 244 | {PLDM_STATE_SET_ALARM_STATE, "Alarm State"}, |
| 245 | {PLDM_STATE_SET_DEVICE_INITIALIZATION, "Device Initialization"}, |
| 246 | {PLDM_STATE_SET_THERMAL_TRIP, "Thermal Trip"}, |
| 247 | {PLDM_STATE_SET_HEARTBEAT, "Heartbeat"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 248 | {PLDM_STATE_SET_LINK_STATE, "Link State"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 249 | {PLDM_STATE_SET_SMOKE_STATE, "Smoke State"}, |
| 250 | {PLDM_STATE_SET_HUMIDITY_STATE, "Humidity State"}, |
| 251 | {PLDM_STATE_SET_DOOR_STATE, "Door State"}, |
| 252 | {PLDM_STATE_SET_SWITCH_STATE, "Switch State"}, |
| 253 | {PLDM_STATE_SET_LOCK_STATE, "Lock State"}, |
| 254 | {PLDM_STATE_SET_PHYSICAL_SECURITY, "Physical Security"}, |
| 255 | {PLDM_STATE_SET_DOCK_AUTHORIZATION, "Dock Authorization"}, |
| 256 | {PLDM_STATE_SET_HW_SECURITY, "Hardware Security"}, |
| 257 | {PLDM_STATE_SET_PHYSICAL_COMM_CONNECTION, |
| 258 | "Physical Communication Connection"}, |
| 259 | {PLDM_STATE_SET_COMM_LEASH_STATUS, "Communication Leash Status"}, |
| 260 | {PLDM_STATE_SET_FOREIGN_NW_DETECTION_STATUS, |
| 261 | "Foreign Network Detection Status"}, |
| 262 | {PLDM_STATE_SET_PASSWORD_PROTECTED_ACCESS_SECURITY, |
| 263 | "Password-Protected Access Security"}, |
| 264 | {PLDM_STATE_SET_SECURITY_ACCESS_PRIVILEGE_LEVEL, |
| 265 | "Security Access –PrivilegeLevel"}, |
| 266 | {PLDM_STATE_SET_SESSION_AUDIT, "PLDM Session Audit"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 267 | {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 268 | {PLDM_STATE_SET_STORAGE_MEDIA_ACTIVITY, "Storage Media Activity"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 269 | {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 270 | {PLDM_STATE_SET_BOOT_RESTART_REQUEST, "Boot/Restart Request"}, |
| 271 | {PLDM_STATE_SET_ENTITY_BOOT_STATUS, "Entity Boot Status"}, |
| 272 | {PLDM_STATE_SET_BOOT_ERROR_STATUS, "Boot ErrorStatus"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 273 | {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"}, |
Manojkiran Eda | afbdb6d | 2021-05-27 17:19:51 +0530 | [diff] [blame] | 274 | {PLDM_STATE_SET_SYS_FIRMWARE_HANG, "System Firmware Hang"}, |
| 275 | {PLDM_STATE_SET_POST_ERRORS, "POST Errors"}, |
| 276 | {PLDM_STATE_SET_LOG_FILL_STATUS, "Log Fill Status"}, |
| 277 | {PLDM_STATE_SET_LOG_FILTER_STATUS, "Log Filter Status"}, |
| 278 | {PLDM_STATE_SET_LOG_TIMESTAMP_CHANGE, "Log Timestamp Change"}, |
| 279 | {PLDM_STATE_SET_INTERRUPT_REQUESTED, "Interrupt Requested"}, |
| 280 | {PLDM_STATE_SET_INTERRUPT_RECEIVED, "Interrupt Received"}, |
| 281 | {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_REQUESTED, |
| 282 | "Diagnostic Interrupt Requested"}, |
| 283 | {PLDM_STATE_SET_DIAGNOSTIC_INTERRUPT_RECEIVED, |
| 284 | "Diagnostic Interrupt Received"}, |
| 285 | {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_REQUESTED, |
| 286 | "I/O Channel Check NMI Requested"}, |
| 287 | {PLDM_STATE_SET_IO_CHANNEL_CHECK_NMI_RECEIVED, |
| 288 | "I/O Channel Check NMI Received"}, |
| 289 | {PLDM_STATE_SET_FATAL_NMI_REQUESTED, "Fatal NMI Requested"}, |
| 290 | {PLDM_STATE_SET_FATAL_NMI_RECEIVED, "Fatal NMI Received"}, |
| 291 | {PLDM_STATE_SET_SOFTWARE_NMI_REQUESTED, "Software NMI Requested"}, |
| 292 | {PLDM_STATE_SET_SOFTWARE_NMI_RECEIVED, "Software NMI Received"}, |
| 293 | {PLDM_STATE_SET_SMI_REQUESTED, "SMI Requested"}, |
| 294 | {PLDM_STATE_SET_SMI_RECEIVED, "SMI Received"}, |
| 295 | {PLDM_STATE_SET_PCI_PERR_REQUESTED, "PCI PERR Requested"}, |
| 296 | {PLDM_STATE_SET_PCI_PERR_RECEIVED, "PCI PERR Received"}, |
| 297 | {PLDM_STATE_SET_PCI_SERR_REQUESTED, "PCI SERR Requested "}, |
| 298 | {PLDM_STATE_SET_PCI_SERR_RECEIVED, "PCI SERR Received"}, |
| 299 | {PLDM_STATE_SET_BUS_ERROR_STATUS, "Bus Error Status"}, |
| 300 | {PLDM_STATE_SET_WATCHDOG_STATUS, "Watchdog Status"}, |
| 301 | {PLDM_STATE_SET_POWER_SUPPLY_STATE, "Power Supply State"}, |
| 302 | {PLDM_STATE_SET_DEVICE_POWER_STATE, "Device Power State"}, |
| 303 | {PLDM_STATE_SET_ACPI_POWER_STATE, "ACPI Power State"}, |
| 304 | {PLDM_STATE_SET_BACKUP_POWER_SOURCE, "Backup Power Source"}, |
| 305 | {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State "}, |
| 306 | {PLDM_STATE_SET_BATTERY_ACTIVITY, "Battery Activity"}, |
| 307 | {PLDM_STATE_SET_BATTERY_STATE, "Battery State"}, |
| 308 | {PLDM_STATE_SET_PROC_POWER_STATE, "Processor Power State"}, |
| 309 | {PLDM_STATE_SET_POWER_PERFORMANCE_STATE, "Power-Performance State"}, |
| 310 | {PLDM_STATE_SET_PROC_ERROR_STATUS, "Processor Error Status"}, |
| 311 | {PLDM_STATE_SET_BIST_FAILURE_STATUS, "BIST FailureStatus"}, |
| 312 | {PLDM_STATE_SET_IBIST_FAILURE_STATUS, "IBIST FailureStatus"}, |
| 313 | {PLDM_STATE_SET_PROC_HANG_IN_POST, "Processor Hang in POST"}, |
| 314 | {PLDM_STATE_SET_PROC_STARTUP_FAILURE, "Processor Startup Failure"}, |
| 315 | {PLDM_STATE_SET_UNCORRECTABLE_CPU_ERROR, "Uncorrectable CPU Error"}, |
| 316 | {PLDM_STATE_SET_MACHINE_CHECK_ERROR, "Machine Check Error"}, |
| 317 | {PLDM_STATE_SET_CORRECTED_MACHINE_CHECK, "Corrected Machine Check"}, |
| 318 | {PLDM_STATE_SET_CACHE_STATUS, "Cache Status"}, |
| 319 | {PLDM_STATE_SET_MEMORY_ERROR_STATUS, "Memory Error Status"}, |
| 320 | {PLDM_STATE_SET_REDUNDANT_MEMORY_ACTIVITY_STATUS, |
| 321 | "Redundant Memory Activity Status"}, |
| 322 | {PLDM_STATE_SET_ERROR_DETECTION_STATUS, "Error Detection Status"}, |
| 323 | {PLDM_STATE_SET_STUCK_BIT_STATUS, "Stuck Bit Status"}, |
| 324 | {PLDM_STATE_SET_SCRUB_STATUS, "Scrub Status"}, |
| 325 | {PLDM_STATE_SET_SLOT_OCCUPANCY, "Slot Occupancy"}, |
| 326 | {PLDM_STATE_SET_SLOT_STATE, "Slot State"}}; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 327 | |
| 328 | const std::array<std::string_view, 4> sensorInit = { |
| 329 | "noInit", "useInitPDR", "enableSensor", "disableSensor"}; |
| 330 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 331 | const std::array<std::string_view, 4> effecterInit = { |
| 332 | "noInit", "useInitPDR", "enableEffecter", "disableEffecter"}; |
| 333 | |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 334 | const std::map<uint8_t, std::string> pdrType = { |
| 335 | {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"}, |
| 336 | {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"}, |
| 337 | {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR, |
| 338 | "Numeric Sensor Initialization PDR"}, |
| 339 | {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"}, |
| 340 | {PLDM_STATE_SENSOR_INITIALIZATION_PDR, |
| 341 | "State Sensor Initialization PDR"}, |
| 342 | {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"}, |
| 343 | {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"}, |
| 344 | {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"}, |
| 345 | {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"}, |
| 346 | {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR, |
| 347 | "Numeric Effecter Initialization PDR"}, |
| 348 | {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"}, |
| 349 | {PLDM_STATE_EFFECTER_INITIALIZATION_PDR, |
| 350 | "State Effecter Initialization PDR"}, |
| 351 | {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"}, |
| 352 | {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"}, |
| 353 | {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"}, |
| 354 | {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"}, |
| 355 | {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"}, |
| 356 | {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"}, |
| 357 | {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"}, |
| 358 | {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"}, |
| 359 | {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"}, |
| 360 | {PLDM_OEM_PDR, "OEM PDR"}, |
| 361 | }; |
| 362 | |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame^] | 363 | bool isLogicalBitSet(const uint16_t entity_type) |
| 364 | { |
| 365 | return entity_type & 0x8000; |
| 366 | } |
| 367 | |
| 368 | uint16_t getEntityTypeForLogicalEntity(const uint16_t logical_entity_type) |
| 369 | { |
| 370 | return logical_entity_type & 0x7FFF; |
| 371 | } |
| 372 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 373 | std::string getEntityName(pldm::pdr::EntityType type) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 374 | { |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame^] | 375 | uint16_t entityNumber = type; |
| 376 | std::string entityName = "[Physical] "; |
| 377 | |
| 378 | if (isLogicalBitSet(type)) |
| 379 | { |
| 380 | entityName = "[Logical] "; |
| 381 | entityNumber = getEntityTypeForLogicalEntity(type); |
| 382 | } |
| 383 | |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 384 | try |
| 385 | { |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame^] | 386 | return entityName + entityType.at(entityNumber); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 387 | } |
| 388 | catch (const std::out_of_range& e) |
| 389 | { |
Manojkiran Eda | 0c5d1ec | 2021-05-29 11:21:25 +0530 | [diff] [blame^] | 390 | if (type >= PLDM_OEM_ENTITY_TYPE_START && |
| 391 | type <= PLDM_OEM_ENTITY_TYPE_END) |
| 392 | { |
| 393 | |
| 394 | return entityName + |
| 395 | std::to_string(static_cast<unsigned>(entityNumber)) + |
| 396 | "(OEM)"; |
| 397 | } |
| 398 | |
| 399 | return std::to_string(static_cast<unsigned>(entityNumber)); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 403 | std::string getStateSetName(uint16_t id) |
| 404 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 405 | auto typeString = std::to_string(id); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 406 | try |
| 407 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 408 | return stateSet.at(id) + "(" + typeString + ")"; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 409 | } |
| 410 | catch (const std::out_of_range& e) |
| 411 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 412 | return typeString; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | std::string getPDRType(uint8_t type) |
| 417 | { |
| 418 | auto typeString = std::to_string(type); |
| 419 | try |
| 420 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 421 | return pdrType.at(type); |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 422 | } |
| 423 | catch (const std::out_of_range& e) |
| 424 | { |
| 425 | return typeString; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 429 | void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output) |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 430 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 431 | output["recordHandle"] = hdr->record_handle; |
| 432 | output["PDRHeaderVersion"] = unsigned(hdr->version); |
| 433 | output["PDRType"] = getPDRType(hdr->type); |
| 434 | output["recordChangeNumber"] = hdr->record_change_num; |
| 435 | output["dataLength"] = hdr->length; |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 438 | std::string printPossibleStates(uint8_t possibleStatesSize, |
| 439 | const bitfield8_t* states) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 440 | { |
| 441 | uint8_t possibleStatesPos{}; |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 442 | std::string data; |
| 443 | auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) { |
| 444 | std::stringstream pstates; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 445 | for (int i = 0; i < CHAR_BIT; i++) |
| 446 | { |
| 447 | if (val.byte & (1 << i)) |
| 448 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 449 | pstates << " " << (possibleStatesPos * CHAR_BIT + i); |
| 450 | data.append(pstates.str()); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 451 | pstates.str(""); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | possibleStatesPos++; |
| 455 | }; |
| 456 | std::for_each(states, states + possibleStatesSize, printStates); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 457 | return data; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 458 | } |
| 459 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 460 | void printStateSensorPDR(const uint8_t* data, ordered_json& output) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 461 | { |
| 462 | auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 463 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 464 | output["sensorID"] = pdr->sensor_id; |
| 465 | output["entityType"] = getEntityName(pdr->entity_type); |
| 466 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 467 | output["containerID"] = pdr->container_id; |
| 468 | output["sensorInit"] = sensorInit[pdr->sensor_init]; |
| 469 | output["sensorAuxiliaryNamesPDR"] = |
| 470 | (pdr->sensor_auxiliary_names_pdr ? true : false); |
| 471 | output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 472 | |
| 473 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 474 | auto compCount = pdr->composite_sensor_count; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 475 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 476 | while (compCount--) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 477 | { |
| 478 | auto state = reinterpret_cast<const state_sensor_possible_states*>( |
| 479 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 480 | output.emplace(("stateSetID[" + std::to_string(compCount) + "]"), |
| 481 | getStateSetName(state->state_set_id)); |
| 482 | output.emplace( |
| 483 | ("possibleStatesSize[" + std::to_string(compCount) + "]"), |
| 484 | state->possible_states_size); |
| 485 | output.emplace( |
| 486 | ("possibleStates[" + std::to_string(compCount) + "]"), |
| 487 | printPossibleStates(state->possible_states_size, |
| 488 | state->states)); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 489 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 490 | if (compCount) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 491 | { |
| 492 | statesPtr += sizeof(state_sensor_possible_states) + |
| 493 | state->possible_states_size - 1; |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 498 | void printPDRFruRecordSet(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 499 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 500 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 501 | { |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | data += sizeof(pldm_pdr_hdr); |
| 506 | pldm_pdr_fru_record_set* pdr = |
| 507 | reinterpret_cast<pldm_pdr_fru_record_set*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 508 | if (!pdr) |
| 509 | { |
| 510 | std::cerr << "Failed to get the FRU record set PDR" << std::endl; |
| 511 | return; |
| 512 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 513 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 514 | output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle); |
| 515 | output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi); |
| 516 | output["entityType"] = getEntityName(pdr->entity_type); |
| 517 | output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num); |
| 518 | output["containerID"] = unsigned(pdr->container_id); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 519 | } |
| 520 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 521 | void printPDREntityAssociation(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 522 | { |
| 523 | const std::map<uint8_t, const char*> assocationType = { |
| 524 | {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"}, |
| 525 | {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"}, |
| 526 | }; |
| 527 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 528 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 529 | { |
| 530 | return; |
| 531 | } |
| 532 | |
| 533 | data += sizeof(pldm_pdr_hdr); |
| 534 | pldm_pdr_entity_association* pdr = |
| 535 | reinterpret_cast<pldm_pdr_entity_association*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 536 | if (!pdr) |
| 537 | { |
| 538 | std::cerr << "Failed to get the PDR eneity association" |
| 539 | << std::endl; |
| 540 | return; |
| 541 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 542 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 543 | output["containerID"] = int(pdr->container_id); |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 544 | if (assocationType.contains(pdr->association_type)) |
| 545 | { |
| 546 | output["associationType"] = |
| 547 | assocationType.at(pdr->association_type); |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | std::cout << "Get associationType failed.\n"; |
| 552 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 553 | output["containerEntityType"] = |
| 554 | getEntityName(pdr->container.entity_type); |
| 555 | output["containerEntityInstanceNumber"] = |
| 556 | int(pdr->container.entity_instance_num); |
| 557 | output["containerEntityContainerID"] = |
| 558 | int(pdr->container.entity_container_id); |
| 559 | output["containedEntityCount"] = |
| 560 | static_cast<unsigned>(pdr->num_children); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 561 | |
| 562 | auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]); |
| 563 | for (int i = 0; i < pdr->num_children; ++i) |
| 564 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 565 | output.emplace("containedEntityType[" + std::to_string(i + 1) + "]", |
| 566 | getEntityName(child->entity_type)); |
| 567 | output.emplace("containedEntityInstanceNumber[" + |
| 568 | std::to_string(i + 1) + "]", |
| 569 | unsigned(child->entity_instance_num)); |
| 570 | output.emplace("containedEntityContainerID[" + |
| 571 | std::to_string(i + 1) + "]", |
| 572 | unsigned(child->entity_container_id)); |
| 573 | |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 574 | ++child; |
| 575 | } |
| 576 | } |
| 577 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 578 | void printNumericEffecterPDR(uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 579 | { |
| 580 | struct pldm_numeric_effecter_value_pdr* pdr = |
| 581 | (struct pldm_numeric_effecter_value_pdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 582 | if (!pdr) |
| 583 | { |
| 584 | std::cerr << "Failed to get numeric effecter PDR" << std::endl; |
| 585 | return; |
| 586 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 587 | |
| 588 | output["PLDMTerminusHandle"] = int(pdr->terminus_handle); |
| 589 | output["effecterID"] = int(pdr->effecter_id); |
| 590 | output["entityType"] = int(pdr->entity_type); |
| 591 | output["entityInstanceNumber"] = int(pdr->entity_instance); |
| 592 | output["containerID"] = int(pdr->container_id); |
| 593 | output["effecterSemanticID"] = int(pdr->effecter_semantic_id); |
| 594 | output["effecterInit"] = unsigned(pdr->effecter_init); |
| 595 | output["effecterAuxiliaryNames"] = |
| 596 | (unsigned(pdr->effecter_auxiliary_names) ? true : false); |
| 597 | output["baseUnit"] = unsigned(pdr->base_unit); |
| 598 | output["unitModifier"] = unsigned(pdr->unit_modifier); |
| 599 | output["rateUnit"] = unsigned(pdr->rate_unit); |
| 600 | output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle); |
| 601 | output["auxUnit"] = unsigned(pdr->aux_unit); |
| 602 | output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier); |
| 603 | output["auxrateUnit"] = unsigned(pdr->aux_rate_unit); |
| 604 | output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle); |
| 605 | output["isLinear"] = (unsigned(pdr->is_linear) ? true : false); |
| 606 | output["effecterDataSize"] = unsigned(pdr->effecter_data_size); |
| 607 | output["resolution"] = unsigned(pdr->resolution); |
| 608 | output["offset"] = unsigned(pdr->offset); |
| 609 | output["accuracy"] = unsigned(pdr->accuracy); |
| 610 | output["plusTolerance"] = unsigned(pdr->plus_tolerance); |
| 611 | output["minusTolerance"] = unsigned(pdr->minus_tolerance); |
| 612 | output["stateTransitionInterval"] = |
| 613 | unsigned(pdr->state_transition_interval); |
| 614 | output["TransitionInterval"] = unsigned(pdr->transition_interval); |
| 615 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 616 | switch (pdr->effecter_data_size) |
| 617 | { |
| 618 | case PLDM_EFFECTER_DATA_SIZE_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 619 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u8); |
| 620 | output["minSettable"] = unsigned(pdr->min_set_table.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 621 | break; |
| 622 | case PLDM_EFFECTER_DATA_SIZE_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 623 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s8); |
| 624 | output["minSettable"] = unsigned(pdr->min_set_table.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 625 | break; |
| 626 | case PLDM_EFFECTER_DATA_SIZE_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 627 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u16); |
| 628 | output["minSettable"] = unsigned(pdr->min_set_table.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 629 | break; |
| 630 | case PLDM_EFFECTER_DATA_SIZE_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 631 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s16); |
| 632 | output["minSettable"] = unsigned(pdr->min_set_table.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 633 | break; |
| 634 | case PLDM_EFFECTER_DATA_SIZE_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 635 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u32); |
| 636 | output["minSettable"] = unsigned(pdr->min_set_table.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 637 | break; |
| 638 | case PLDM_EFFECTER_DATA_SIZE_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 639 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s32); |
| 640 | output["minSettable"] = unsigned(pdr->min_set_table.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 641 | break; |
| 642 | default: |
| 643 | break; |
| 644 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 645 | |
| 646 | output["rangeFieldFormat"] = unsigned(pdr->range_field_format); |
| 647 | output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte); |
| 648 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 649 | switch (pdr->range_field_format) |
| 650 | { |
| 651 | case PLDM_RANGE_FIELD_FORMAT_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 652 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u8); |
| 653 | output["normalMax"] = unsigned(pdr->normal_max.value_u8); |
| 654 | output["normalMin"] = unsigned(pdr->normal_min.value_u8); |
| 655 | output["ratedMax"] = unsigned(pdr->rated_max.value_u8); |
| 656 | output["ratedMin"] = unsigned(pdr->rated_min.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 657 | break; |
| 658 | case PLDM_RANGE_FIELD_FORMAT_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 659 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s8); |
| 660 | output["normalMax"] = unsigned(pdr->normal_max.value_s8); |
| 661 | output["normalMin"] = unsigned(pdr->normal_min.value_s8); |
| 662 | output["ratedMax"] = unsigned(pdr->rated_max.value_s8); |
| 663 | output["ratedMin"] = unsigned(pdr->rated_min.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 664 | break; |
| 665 | case PLDM_RANGE_FIELD_FORMAT_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 666 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u16); |
| 667 | output["normalMax"] = unsigned(pdr->normal_max.value_u16); |
| 668 | output["normalMin"] = unsigned(pdr->normal_min.value_u16); |
| 669 | output["ratedMax"] = unsigned(pdr->rated_max.value_u16); |
| 670 | output["ratedMin"] = unsigned(pdr->rated_min.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 671 | break; |
| 672 | case PLDM_RANGE_FIELD_FORMAT_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 673 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s16); |
| 674 | output["normalMax"] = unsigned(pdr->normal_max.value_s16); |
| 675 | output["normalMin"] = unsigned(pdr->normal_min.value_s16); |
| 676 | output["ratedMax"] = unsigned(pdr->rated_max.value_s16); |
| 677 | output["ratedMin"] = unsigned(pdr->rated_min.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 678 | break; |
| 679 | case PLDM_RANGE_FIELD_FORMAT_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 680 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u32); |
| 681 | output["normalMax"] = unsigned(pdr->normal_max.value_u32); |
| 682 | output["normalMin"] = unsigned(pdr->normal_min.value_u32); |
| 683 | output["ratedMax"] = unsigned(pdr->rated_max.value_u32); |
| 684 | output["ratedMin"] = unsigned(pdr->rated_min.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 685 | break; |
| 686 | case PLDM_RANGE_FIELD_FORMAT_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 687 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s32); |
| 688 | output["normalMax"] = unsigned(pdr->normal_max.value_s32); |
| 689 | output["normalMin"] = unsigned(pdr->normal_min.value_s32); |
| 690 | output["ratedMax"] = unsigned(pdr->rated_max.value_s32); |
| 691 | output["ratedMin"] = unsigned(pdr->rated_min.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 692 | break; |
| 693 | case PLDM_RANGE_FIELD_FORMAT_REAL32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 694 | output["nominalValue"] = unsigned(pdr->nominal_value.value_f32); |
| 695 | output["normalMax"] = unsigned(pdr->normal_max.value_f32); |
| 696 | output["normalMin"] = unsigned(pdr->normal_min.value_f32); |
| 697 | output["ratedMax"] = unsigned(pdr->rated_max.value_f32); |
| 698 | output["ratedMin"] = unsigned(pdr->rated_min.value_f32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 699 | break; |
| 700 | default: |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 705 | void printStateEffecterPDR(const uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 706 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 707 | auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 708 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 709 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 710 | output["effecterID"] = pdr->effecter_id; |
| 711 | output["entityType"] = getEntityName(pdr->entity_type); |
| 712 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 713 | output["containerID"] = pdr->container_id; |
| 714 | output["effecterSemanticID"] = pdr->effecter_semantic_id; |
| 715 | output["effecterInit"] = effecterInit[pdr->effecter_init]; |
| 716 | output["effecterDescriptionPDR"] = |
| 717 | (pdr->has_description_pdr ? true : false); |
| 718 | output["compositeEffecterCount"] = |
| 719 | unsigned(pdr->composite_effecter_count); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 720 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 721 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 722 | auto compEffCount = pdr->composite_effecter_count; |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 723 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 724 | while (compEffCount--) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 725 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 726 | auto state = |
| 727 | reinterpret_cast<const state_effecter_possible_states*>( |
| 728 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 729 | output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"), |
| 730 | getStateSetName(state->state_set_id)); |
| 731 | output.emplace( |
| 732 | ("possibleStatesSize[" + std::to_string(compEffCount) + "]"), |
| 733 | state->possible_states_size); |
| 734 | output.emplace( |
| 735 | ("possibleStates[" + std::to_string(compEffCount) + "]"), |
| 736 | printPossibleStates(state->possible_states_size, |
| 737 | state->states)); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 738 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 739 | if (compEffCount) |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 740 | { |
| 741 | statesPtr += sizeof(state_effecter_possible_states) + |
| 742 | state->possible_states_size - 1; |
| 743 | } |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 747 | void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output) |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 748 | { |
| 749 | const std::array<std::string_view, 4> terminusLocatorType = { |
| 750 | "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"}; |
| 751 | |
| 752 | auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data); |
| 753 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 754 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 755 | output["validity"] = (pdr->validity ? "valid" : "notValid"); |
| 756 | output["TID"] = unsigned(pdr->tid); |
| 757 | output["containerID"] = pdr->container_id; |
| 758 | output["terminusLocatorType"] = |
| 759 | terminusLocatorType[pdr->terminus_locator_type]; |
| 760 | output["terminusLocatorValueSize"] = |
| 761 | unsigned(pdr->terminus_locator_value_size); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 762 | |
| 763 | if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID) |
| 764 | { |
| 765 | auto locatorValue = |
| 766 | reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>( |
| 767 | pdr->terminus_locator_value); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 768 | output["EID"] = unsigned(locatorValue->eid); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 772 | void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt, |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 773 | uint8_t* data) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 774 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 775 | if (data == NULL) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 776 | { |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 777 | std::cerr << "Failed to get PDR message" << std::endl; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 778 | return; |
| 779 | } |
| 780 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 781 | ordered_json output; |
| 782 | output["nextRecordHandle"] = nextRecordHndl; |
| 783 | output["responseCount"] = respCnt; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 784 | |
| 785 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 786 | if (!pdr) |
| 787 | { |
| 788 | return; |
| 789 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 790 | printCommonPDRHeader(pdr, output); |
| 791 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 792 | switch (pdr->type) |
| 793 | { |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 794 | case PLDM_TERMINUS_LOCATOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 795 | printTerminusLocatorPDR(data, output); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 796 | break; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 797 | case PLDM_STATE_SENSOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 798 | printStateSensorPDR(data, output); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 799 | break; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 800 | case PLDM_NUMERIC_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 801 | printNumericEffecterPDR(data, output); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 802 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 803 | case PLDM_STATE_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 804 | printStateEffecterPDR(data, output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 805 | break; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 806 | case PLDM_PDR_ENTITY_ASSOCIATION: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 807 | printPDREntityAssociation(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 808 | break; |
| 809 | case PLDM_PDR_FRU_RECORD_SET: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 810 | printPDRFruRecordSet(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 811 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 812 | default: |
| 813 | break; |
| 814 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 815 | pldmtool::helper::DisplayInJson(output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | private: |
| 819 | uint32_t recordHandle; |
| 820 | }; |
| 821 | |
| 822 | class SetStateEffecter : public CommandInterface |
| 823 | { |
| 824 | public: |
| 825 | ~SetStateEffecter() = default; |
| 826 | SetStateEffecter() = delete; |
| 827 | SetStateEffecter(const SetStateEffecter&) = delete; |
| 828 | SetStateEffecter(SetStateEffecter&&) = default; |
| 829 | SetStateEffecter& operator=(const SetStateEffecter&) = delete; |
| 830 | SetStateEffecter& operator=(SetStateEffecter&&) = default; |
| 831 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 832 | // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2) |
| 833 | static constexpr auto maxEffecterDataSize = 16; |
| 834 | |
| 835 | // compositeEffecterCount(value: 0x01 to 0x08) |
| 836 | static constexpr auto minEffecterCount = 1; |
| 837 | static constexpr auto maxEffecterCount = 8; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 838 | explicit SetStateEffecter(const char* type, const char* name, |
| 839 | CLI::App* app) : |
| 840 | CommandInterface(type, name, app) |
| 841 | { |
| 842 | app->add_option( |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 843 | "-i, --id", effecterId, |
| 844 | "A handle that is used to identify and access the effecter") |
| 845 | ->required(); |
| 846 | app->add_option("-c, --count", effecterCount, |
| 847 | "The number of individual sets of effecter information") |
| 848 | ->required(); |
| 849 | app->add_option( |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 850 | "-d,--data", effecterData, |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 851 | "Set effecter state data\n" |
| 852 | "eg: requestSet0 effecterState0 noChange1 dummyState1 ...") |
| 853 | ->required(); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 857 | { |
| 858 | std::vector<uint8_t> requestMsg( |
| 859 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES); |
| 860 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 861 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 862 | if (effecterCount > maxEffecterCount || |
| 863 | effecterCount < minEffecterCount) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 864 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 865 | std::cerr << "Request Message Error: effecterCount size " |
| 866 | << effecterCount << "is invalid\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 867 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 868 | return {rc, requestMsg}; |
| 869 | } |
| 870 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 871 | if (effecterData.size() > maxEffecterDataSize) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 872 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 873 | std::cerr << "Request Message Error: effecterData size " |
| 874 | << effecterData.size() << "is invalid\n"; |
| 875 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 876 | return {rc, requestMsg}; |
| 877 | } |
| 878 | |
| 879 | auto stateField = parseEffecterData(effecterData, effecterCount); |
| 880 | if (!stateField) |
| 881 | { |
| 882 | std::cerr << "Failed to parse effecter data, effecterCount size " |
| 883 | << effecterCount << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 884 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 885 | return {rc, requestMsg}; |
| 886 | } |
| 887 | |
| 888 | auto rc = encode_set_state_effecter_states_req( |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 889 | instanceId, effecterId, effecterCount, stateField->data(), request); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 890 | return {rc, requestMsg}; |
| 891 | } |
| 892 | |
| 893 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 894 | { |
| 895 | uint8_t completionCode = 0; |
| 896 | auto rc = decode_set_state_effecter_states_resp( |
| 897 | responsePtr, payloadLength, &completionCode); |
| 898 | |
| 899 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 900 | { |
| 901 | std::cerr << "Response Message Error: " |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 902 | << "rc=" << rc << ",cc=" << (int)completionCode << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 903 | return; |
| 904 | } |
| 905 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 906 | ordered_json data; |
| 907 | data["Response"] = "SUCCESS"; |
| 908 | pldmtool::helper::DisplayInJson(data); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | private: |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 912 | uint16_t effecterId; |
| 913 | uint8_t effecterCount; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 914 | std::vector<uint8_t> effecterData; |
| 915 | }; |
| 916 | |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 917 | class SetNumericEffecterValue : public CommandInterface |
| 918 | { |
| 919 | public: |
| 920 | ~SetNumericEffecterValue() = default; |
| 921 | SetNumericEffecterValue() = delete; |
| 922 | SetNumericEffecterValue(const SetNumericEffecterValue&) = delete; |
| 923 | SetNumericEffecterValue(SetNumericEffecterValue&&) = default; |
| 924 | SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete; |
| 925 | SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default; |
| 926 | |
| 927 | explicit SetNumericEffecterValue(const char* type, const char* name, |
| 928 | CLI::App* app) : |
| 929 | CommandInterface(type, name, app) |
| 930 | { |
| 931 | app->add_option( |
| 932 | "-i, --id", effecterId, |
| 933 | "A handle that is used to identify and access the effecter") |
| 934 | ->required(); |
| 935 | app->add_option("-s, --size", effecterDataSize, |
| 936 | "The bit width and format of the setting value for the " |
| 937 | "effecter. enum value: {uint8, sint8, uint16, sint16, " |
| 938 | "uint32, sint32}\n") |
| 939 | ->required(); |
| 940 | app->add_option("-d,--data", maxEffecterValue, |
| 941 | "The setting value of numeric effecter being " |
| 942 | "requested\n") |
| 943 | ->required(); |
| 944 | } |
| 945 | |
| 946 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 947 | { |
| 948 | std::vector<uint8_t> requestMsg( |
| 949 | sizeof(pldm_msg_hdr) + |
| 950 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3); |
| 951 | |
| 952 | uint8_t* effecterValue = (uint8_t*)&maxEffecterValue; |
| 953 | |
| 954 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 955 | size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES; |
| 956 | |
| 957 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 958 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16) |
| 959 | { |
| 960 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1; |
| 961 | } |
| 962 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 963 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32) |
| 964 | { |
| 965 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3; |
| 966 | } |
| 967 | auto rc = encode_set_numeric_effecter_value_req( |
| 968 | 0, effecterId, effecterDataSize, effecterValue, request, |
| 969 | payload_length); |
| 970 | |
| 971 | return {rc, requestMsg}; |
| 972 | } |
| 973 | |
| 974 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 975 | { |
| 976 | uint8_t completionCode = 0; |
| 977 | auto rc = decode_set_numeric_effecter_value_resp( |
| 978 | responsePtr, payloadLength, &completionCode); |
| 979 | |
| 980 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 981 | { |
| 982 | std::cerr << "Response Message Error: " |
| 983 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 984 | << std::endl; |
| 985 | return; |
| 986 | } |
| 987 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 988 | ordered_json data; |
| 989 | data["Response"] = "SUCCESS"; |
| 990 | pldmtool::helper::DisplayInJson(data); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | private: |
| 994 | uint16_t effecterId; |
| 995 | uint8_t effecterDataSize; |
| 996 | uint64_t maxEffecterValue; |
| 997 | }; |
| 998 | |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 999 | class GetStateSensorReadings : public CommandInterface |
| 1000 | { |
| 1001 | public: |
| 1002 | ~GetStateSensorReadings() = default; |
| 1003 | GetStateSensorReadings() = delete; |
| 1004 | GetStateSensorReadings(const GetStateSensorReadings&) = delete; |
| 1005 | GetStateSensorReadings(GetStateSensorReadings&&) = default; |
| 1006 | GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete; |
| 1007 | GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default; |
| 1008 | |
| 1009 | explicit GetStateSensorReadings(const char* type, const char* name, |
| 1010 | CLI::App* app) : |
| 1011 | CommandInterface(type, name, app) |
| 1012 | { |
| 1013 | app->add_option( |
| 1014 | "-i, --sensor_id", sensorId, |
| 1015 | "Sensor ID that is used to identify and access the sensor") |
| 1016 | ->required(); |
| 1017 | app->add_option("-r, --rearm", sensorRearm, |
| 1018 | "Each bit location in this field corresponds to a " |
| 1019 | "particular sensor") |
| 1020 | ->required(); |
| 1021 | } |
| 1022 | |
| 1023 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 1024 | { |
| 1025 | std::vector<uint8_t> requestMsg( |
| 1026 | sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES); |
| 1027 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1028 | |
| 1029 | uint8_t reserved = 0; |
| 1030 | bitfield8_t bf; |
| 1031 | bf.byte = sensorRearm; |
| 1032 | auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf, |
| 1033 | reserved, request); |
| 1034 | |
| 1035 | return {rc, requestMsg}; |
| 1036 | } |
| 1037 | |
| 1038 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 1039 | { |
| 1040 | uint8_t completionCode = 0; |
| 1041 | uint8_t compSensorCount = 0; |
| 1042 | std::array<get_sensor_state_field, 8> stateField{}; |
| 1043 | auto rc = decode_get_state_sensor_readings_resp( |
| 1044 | responsePtr, payloadLength, &completionCode, &compSensorCount, |
| 1045 | stateField.data()); |
| 1046 | |
| 1047 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 1048 | { |
| 1049 | std::cerr << "Response Message Error: " |
| 1050 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 1051 | << std::endl; |
| 1052 | return; |
| 1053 | } |
| 1054 | ordered_json output; |
| 1055 | output["compositeSensorCount"] = (int)compSensorCount; |
| 1056 | |
| 1057 | for (size_t i = 0; i < compSensorCount; i++) |
| 1058 | { |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 1059 | if (sensorOpState.contains(stateField[i].sensor_op_state)) |
| 1060 | { |
| 1061 | output.emplace(("sensorOpState[" + std::to_string(i) + "]"), |
| 1062 | sensorOpState.at(stateField[i].sensor_op_state)); |
| 1063 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1064 | |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 1065 | if (sensorPresState.contains(stateField[i].present_state)) |
| 1066 | { |
| 1067 | output.emplace(("presentState[" + std::to_string(i) + "]"), |
| 1068 | sensorPresState.at(stateField[i].present_state)); |
| 1069 | } |
| 1070 | |
| 1071 | if (sensorPresState.contains(stateField[i].previous_state)) |
| 1072 | { |
| 1073 | output.emplace( |
| 1074 | ("previousState[" + std::to_string(i) + "]"), |
| 1075 | sensorPresState.at(stateField[i].previous_state)); |
| 1076 | } |
| 1077 | |
| 1078 | if (sensorPresState.contains(stateField[i].event_state)) |
| 1079 | { |
| 1080 | output.emplace(("eventState[" + std::to_string(i) + "]"), |
| 1081 | sensorPresState.at(stateField[i].event_state)); |
| 1082 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | pldmtool::helper::DisplayInJson(output); |
| 1086 | } |
| 1087 | |
| 1088 | private: |
| 1089 | uint16_t sensorId; |
| 1090 | uint8_t sensorRearm; |
| 1091 | }; |
| 1092 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1093 | void registerCommand(CLI::App& app) |
| 1094 | { |
| 1095 | auto platform = app.add_subcommand("platform", "platform type command"); |
| 1096 | platform->require_subcommand(1); |
| 1097 | |
| 1098 | auto getPDR = |
| 1099 | platform->add_subcommand("GetPDR", "get platform descriptor records"); |
| 1100 | commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR)); |
| 1101 | |
| 1102 | auto setStateEffecterStates = platform->add_subcommand( |
| 1103 | "SetStateEffecterStates", "set effecter states"); |
| 1104 | commands.push_back(std::make_unique<SetStateEffecter>( |
| 1105 | "platform", "setStateEffecterStates", setStateEffecterStates)); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 1106 | |
| 1107 | auto setNumericEffecterValue = platform->add_subcommand( |
| 1108 | "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter"); |
| 1109 | commands.push_back(std::make_unique<SetNumericEffecterValue>( |
| 1110 | "platform", "setNumericEffecterValue", setNumericEffecterValue)); |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1111 | |
| 1112 | auto getStateSensorReadings = platform->add_subcommand( |
| 1113 | "GetStateSensorReadings", "get the state sensor readings"); |
| 1114 | commands.push_back(std::make_unique<GetStateSensorReadings>( |
| 1115 | "platform", "getStateSensorReadings", getStateSensorReadings)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | } // namespace platform |
| 1119 | } // namespace pldmtool |