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 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 363 | std::string getEntityName(pldm::pdr::EntityType type) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 364 | { |
| 365 | try |
| 366 | { |
| 367 | return entityType.at(type); |
| 368 | } |
| 369 | catch (const std::out_of_range& e) |
| 370 | { |
| 371 | return std::to_string(static_cast<unsigned>(type)) + "(OEM)"; |
| 372 | } |
| 373 | } |
| 374 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 375 | std::string getStateSetName(uint16_t id) |
| 376 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 377 | auto typeString = std::to_string(id); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 378 | try |
| 379 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 380 | return stateSet.at(id) + "(" + typeString + ")"; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 381 | } |
| 382 | catch (const std::out_of_range& e) |
| 383 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 384 | return typeString; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | std::string getPDRType(uint8_t type) |
| 389 | { |
| 390 | auto typeString = std::to_string(type); |
| 391 | try |
| 392 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 393 | return pdrType.at(type); |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 394 | } |
| 395 | catch (const std::out_of_range& e) |
| 396 | { |
| 397 | return typeString; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 398 | } |
| 399 | } |
| 400 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 401 | void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output) |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 402 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 403 | output["recordHandle"] = hdr->record_handle; |
| 404 | output["PDRHeaderVersion"] = unsigned(hdr->version); |
| 405 | output["PDRType"] = getPDRType(hdr->type); |
| 406 | output["recordChangeNumber"] = hdr->record_change_num; |
| 407 | output["dataLength"] = hdr->length; |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 408 | } |
| 409 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 410 | std::string printPossibleStates(uint8_t possibleStatesSize, |
| 411 | const bitfield8_t* states) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 412 | { |
| 413 | uint8_t possibleStatesPos{}; |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 414 | std::string data; |
| 415 | auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) { |
| 416 | std::stringstream pstates; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 417 | for (int i = 0; i < CHAR_BIT; i++) |
| 418 | { |
| 419 | if (val.byte & (1 << i)) |
| 420 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 421 | pstates << " " << (possibleStatesPos * CHAR_BIT + i); |
| 422 | data.append(pstates.str()); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 423 | pstates.str(""); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | possibleStatesPos++; |
| 427 | }; |
| 428 | std::for_each(states, states + possibleStatesSize, printStates); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 429 | return data; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 430 | } |
| 431 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 432 | void printStateSensorPDR(const uint8_t* data, ordered_json& output) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 433 | { |
| 434 | auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 435 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 436 | output["sensorID"] = pdr->sensor_id; |
| 437 | output["entityType"] = getEntityName(pdr->entity_type); |
| 438 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 439 | output["containerID"] = pdr->container_id; |
| 440 | output["sensorInit"] = sensorInit[pdr->sensor_init]; |
| 441 | output["sensorAuxiliaryNamesPDR"] = |
| 442 | (pdr->sensor_auxiliary_names_pdr ? true : false); |
| 443 | output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 444 | |
| 445 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 446 | auto compCount = pdr->composite_sensor_count; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 447 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 448 | while (compCount--) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 449 | { |
| 450 | auto state = reinterpret_cast<const state_sensor_possible_states*>( |
| 451 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 452 | output.emplace(("stateSetID[" + std::to_string(compCount) + "]"), |
| 453 | getStateSetName(state->state_set_id)); |
| 454 | output.emplace( |
| 455 | ("possibleStatesSize[" + std::to_string(compCount) + "]"), |
| 456 | state->possible_states_size); |
| 457 | output.emplace( |
| 458 | ("possibleStates[" + std::to_string(compCount) + "]"), |
| 459 | printPossibleStates(state->possible_states_size, |
| 460 | state->states)); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 461 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 462 | if (compCount) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 463 | { |
| 464 | statesPtr += sizeof(state_sensor_possible_states) + |
| 465 | state->possible_states_size - 1; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 470 | void printPDRFruRecordSet(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 471 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 472 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 473 | { |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | data += sizeof(pldm_pdr_hdr); |
| 478 | pldm_pdr_fru_record_set* pdr = |
| 479 | reinterpret_cast<pldm_pdr_fru_record_set*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 480 | if (!pdr) |
| 481 | { |
| 482 | std::cerr << "Failed to get the FRU record set PDR" << std::endl; |
| 483 | return; |
| 484 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 485 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 486 | output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle); |
| 487 | output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi); |
| 488 | output["entityType"] = getEntityName(pdr->entity_type); |
| 489 | output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num); |
| 490 | output["containerID"] = unsigned(pdr->container_id); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 491 | } |
| 492 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 493 | void printPDREntityAssociation(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 494 | { |
| 495 | const std::map<uint8_t, const char*> assocationType = { |
| 496 | {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"}, |
| 497 | {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"}, |
| 498 | }; |
| 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_entity_association* pdr = |
| 507 | reinterpret_cast<pldm_pdr_entity_association*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 508 | if (!pdr) |
| 509 | { |
| 510 | std::cerr << "Failed to get the PDR eneity association" |
| 511 | << std::endl; |
| 512 | return; |
| 513 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 514 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 515 | output["containerID"] = int(pdr->container_id); |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 516 | if (assocationType.contains(pdr->association_type)) |
| 517 | { |
| 518 | output["associationType"] = |
| 519 | assocationType.at(pdr->association_type); |
| 520 | } |
| 521 | else |
| 522 | { |
| 523 | std::cout << "Get associationType failed.\n"; |
| 524 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 525 | output["containerEntityType"] = |
| 526 | getEntityName(pdr->container.entity_type); |
| 527 | output["containerEntityInstanceNumber"] = |
| 528 | int(pdr->container.entity_instance_num); |
| 529 | output["containerEntityContainerID"] = |
| 530 | int(pdr->container.entity_container_id); |
| 531 | output["containedEntityCount"] = |
| 532 | static_cast<unsigned>(pdr->num_children); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 533 | |
| 534 | auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]); |
| 535 | for (int i = 0; i < pdr->num_children; ++i) |
| 536 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 537 | output.emplace("containedEntityType[" + std::to_string(i + 1) + "]", |
| 538 | getEntityName(child->entity_type)); |
| 539 | output.emplace("containedEntityInstanceNumber[" + |
| 540 | std::to_string(i + 1) + "]", |
| 541 | unsigned(child->entity_instance_num)); |
| 542 | output.emplace("containedEntityContainerID[" + |
| 543 | std::to_string(i + 1) + "]", |
| 544 | unsigned(child->entity_container_id)); |
| 545 | |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 546 | ++child; |
| 547 | } |
| 548 | } |
| 549 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 550 | void printNumericEffecterPDR(uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 551 | { |
| 552 | struct pldm_numeric_effecter_value_pdr* pdr = |
| 553 | (struct pldm_numeric_effecter_value_pdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 554 | if (!pdr) |
| 555 | { |
| 556 | std::cerr << "Failed to get numeric effecter PDR" << std::endl; |
| 557 | return; |
| 558 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 559 | |
| 560 | output["PLDMTerminusHandle"] = int(pdr->terminus_handle); |
| 561 | output["effecterID"] = int(pdr->effecter_id); |
| 562 | output["entityType"] = int(pdr->entity_type); |
| 563 | output["entityInstanceNumber"] = int(pdr->entity_instance); |
| 564 | output["containerID"] = int(pdr->container_id); |
| 565 | output["effecterSemanticID"] = int(pdr->effecter_semantic_id); |
| 566 | output["effecterInit"] = unsigned(pdr->effecter_init); |
| 567 | output["effecterAuxiliaryNames"] = |
| 568 | (unsigned(pdr->effecter_auxiliary_names) ? true : false); |
| 569 | output["baseUnit"] = unsigned(pdr->base_unit); |
| 570 | output["unitModifier"] = unsigned(pdr->unit_modifier); |
| 571 | output["rateUnit"] = unsigned(pdr->rate_unit); |
| 572 | output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle); |
| 573 | output["auxUnit"] = unsigned(pdr->aux_unit); |
| 574 | output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier); |
| 575 | output["auxrateUnit"] = unsigned(pdr->aux_rate_unit); |
| 576 | output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle); |
| 577 | output["isLinear"] = (unsigned(pdr->is_linear) ? true : false); |
| 578 | output["effecterDataSize"] = unsigned(pdr->effecter_data_size); |
| 579 | output["resolution"] = unsigned(pdr->resolution); |
| 580 | output["offset"] = unsigned(pdr->offset); |
| 581 | output["accuracy"] = unsigned(pdr->accuracy); |
| 582 | output["plusTolerance"] = unsigned(pdr->plus_tolerance); |
| 583 | output["minusTolerance"] = unsigned(pdr->minus_tolerance); |
| 584 | output["stateTransitionInterval"] = |
| 585 | unsigned(pdr->state_transition_interval); |
| 586 | output["TransitionInterval"] = unsigned(pdr->transition_interval); |
| 587 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 588 | switch (pdr->effecter_data_size) |
| 589 | { |
| 590 | case PLDM_EFFECTER_DATA_SIZE_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 591 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u8); |
| 592 | output["minSettable"] = unsigned(pdr->min_set_table.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 593 | break; |
| 594 | case PLDM_EFFECTER_DATA_SIZE_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 595 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s8); |
| 596 | output["minSettable"] = unsigned(pdr->min_set_table.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 597 | break; |
| 598 | case PLDM_EFFECTER_DATA_SIZE_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 599 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u16); |
| 600 | output["minSettable"] = unsigned(pdr->min_set_table.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 601 | break; |
| 602 | case PLDM_EFFECTER_DATA_SIZE_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 603 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s16); |
| 604 | output["minSettable"] = unsigned(pdr->min_set_table.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 605 | break; |
| 606 | case PLDM_EFFECTER_DATA_SIZE_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 607 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u32); |
| 608 | output["minSettable"] = unsigned(pdr->min_set_table.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 609 | break; |
| 610 | case PLDM_EFFECTER_DATA_SIZE_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 611 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s32); |
| 612 | output["minSettable"] = unsigned(pdr->min_set_table.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 613 | break; |
| 614 | default: |
| 615 | break; |
| 616 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 617 | |
| 618 | output["rangeFieldFormat"] = unsigned(pdr->range_field_format); |
| 619 | output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte); |
| 620 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 621 | switch (pdr->range_field_format) |
| 622 | { |
| 623 | case PLDM_RANGE_FIELD_FORMAT_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 624 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u8); |
| 625 | output["normalMax"] = unsigned(pdr->normal_max.value_u8); |
| 626 | output["normalMin"] = unsigned(pdr->normal_min.value_u8); |
| 627 | output["ratedMax"] = unsigned(pdr->rated_max.value_u8); |
| 628 | output["ratedMin"] = unsigned(pdr->rated_min.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 629 | break; |
| 630 | case PLDM_RANGE_FIELD_FORMAT_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 631 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s8); |
| 632 | output["normalMax"] = unsigned(pdr->normal_max.value_s8); |
| 633 | output["normalMin"] = unsigned(pdr->normal_min.value_s8); |
| 634 | output["ratedMax"] = unsigned(pdr->rated_max.value_s8); |
| 635 | output["ratedMin"] = unsigned(pdr->rated_min.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 636 | break; |
| 637 | case PLDM_RANGE_FIELD_FORMAT_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 638 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u16); |
| 639 | output["normalMax"] = unsigned(pdr->normal_max.value_u16); |
| 640 | output["normalMin"] = unsigned(pdr->normal_min.value_u16); |
| 641 | output["ratedMax"] = unsigned(pdr->rated_max.value_u16); |
| 642 | output["ratedMin"] = unsigned(pdr->rated_min.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 643 | break; |
| 644 | case PLDM_RANGE_FIELD_FORMAT_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 645 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s16); |
| 646 | output["normalMax"] = unsigned(pdr->normal_max.value_s16); |
| 647 | output["normalMin"] = unsigned(pdr->normal_min.value_s16); |
| 648 | output["ratedMax"] = unsigned(pdr->rated_max.value_s16); |
| 649 | output["ratedMin"] = unsigned(pdr->rated_min.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 650 | break; |
| 651 | case PLDM_RANGE_FIELD_FORMAT_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 652 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u32); |
| 653 | output["normalMax"] = unsigned(pdr->normal_max.value_u32); |
| 654 | output["normalMin"] = unsigned(pdr->normal_min.value_u32); |
| 655 | output["ratedMax"] = unsigned(pdr->rated_max.value_u32); |
| 656 | output["ratedMin"] = unsigned(pdr->rated_min.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 657 | break; |
| 658 | case PLDM_RANGE_FIELD_FORMAT_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 659 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s32); |
| 660 | output["normalMax"] = unsigned(pdr->normal_max.value_s32); |
| 661 | output["normalMin"] = unsigned(pdr->normal_min.value_s32); |
| 662 | output["ratedMax"] = unsigned(pdr->rated_max.value_s32); |
| 663 | output["ratedMin"] = unsigned(pdr->rated_min.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 664 | break; |
| 665 | case PLDM_RANGE_FIELD_FORMAT_REAL32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 666 | output["nominalValue"] = unsigned(pdr->nominal_value.value_f32); |
| 667 | output["normalMax"] = unsigned(pdr->normal_max.value_f32); |
| 668 | output["normalMin"] = unsigned(pdr->normal_min.value_f32); |
| 669 | output["ratedMax"] = unsigned(pdr->rated_max.value_f32); |
| 670 | output["ratedMin"] = unsigned(pdr->rated_min.value_f32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 671 | break; |
| 672 | default: |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 677 | void printStateEffecterPDR(const uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 678 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 679 | auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 680 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 681 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 682 | output["effecterID"] = pdr->effecter_id; |
| 683 | output["entityType"] = getEntityName(pdr->entity_type); |
| 684 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 685 | output["containerID"] = pdr->container_id; |
| 686 | output["effecterSemanticID"] = pdr->effecter_semantic_id; |
| 687 | output["effecterInit"] = effecterInit[pdr->effecter_init]; |
| 688 | output["effecterDescriptionPDR"] = |
| 689 | (pdr->has_description_pdr ? true : false); |
| 690 | output["compositeEffecterCount"] = |
| 691 | unsigned(pdr->composite_effecter_count); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 692 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 693 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 694 | auto compEffCount = pdr->composite_effecter_count; |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 695 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 696 | while (compEffCount--) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 697 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 698 | auto state = |
| 699 | reinterpret_cast<const state_effecter_possible_states*>( |
| 700 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 701 | output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"), |
| 702 | getStateSetName(state->state_set_id)); |
| 703 | output.emplace( |
| 704 | ("possibleStatesSize[" + std::to_string(compEffCount) + "]"), |
| 705 | state->possible_states_size); |
| 706 | output.emplace( |
| 707 | ("possibleStates[" + std::to_string(compEffCount) + "]"), |
| 708 | printPossibleStates(state->possible_states_size, |
| 709 | state->states)); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 710 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 711 | if (compEffCount) |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 712 | { |
| 713 | statesPtr += sizeof(state_effecter_possible_states) + |
| 714 | state->possible_states_size - 1; |
| 715 | } |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 719 | void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output) |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 720 | { |
| 721 | const std::array<std::string_view, 4> terminusLocatorType = { |
| 722 | "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"}; |
| 723 | |
| 724 | auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data); |
| 725 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 726 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 727 | output["validity"] = (pdr->validity ? "valid" : "notValid"); |
| 728 | output["TID"] = unsigned(pdr->tid); |
| 729 | output["containerID"] = pdr->container_id; |
| 730 | output["terminusLocatorType"] = |
| 731 | terminusLocatorType[pdr->terminus_locator_type]; |
| 732 | output["terminusLocatorValueSize"] = |
| 733 | unsigned(pdr->terminus_locator_value_size); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 734 | |
| 735 | if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID) |
| 736 | { |
| 737 | auto locatorValue = |
| 738 | reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>( |
| 739 | pdr->terminus_locator_value); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 740 | output["EID"] = unsigned(locatorValue->eid); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 741 | } |
| 742 | } |
| 743 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 744 | void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt, |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 745 | uint8_t* data) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 746 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 747 | if (data == NULL) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 748 | { |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 749 | std::cerr << "Failed to get PDR message" << std::endl; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 750 | return; |
| 751 | } |
| 752 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 753 | ordered_json output; |
| 754 | output["nextRecordHandle"] = nextRecordHndl; |
| 755 | output["responseCount"] = respCnt; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 756 | |
| 757 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 758 | if (!pdr) |
| 759 | { |
| 760 | return; |
| 761 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 762 | printCommonPDRHeader(pdr, output); |
| 763 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 764 | switch (pdr->type) |
| 765 | { |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 766 | case PLDM_TERMINUS_LOCATOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 767 | printTerminusLocatorPDR(data, output); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 768 | break; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 769 | case PLDM_STATE_SENSOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 770 | printStateSensorPDR(data, output); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 771 | break; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 772 | case PLDM_NUMERIC_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 773 | printNumericEffecterPDR(data, output); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 774 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 775 | case PLDM_STATE_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 776 | printStateEffecterPDR(data, output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 777 | break; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 778 | case PLDM_PDR_ENTITY_ASSOCIATION: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 779 | printPDREntityAssociation(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 780 | break; |
| 781 | case PLDM_PDR_FRU_RECORD_SET: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 782 | printPDRFruRecordSet(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 783 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 784 | default: |
| 785 | break; |
| 786 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 787 | pldmtool::helper::DisplayInJson(output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | private: |
| 791 | uint32_t recordHandle; |
| 792 | }; |
| 793 | |
| 794 | class SetStateEffecter : public CommandInterface |
| 795 | { |
| 796 | public: |
| 797 | ~SetStateEffecter() = default; |
| 798 | SetStateEffecter() = delete; |
| 799 | SetStateEffecter(const SetStateEffecter&) = delete; |
| 800 | SetStateEffecter(SetStateEffecter&&) = default; |
| 801 | SetStateEffecter& operator=(const SetStateEffecter&) = delete; |
| 802 | SetStateEffecter& operator=(SetStateEffecter&&) = default; |
| 803 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 804 | // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2) |
| 805 | static constexpr auto maxEffecterDataSize = 16; |
| 806 | |
| 807 | // compositeEffecterCount(value: 0x01 to 0x08) |
| 808 | static constexpr auto minEffecterCount = 1; |
| 809 | static constexpr auto maxEffecterCount = 8; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 810 | explicit SetStateEffecter(const char* type, const char* name, |
| 811 | CLI::App* app) : |
| 812 | CommandInterface(type, name, app) |
| 813 | { |
| 814 | app->add_option( |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 815 | "-i, --id", effecterId, |
| 816 | "A handle that is used to identify and access the effecter") |
| 817 | ->required(); |
| 818 | app->add_option("-c, --count", effecterCount, |
| 819 | "The number of individual sets of effecter information") |
| 820 | ->required(); |
| 821 | app->add_option( |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 822 | "-d,--data", effecterData, |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 823 | "Set effecter state data\n" |
| 824 | "eg: requestSet0 effecterState0 noChange1 dummyState1 ...") |
| 825 | ->required(); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 829 | { |
| 830 | std::vector<uint8_t> requestMsg( |
| 831 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES); |
| 832 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 833 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 834 | if (effecterCount > maxEffecterCount || |
| 835 | effecterCount < minEffecterCount) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 836 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 837 | std::cerr << "Request Message Error: effecterCount size " |
| 838 | << effecterCount << "is invalid\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 839 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 840 | return {rc, requestMsg}; |
| 841 | } |
| 842 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 843 | if (effecterData.size() > maxEffecterDataSize) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 844 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 845 | std::cerr << "Request Message Error: effecterData size " |
| 846 | << effecterData.size() << "is invalid\n"; |
| 847 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 848 | return {rc, requestMsg}; |
| 849 | } |
| 850 | |
| 851 | auto stateField = parseEffecterData(effecterData, effecterCount); |
| 852 | if (!stateField) |
| 853 | { |
| 854 | std::cerr << "Failed to parse effecter data, effecterCount size " |
| 855 | << effecterCount << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 856 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 857 | return {rc, requestMsg}; |
| 858 | } |
| 859 | |
| 860 | auto rc = encode_set_state_effecter_states_req( |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 861 | instanceId, effecterId, effecterCount, stateField->data(), request); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 862 | return {rc, requestMsg}; |
| 863 | } |
| 864 | |
| 865 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 866 | { |
| 867 | uint8_t completionCode = 0; |
| 868 | auto rc = decode_set_state_effecter_states_resp( |
| 869 | responsePtr, payloadLength, &completionCode); |
| 870 | |
| 871 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 872 | { |
| 873 | std::cerr << "Response Message Error: " |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 874 | << "rc=" << rc << ",cc=" << (int)completionCode << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 875 | return; |
| 876 | } |
| 877 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 878 | ordered_json data; |
| 879 | data["Response"] = "SUCCESS"; |
| 880 | pldmtool::helper::DisplayInJson(data); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | private: |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 884 | uint16_t effecterId; |
| 885 | uint8_t effecterCount; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 886 | std::vector<uint8_t> effecterData; |
| 887 | }; |
| 888 | |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 889 | class SetNumericEffecterValue : public CommandInterface |
| 890 | { |
| 891 | public: |
| 892 | ~SetNumericEffecterValue() = default; |
| 893 | SetNumericEffecterValue() = delete; |
| 894 | SetNumericEffecterValue(const SetNumericEffecterValue&) = delete; |
| 895 | SetNumericEffecterValue(SetNumericEffecterValue&&) = default; |
| 896 | SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete; |
| 897 | SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default; |
| 898 | |
| 899 | explicit SetNumericEffecterValue(const char* type, const char* name, |
| 900 | CLI::App* app) : |
| 901 | CommandInterface(type, name, app) |
| 902 | { |
| 903 | app->add_option( |
| 904 | "-i, --id", effecterId, |
| 905 | "A handle that is used to identify and access the effecter") |
| 906 | ->required(); |
| 907 | app->add_option("-s, --size", effecterDataSize, |
| 908 | "The bit width and format of the setting value for the " |
| 909 | "effecter. enum value: {uint8, sint8, uint16, sint16, " |
| 910 | "uint32, sint32}\n") |
| 911 | ->required(); |
| 912 | app->add_option("-d,--data", maxEffecterValue, |
| 913 | "The setting value of numeric effecter being " |
| 914 | "requested\n") |
| 915 | ->required(); |
| 916 | } |
| 917 | |
| 918 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 919 | { |
| 920 | std::vector<uint8_t> requestMsg( |
| 921 | sizeof(pldm_msg_hdr) + |
| 922 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3); |
| 923 | |
| 924 | uint8_t* effecterValue = (uint8_t*)&maxEffecterValue; |
| 925 | |
| 926 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 927 | size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES; |
| 928 | |
| 929 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 930 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16) |
| 931 | { |
| 932 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1; |
| 933 | } |
| 934 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 935 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32) |
| 936 | { |
| 937 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3; |
| 938 | } |
| 939 | auto rc = encode_set_numeric_effecter_value_req( |
| 940 | 0, effecterId, effecterDataSize, effecterValue, request, |
| 941 | payload_length); |
| 942 | |
| 943 | return {rc, requestMsg}; |
| 944 | } |
| 945 | |
| 946 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 947 | { |
| 948 | uint8_t completionCode = 0; |
| 949 | auto rc = decode_set_numeric_effecter_value_resp( |
| 950 | responsePtr, payloadLength, &completionCode); |
| 951 | |
| 952 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 953 | { |
| 954 | std::cerr << "Response Message Error: " |
| 955 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 956 | << std::endl; |
| 957 | return; |
| 958 | } |
| 959 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 960 | ordered_json data; |
| 961 | data["Response"] = "SUCCESS"; |
| 962 | pldmtool::helper::DisplayInJson(data); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | private: |
| 966 | uint16_t effecterId; |
| 967 | uint8_t effecterDataSize; |
| 968 | uint64_t maxEffecterValue; |
| 969 | }; |
| 970 | |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 971 | class GetStateSensorReadings : public CommandInterface |
| 972 | { |
| 973 | public: |
| 974 | ~GetStateSensorReadings() = default; |
| 975 | GetStateSensorReadings() = delete; |
| 976 | GetStateSensorReadings(const GetStateSensorReadings&) = delete; |
| 977 | GetStateSensorReadings(GetStateSensorReadings&&) = default; |
| 978 | GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete; |
| 979 | GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default; |
| 980 | |
| 981 | explicit GetStateSensorReadings(const char* type, const char* name, |
| 982 | CLI::App* app) : |
| 983 | CommandInterface(type, name, app) |
| 984 | { |
| 985 | app->add_option( |
| 986 | "-i, --sensor_id", sensorId, |
| 987 | "Sensor ID that is used to identify and access the sensor") |
| 988 | ->required(); |
| 989 | app->add_option("-r, --rearm", sensorRearm, |
| 990 | "Each bit location in this field corresponds to a " |
| 991 | "particular sensor") |
| 992 | ->required(); |
| 993 | } |
| 994 | |
| 995 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 996 | { |
| 997 | std::vector<uint8_t> requestMsg( |
| 998 | sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES); |
| 999 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 1000 | |
| 1001 | uint8_t reserved = 0; |
| 1002 | bitfield8_t bf; |
| 1003 | bf.byte = sensorRearm; |
| 1004 | auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf, |
| 1005 | reserved, request); |
| 1006 | |
| 1007 | return {rc, requestMsg}; |
| 1008 | } |
| 1009 | |
| 1010 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 1011 | { |
| 1012 | uint8_t completionCode = 0; |
| 1013 | uint8_t compSensorCount = 0; |
| 1014 | std::array<get_sensor_state_field, 8> stateField{}; |
| 1015 | auto rc = decode_get_state_sensor_readings_resp( |
| 1016 | responsePtr, payloadLength, &completionCode, &compSensorCount, |
| 1017 | stateField.data()); |
| 1018 | |
| 1019 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 1020 | { |
| 1021 | std::cerr << "Response Message Error: " |
| 1022 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 1023 | << std::endl; |
| 1024 | return; |
| 1025 | } |
| 1026 | ordered_json output; |
| 1027 | output["compositeSensorCount"] = (int)compSensorCount; |
| 1028 | |
| 1029 | for (size_t i = 0; i < compSensorCount; i++) |
| 1030 | { |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 1031 | if (sensorOpState.contains(stateField[i].sensor_op_state)) |
| 1032 | { |
| 1033 | output.emplace(("sensorOpState[" + std::to_string(i) + "]"), |
| 1034 | sensorOpState.at(stateField[i].sensor_op_state)); |
| 1035 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1036 | |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 1037 | if (sensorPresState.contains(stateField[i].present_state)) |
| 1038 | { |
| 1039 | output.emplace(("presentState[" + std::to_string(i) + "]"), |
| 1040 | sensorPresState.at(stateField[i].present_state)); |
| 1041 | } |
| 1042 | |
| 1043 | if (sensorPresState.contains(stateField[i].previous_state)) |
| 1044 | { |
| 1045 | output.emplace( |
| 1046 | ("previousState[" + std::to_string(i) + "]"), |
| 1047 | sensorPresState.at(stateField[i].previous_state)); |
| 1048 | } |
| 1049 | |
| 1050 | if (sensorPresState.contains(stateField[i].event_state)) |
| 1051 | { |
| 1052 | output.emplace(("eventState[" + std::to_string(i) + "]"), |
| 1053 | sensorPresState.at(stateField[i].event_state)); |
| 1054 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | pldmtool::helper::DisplayInJson(output); |
| 1058 | } |
| 1059 | |
| 1060 | private: |
| 1061 | uint16_t sensorId; |
| 1062 | uint8_t sensorRearm; |
| 1063 | }; |
| 1064 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1065 | void registerCommand(CLI::App& app) |
| 1066 | { |
| 1067 | auto platform = app.add_subcommand("platform", "platform type command"); |
| 1068 | platform->require_subcommand(1); |
| 1069 | |
| 1070 | auto getPDR = |
| 1071 | platform->add_subcommand("GetPDR", "get platform descriptor records"); |
| 1072 | commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR)); |
| 1073 | |
| 1074 | auto setStateEffecterStates = platform->add_subcommand( |
| 1075 | "SetStateEffecterStates", "set effecter states"); |
| 1076 | commands.push_back(std::make_unique<SetStateEffecter>( |
| 1077 | "platform", "setStateEffecterStates", setStateEffecterStates)); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 1078 | |
| 1079 | auto setNumericEffecterValue = platform->add_subcommand( |
| 1080 | "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter"); |
| 1081 | commands.push_back(std::make_unique<SetNumericEffecterValue>( |
| 1082 | "platform", "setNumericEffecterValue", setNumericEffecterValue)); |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 1083 | |
| 1084 | auto getStateSensorReadings = platform->add_subcommand( |
| 1085 | "GetStateSensorReadings", "get the state sensor readings"); |
| 1086 | commands.push_back(std::make_unique<GetStateSensorReadings>( |
| 1087 | "platform", "getStateSensorReadings", getStateSensorReadings)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | } // namespace platform |
| 1091 | } // namespace pldmtool |