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 = { |
| 110 | {PLDM_ENTITY_COMM_CHANNEL, "Communication Channel"}, |
| 111 | {PLDM_ENTITY_SYS_FIRMWARE, "System Firmware"}, |
| 112 | {PLDM_ENTITY_VIRTUAL_MACHINE_MANAGER, "Virtual Machine Manager"}, |
| 113 | {PLDM_ENTITY_SYSTEM_CHASSIS, "System chassis (main enclosure)"}, |
| 114 | {PLDM_ENTITY_SYS_BOARD, "System Board"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 115 | {PLDM_ENTITY_DRIVE_BACKPLANE, "Drive backplane"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 116 | {PLDM_ENTITY_MEMORY_MODULE, "Memory Module"}, |
| 117 | {PLDM_ENTITY_PROC_MODULE, "Processor Module"}, |
| 118 | {PLDM_ENTITY_CHASSIS_FRONT_PANEL_BOARD, |
| 119 | "Chassis front panel board (control panel)"}, |
| 120 | {PLDM_ENTITY_POWER_CONVERTER, "Power converter"}, |
| 121 | {PLDM_ENTITY_PROC, "Processor"}, |
| 122 | {PLDM_ENTITY_MGMT_CONTROLLER, "Management Controller"}, |
| 123 | {PLDM_ENTITY_CONNECTOR, "Connector"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 124 | {PLDM_ENTITY_FAN, "Fan"}, |
| 125 | {PLDM_ENTITY_SOLID_STATE_SRIVE, "Solid State Drive"}, |
Deepak Kodihalli | e05dcc2 | 2020-07-14 05:13:58 -0500 | [diff] [blame] | 126 | {PLDM_ENTITY_POWER_SUPPLY, "Power Supply"}, |
Jayashankar Padath | 79175b4 | 2021-05-20 22:54:34 -0500 | [diff] [blame] | 127 | {PLDM_ENTITY_MEMORY_CHIP, "Memory chip"}, |
| 128 | {PLDM_ENTITY_REAL_TIME_CLOCK, "Real Time Clock (RTC)"}, |
| 129 | {PLDM_ENTITY_SLOT, "Slot"}, |
| 130 | {PLDM_ENTITY_CABLE, "Cable (electrical or optical)"}, |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 131 | {11521, "System (logical)"}, |
| 132 | }; |
| 133 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 134 | const std::map<uint16_t, std::string> stateSet = { |
| 135 | {PLDM_STATE_SET_HEALTH_STATE, "Health State"}, |
| 136 | {PLDM_STATE_SET_AVAILABILITY, "Availability"}, |
| 137 | {PLDM_STATE_SET_OPERATIONAL_STATUS, "Operational Status"}, |
| 138 | {PLDM_STATE_SET_OPERATIONAL_RUNNING_STATUS, |
| 139 | "Operational Running Status"}, |
| 140 | {PLDM_STATE_SET_PRESENCE, "Presence"}, |
| 141 | {PLDM_STATE_SET_CONFIGURATION_STATE, "Configuration State"}, |
| 142 | {PLDM_STATE_SET_LINK_STATE, "Link State"}, |
| 143 | {PLDM_STATE_SET_SW_TERMINATION_STATUS, "Software Termination Status"}, |
| 144 | {PLDM_STATE_SET_BOOT_RESTART_CAUSE, "Boot/Restart Cause"}, |
| 145 | {PLDM_STATE_SET_BOOT_PROGRESS, "Boot Progress"}, |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 146 | {PLDM_STATE_SET_SYSTEM_POWER_STATE, "System Power State"}, |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | const std::array<std::string_view, 4> sensorInit = { |
| 150 | "noInit", "useInitPDR", "enableSensor", "disableSensor"}; |
| 151 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 152 | const std::array<std::string_view, 4> effecterInit = { |
| 153 | "noInit", "useInitPDR", "enableEffecter", "disableEffecter"}; |
| 154 | |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 155 | const std::map<uint8_t, std::string> pdrType = { |
| 156 | {PLDM_TERMINUS_LOCATOR_PDR, "Terminus Locator PDR"}, |
| 157 | {PLDM_NUMERIC_SENSOR_PDR, "Numeric Sensor PDR"}, |
| 158 | {PLDM_NUMERIC_SENSOR_INITIALIZATION_PDR, |
| 159 | "Numeric Sensor Initialization PDR"}, |
| 160 | {PLDM_STATE_SENSOR_PDR, "State Sensor PDR"}, |
| 161 | {PLDM_STATE_SENSOR_INITIALIZATION_PDR, |
| 162 | "State Sensor Initialization PDR"}, |
| 163 | {PLDM_SENSOR_AUXILIARY_NAMES_PDR, "Sensor Auxiliary Names PDR"}, |
| 164 | {PLDM_OEM_UNIT_PDR, "OEM Unit PDR"}, |
| 165 | {PLDM_OEM_STATE_SET_PDR, "OEM State Set PDR"}, |
| 166 | {PLDM_NUMERIC_EFFECTER_PDR, "Numeric Effecter PDR"}, |
| 167 | {PLDM_NUMERIC_EFFECTER_INITIALIZATION_PDR, |
| 168 | "Numeric Effecter Initialization PDR"}, |
| 169 | {PLDM_STATE_EFFECTER_PDR, "State Effecter PDR"}, |
| 170 | {PLDM_STATE_EFFECTER_INITIALIZATION_PDR, |
| 171 | "State Effecter Initialization PDR"}, |
| 172 | {PLDM_EFFECTER_AUXILIARY_NAMES_PDR, "Effecter Auxiliary Names PDR"}, |
| 173 | {PLDM_EFFECTER_OEM_SEMANTIC_PDR, "Effecter OEM Semantic PDR"}, |
| 174 | {PLDM_PDR_ENTITY_ASSOCIATION, "Entity Association PDR"}, |
| 175 | {PLDM_ENTITY_AUXILIARY_NAMES_PDR, "Entity Auxiliary Names PDR"}, |
| 176 | {PLDM_OEM_ENTITY_ID_PDR, "OEM Entity ID PDR"}, |
| 177 | {PLDM_INTERRUPT_ASSOCIATION_PDR, "Interrupt Association PDR"}, |
| 178 | {PLDM_EVENT_LOG_PDR, "PLDM Event Log PDR"}, |
| 179 | {PLDM_PDR_FRU_RECORD_SET, "FRU Record Set PDR"}, |
| 180 | {PLDM_OEM_DEVICE_PDR, "OEM Device PDR"}, |
| 181 | {PLDM_OEM_PDR, "OEM PDR"}, |
| 182 | }; |
| 183 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 184 | std::string getEntityName(pldm::pdr::EntityType type) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 185 | { |
| 186 | try |
| 187 | { |
| 188 | return entityType.at(type); |
| 189 | } |
| 190 | catch (const std::out_of_range& e) |
| 191 | { |
| 192 | return std::to_string(static_cast<unsigned>(type)) + "(OEM)"; |
| 193 | } |
| 194 | } |
| 195 | |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 196 | std::string getStateSetName(uint16_t id) |
| 197 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 198 | auto typeString = std::to_string(id); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 199 | try |
| 200 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 201 | return stateSet.at(id) + "(" + typeString + ")"; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 202 | } |
| 203 | catch (const std::out_of_range& e) |
| 204 | { |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 205 | return typeString; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | std::string getPDRType(uint8_t type) |
| 210 | { |
| 211 | auto typeString = std::to_string(type); |
| 212 | try |
| 213 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 214 | return pdrType.at(type); |
Sridevi Ramesh | a1bfb78 | 2020-07-14 02:51:23 -0500 | [diff] [blame] | 215 | } |
| 216 | catch (const std::out_of_range& e) |
| 217 | { |
| 218 | return typeString; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 222 | void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output) |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 223 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 224 | output["recordHandle"] = hdr->record_handle; |
| 225 | output["PDRHeaderVersion"] = unsigned(hdr->version); |
| 226 | output["PDRType"] = getPDRType(hdr->type); |
| 227 | output["recordChangeNumber"] = hdr->record_change_num; |
| 228 | output["dataLength"] = hdr->length; |
Tom Joseph | 952abfa | 2020-07-03 12:25:15 +0530 | [diff] [blame] | 229 | } |
| 230 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 231 | std::string printPossibleStates(uint8_t possibleStatesSize, |
| 232 | const bitfield8_t* states) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 233 | { |
| 234 | uint8_t possibleStatesPos{}; |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 235 | std::string data; |
| 236 | auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) { |
| 237 | std::stringstream pstates; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 238 | for (int i = 0; i < CHAR_BIT; i++) |
| 239 | { |
| 240 | if (val.byte & (1 << i)) |
| 241 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 242 | pstates << " " << (possibleStatesPos * CHAR_BIT + i); |
| 243 | data.append(pstates.str()); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 244 | pstates.str(""); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | possibleStatesPos++; |
| 248 | }; |
| 249 | std::for_each(states, states + possibleStatesSize, printStates); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 250 | return data; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 251 | } |
| 252 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 253 | void printStateSensorPDR(const uint8_t* data, ordered_json& output) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 254 | { |
| 255 | auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 256 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 257 | output["sensorID"] = pdr->sensor_id; |
| 258 | output["entityType"] = getEntityName(pdr->entity_type); |
| 259 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 260 | output["containerID"] = pdr->container_id; |
| 261 | output["sensorInit"] = sensorInit[pdr->sensor_init]; |
| 262 | output["sensorAuxiliaryNamesPDR"] = |
| 263 | (pdr->sensor_auxiliary_names_pdr ? true : false); |
| 264 | output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 265 | |
| 266 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 267 | auto compCount = pdr->composite_sensor_count; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 268 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 269 | while (compCount--) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 270 | { |
| 271 | auto state = reinterpret_cast<const state_sensor_possible_states*>( |
| 272 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 273 | output.emplace(("stateSetID[" + std::to_string(compCount) + "]"), |
| 274 | getStateSetName(state->state_set_id)); |
| 275 | output.emplace( |
| 276 | ("possibleStatesSize[" + std::to_string(compCount) + "]"), |
| 277 | state->possible_states_size); |
| 278 | output.emplace( |
| 279 | ("possibleStates[" + std::to_string(compCount) + "]"), |
| 280 | printPossibleStates(state->possible_states_size, |
| 281 | state->states)); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 282 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 283 | if (compCount) |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 284 | { |
| 285 | statesPtr += sizeof(state_sensor_possible_states) + |
| 286 | state->possible_states_size - 1; |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 291 | void printPDRFruRecordSet(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 292 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 293 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 294 | { |
| 295 | return; |
| 296 | } |
| 297 | |
| 298 | data += sizeof(pldm_pdr_hdr); |
| 299 | pldm_pdr_fru_record_set* pdr = |
| 300 | reinterpret_cast<pldm_pdr_fru_record_set*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 301 | if (!pdr) |
| 302 | { |
| 303 | std::cerr << "Failed to get the FRU record set PDR" << std::endl; |
| 304 | return; |
| 305 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 306 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 307 | output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle); |
| 308 | output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi); |
| 309 | output["entityType"] = getEntityName(pdr->entity_type); |
| 310 | output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num); |
| 311 | output["containerID"] = unsigned(pdr->container_id); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 312 | } |
| 313 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 314 | void printPDREntityAssociation(uint8_t* data, ordered_json& output) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 315 | { |
| 316 | const std::map<uint8_t, const char*> assocationType = { |
| 317 | {PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"}, |
| 318 | {PLDM_ENTITY_ASSOCIAION_LOGICAL, "Logical"}, |
| 319 | }; |
| 320 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 321 | if (data == NULL) |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 322 | { |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | data += sizeof(pldm_pdr_hdr); |
| 327 | pldm_pdr_entity_association* pdr = |
| 328 | reinterpret_cast<pldm_pdr_entity_association*>(data); |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 329 | if (!pdr) |
| 330 | { |
| 331 | std::cerr << "Failed to get the PDR eneity association" |
| 332 | << std::endl; |
| 333 | return; |
| 334 | } |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 335 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 336 | output["containerID"] = int(pdr->container_id); |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 337 | if (assocationType.contains(pdr->association_type)) |
| 338 | { |
| 339 | output["associationType"] = |
| 340 | assocationType.at(pdr->association_type); |
| 341 | } |
| 342 | else |
| 343 | { |
| 344 | std::cout << "Get associationType failed.\n"; |
| 345 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 346 | output["containerEntityType"] = |
| 347 | getEntityName(pdr->container.entity_type); |
| 348 | output["containerEntityInstanceNumber"] = |
| 349 | int(pdr->container.entity_instance_num); |
| 350 | output["containerEntityContainerID"] = |
| 351 | int(pdr->container.entity_container_id); |
| 352 | output["containedEntityCount"] = |
| 353 | static_cast<unsigned>(pdr->num_children); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 354 | |
| 355 | auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]); |
| 356 | for (int i = 0; i < pdr->num_children; ++i) |
| 357 | { |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 358 | output.emplace("containedEntityType[" + std::to_string(i + 1) + "]", |
| 359 | getEntityName(child->entity_type)); |
| 360 | output.emplace("containedEntityInstanceNumber[" + |
| 361 | std::to_string(i + 1) + "]", |
| 362 | unsigned(child->entity_instance_num)); |
| 363 | output.emplace("containedEntityContainerID[" + |
| 364 | std::to_string(i + 1) + "]", |
| 365 | unsigned(child->entity_container_id)); |
| 366 | |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 367 | ++child; |
| 368 | } |
| 369 | } |
| 370 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 371 | void printNumericEffecterPDR(uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 372 | { |
| 373 | struct pldm_numeric_effecter_value_pdr* pdr = |
| 374 | (struct pldm_numeric_effecter_value_pdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 375 | if (!pdr) |
| 376 | { |
| 377 | std::cerr << "Failed to get numeric effecter PDR" << std::endl; |
| 378 | return; |
| 379 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 380 | |
| 381 | output["PLDMTerminusHandle"] = int(pdr->terminus_handle); |
| 382 | output["effecterID"] = int(pdr->effecter_id); |
| 383 | output["entityType"] = int(pdr->entity_type); |
| 384 | output["entityInstanceNumber"] = int(pdr->entity_instance); |
| 385 | output["containerID"] = int(pdr->container_id); |
| 386 | output["effecterSemanticID"] = int(pdr->effecter_semantic_id); |
| 387 | output["effecterInit"] = unsigned(pdr->effecter_init); |
| 388 | output["effecterAuxiliaryNames"] = |
| 389 | (unsigned(pdr->effecter_auxiliary_names) ? true : false); |
| 390 | output["baseUnit"] = unsigned(pdr->base_unit); |
| 391 | output["unitModifier"] = unsigned(pdr->unit_modifier); |
| 392 | output["rateUnit"] = unsigned(pdr->rate_unit); |
| 393 | output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle); |
| 394 | output["auxUnit"] = unsigned(pdr->aux_unit); |
| 395 | output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier); |
| 396 | output["auxrateUnit"] = unsigned(pdr->aux_rate_unit); |
| 397 | output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle); |
| 398 | output["isLinear"] = (unsigned(pdr->is_linear) ? true : false); |
| 399 | output["effecterDataSize"] = unsigned(pdr->effecter_data_size); |
| 400 | output["resolution"] = unsigned(pdr->resolution); |
| 401 | output["offset"] = unsigned(pdr->offset); |
| 402 | output["accuracy"] = unsigned(pdr->accuracy); |
| 403 | output["plusTolerance"] = unsigned(pdr->plus_tolerance); |
| 404 | output["minusTolerance"] = unsigned(pdr->minus_tolerance); |
| 405 | output["stateTransitionInterval"] = |
| 406 | unsigned(pdr->state_transition_interval); |
| 407 | output["TransitionInterval"] = unsigned(pdr->transition_interval); |
| 408 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 409 | switch (pdr->effecter_data_size) |
| 410 | { |
| 411 | case PLDM_EFFECTER_DATA_SIZE_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 412 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u8); |
| 413 | output["minSettable"] = unsigned(pdr->min_set_table.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 414 | break; |
| 415 | case PLDM_EFFECTER_DATA_SIZE_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 416 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s8); |
| 417 | output["minSettable"] = unsigned(pdr->min_set_table.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 418 | break; |
| 419 | case PLDM_EFFECTER_DATA_SIZE_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 420 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u16); |
| 421 | output["minSettable"] = unsigned(pdr->min_set_table.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 422 | break; |
| 423 | case PLDM_EFFECTER_DATA_SIZE_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 424 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s16); |
| 425 | output["minSettable"] = unsigned(pdr->min_set_table.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 426 | break; |
| 427 | case PLDM_EFFECTER_DATA_SIZE_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 428 | output["maxSettable"] = unsigned(pdr->max_set_table.value_u32); |
| 429 | output["minSettable"] = unsigned(pdr->min_set_table.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 430 | break; |
| 431 | case PLDM_EFFECTER_DATA_SIZE_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 432 | output["maxSettable"] = unsigned(pdr->max_set_table.value_s32); |
| 433 | output["minSettable"] = unsigned(pdr->min_set_table.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 434 | break; |
| 435 | default: |
| 436 | break; |
| 437 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 438 | |
| 439 | output["rangeFieldFormat"] = unsigned(pdr->range_field_format); |
| 440 | output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte); |
| 441 | |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 442 | switch (pdr->range_field_format) |
| 443 | { |
| 444 | case PLDM_RANGE_FIELD_FORMAT_UINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 445 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u8); |
| 446 | output["normalMax"] = unsigned(pdr->normal_max.value_u8); |
| 447 | output["normalMin"] = unsigned(pdr->normal_min.value_u8); |
| 448 | output["ratedMax"] = unsigned(pdr->rated_max.value_u8); |
| 449 | output["ratedMin"] = unsigned(pdr->rated_min.value_u8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 450 | break; |
| 451 | case PLDM_RANGE_FIELD_FORMAT_SINT8: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 452 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s8); |
| 453 | output["normalMax"] = unsigned(pdr->normal_max.value_s8); |
| 454 | output["normalMin"] = unsigned(pdr->normal_min.value_s8); |
| 455 | output["ratedMax"] = unsigned(pdr->rated_max.value_s8); |
| 456 | output["ratedMin"] = unsigned(pdr->rated_min.value_s8); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 457 | break; |
| 458 | case PLDM_RANGE_FIELD_FORMAT_UINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 459 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u16); |
| 460 | output["normalMax"] = unsigned(pdr->normal_max.value_u16); |
| 461 | output["normalMin"] = unsigned(pdr->normal_min.value_u16); |
| 462 | output["ratedMax"] = unsigned(pdr->rated_max.value_u16); |
| 463 | output["ratedMin"] = unsigned(pdr->rated_min.value_u16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 464 | break; |
| 465 | case PLDM_RANGE_FIELD_FORMAT_SINT16: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 466 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s16); |
| 467 | output["normalMax"] = unsigned(pdr->normal_max.value_s16); |
| 468 | output["normalMin"] = unsigned(pdr->normal_min.value_s16); |
| 469 | output["ratedMax"] = unsigned(pdr->rated_max.value_s16); |
| 470 | output["ratedMin"] = unsigned(pdr->rated_min.value_s16); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 471 | break; |
| 472 | case PLDM_RANGE_FIELD_FORMAT_UINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 473 | output["nominalValue"] = unsigned(pdr->nominal_value.value_u32); |
| 474 | output["normalMax"] = unsigned(pdr->normal_max.value_u32); |
| 475 | output["normalMin"] = unsigned(pdr->normal_min.value_u32); |
| 476 | output["ratedMax"] = unsigned(pdr->rated_max.value_u32); |
| 477 | output["ratedMin"] = unsigned(pdr->rated_min.value_u32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 478 | break; |
| 479 | case PLDM_RANGE_FIELD_FORMAT_SINT32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 480 | output["nominalValue"] = unsigned(pdr->nominal_value.value_s32); |
| 481 | output["normalMax"] = unsigned(pdr->normal_max.value_s32); |
| 482 | output["normalMin"] = unsigned(pdr->normal_min.value_s32); |
| 483 | output["ratedMax"] = unsigned(pdr->rated_max.value_s32); |
| 484 | output["ratedMin"] = unsigned(pdr->rated_min.value_s32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 485 | break; |
| 486 | case PLDM_RANGE_FIELD_FORMAT_REAL32: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 487 | output["nominalValue"] = unsigned(pdr->nominal_value.value_f32); |
| 488 | output["normalMax"] = unsigned(pdr->normal_max.value_f32); |
| 489 | output["normalMin"] = unsigned(pdr->normal_min.value_f32); |
| 490 | output["ratedMax"] = unsigned(pdr->rated_max.value_f32); |
| 491 | output["ratedMin"] = unsigned(pdr->rated_min.value_f32); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 492 | break; |
| 493 | default: |
| 494 | break; |
| 495 | } |
| 496 | } |
| 497 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 498 | void printStateEffecterPDR(const uint8_t* data, ordered_json& output) |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 499 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 500 | auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 501 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 502 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 503 | output["effecterID"] = pdr->effecter_id; |
| 504 | output["entityType"] = getEntityName(pdr->entity_type); |
| 505 | output["entityInstanceNumber"] = pdr->entity_instance; |
| 506 | output["containerID"] = pdr->container_id; |
| 507 | output["effecterSemanticID"] = pdr->effecter_semantic_id; |
| 508 | output["effecterInit"] = effecterInit[pdr->effecter_init]; |
| 509 | output["effecterDescriptionPDR"] = |
| 510 | (pdr->has_description_pdr ? true : false); |
| 511 | output["compositeEffecterCount"] = |
| 512 | unsigned(pdr->composite_effecter_count); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 513 | |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 514 | auto statesPtr = pdr->possible_states; |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 515 | auto compEffCount = pdr->composite_effecter_count; |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 516 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 517 | while (compEffCount--) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 518 | { |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 519 | auto state = |
| 520 | reinterpret_cast<const state_effecter_possible_states*>( |
| 521 | statesPtr); |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 522 | output.emplace(("stateSetID[" + std::to_string(compEffCount) + "]"), |
| 523 | getStateSetName(state->state_set_id)); |
| 524 | output.emplace( |
| 525 | ("possibleStatesSize[" + std::to_string(compEffCount) + "]"), |
| 526 | state->possible_states_size); |
| 527 | output.emplace( |
| 528 | ("possibleStates[" + std::to_string(compEffCount) + "]"), |
| 529 | printPossibleStates(state->possible_states_size, |
| 530 | state->states)); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 531 | |
Sridevi Ramesh | 148ccab | 2020-11-23 08:23:09 -0600 | [diff] [blame] | 532 | if (compEffCount) |
Tom Joseph | 97a7a76 | 2020-07-06 10:37:18 +0530 | [diff] [blame] | 533 | { |
| 534 | statesPtr += sizeof(state_effecter_possible_states) + |
| 535 | state->possible_states_size - 1; |
| 536 | } |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 540 | void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output) |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 541 | { |
| 542 | const std::array<std::string_view, 4> terminusLocatorType = { |
| 543 | "UID", "MCTP_EID", "SMBusRelative", "systemSoftware"}; |
| 544 | |
| 545 | auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data); |
| 546 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 547 | output["PLDMTerminusHandle"] = pdr->terminus_handle; |
| 548 | output["validity"] = (pdr->validity ? "valid" : "notValid"); |
| 549 | output["TID"] = unsigned(pdr->tid); |
| 550 | output["containerID"] = pdr->container_id; |
| 551 | output["terminusLocatorType"] = |
| 552 | terminusLocatorType[pdr->terminus_locator_type]; |
| 553 | output["terminusLocatorValueSize"] = |
| 554 | unsigned(pdr->terminus_locator_value_size); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 555 | |
| 556 | if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID) |
| 557 | { |
| 558 | auto locatorValue = |
| 559 | reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>( |
| 560 | pdr->terminus_locator_value); |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 561 | output["EID"] = unsigned(locatorValue->eid); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 565 | void printPDRMsg(const uint32_t nextRecordHndl, const uint16_t respCnt, |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 566 | uint8_t* data) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 567 | { |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 568 | if (data == NULL) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 569 | { |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 570 | std::cerr << "Failed to get PDR message" << std::endl; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 571 | return; |
| 572 | } |
| 573 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 574 | ordered_json output; |
| 575 | output["nextRecordHandle"] = nextRecordHndl; |
| 576 | output["responseCount"] = respCnt; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 577 | |
| 578 | struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data; |
Manojkiran Eda | bcf91ac | 2021-03-14 13:50:48 +0530 | [diff] [blame] | 579 | if (!pdr) |
| 580 | { |
| 581 | return; |
| 582 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 583 | printCommonPDRHeader(pdr, output); |
| 584 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 585 | switch (pdr->type) |
| 586 | { |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 587 | case PLDM_TERMINUS_LOCATOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 588 | printTerminusLocatorPDR(data, output); |
Sampa Misra | 12afe11 | 2020-05-25 11:40:44 -0500 | [diff] [blame] | 589 | break; |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 590 | case PLDM_STATE_SENSOR_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 591 | printStateSensorPDR(data, output); |
Tom Joseph | a65c041 | 2020-07-03 21:14:44 +0530 | [diff] [blame] | 592 | break; |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 593 | case PLDM_NUMERIC_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 594 | printNumericEffecterPDR(data, output); |
George Liu | 62d12ec | 2020-02-05 16:27:08 +0800 | [diff] [blame] | 595 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 596 | case PLDM_STATE_EFFECTER_PDR: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 597 | printStateEffecterPDR(data, output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 598 | break; |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 599 | case PLDM_PDR_ENTITY_ASSOCIATION: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 600 | printPDREntityAssociation(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 601 | break; |
| 602 | case PLDM_PDR_FRU_RECORD_SET: |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 603 | printPDRFruRecordSet(data, output); |
Deepak Kodihalli | 5544ccd | 2020-03-15 23:36:16 -0500 | [diff] [blame] | 604 | break; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 605 | default: |
| 606 | break; |
| 607 | } |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 608 | pldmtool::helper::DisplayInJson(output); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | private: |
| 612 | uint32_t recordHandle; |
| 613 | }; |
| 614 | |
| 615 | class SetStateEffecter : public CommandInterface |
| 616 | { |
| 617 | public: |
| 618 | ~SetStateEffecter() = default; |
| 619 | SetStateEffecter() = delete; |
| 620 | SetStateEffecter(const SetStateEffecter&) = delete; |
| 621 | SetStateEffecter(SetStateEffecter&&) = default; |
| 622 | SetStateEffecter& operator=(const SetStateEffecter&) = delete; |
| 623 | SetStateEffecter& operator=(SetStateEffecter&&) = default; |
| 624 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 625 | // compositeEffecterCount(value: 0x01 to 0x08) * stateField(2) |
| 626 | static constexpr auto maxEffecterDataSize = 16; |
| 627 | |
| 628 | // compositeEffecterCount(value: 0x01 to 0x08) |
| 629 | static constexpr auto minEffecterCount = 1; |
| 630 | static constexpr auto maxEffecterCount = 8; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 631 | explicit SetStateEffecter(const char* type, const char* name, |
| 632 | CLI::App* app) : |
| 633 | CommandInterface(type, name, app) |
| 634 | { |
| 635 | app->add_option( |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 636 | "-i, --id", effecterId, |
| 637 | "A handle that is used to identify and access the effecter") |
| 638 | ->required(); |
| 639 | app->add_option("-c, --count", effecterCount, |
| 640 | "The number of individual sets of effecter information") |
| 641 | ->required(); |
| 642 | app->add_option( |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 643 | "-d,--data", effecterData, |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 644 | "Set effecter state data\n" |
| 645 | "eg: requestSet0 effecterState0 noChange1 dummyState1 ...") |
| 646 | ->required(); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 650 | { |
| 651 | std::vector<uint8_t> requestMsg( |
| 652 | sizeof(pldm_msg_hdr) + PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES); |
| 653 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 654 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 655 | if (effecterCount > maxEffecterCount || |
| 656 | effecterCount < minEffecterCount) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 657 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 658 | std::cerr << "Request Message Error: effecterCount size " |
| 659 | << effecterCount << "is invalid\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 660 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 661 | return {rc, requestMsg}; |
| 662 | } |
| 663 | |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 664 | if (effecterData.size() > maxEffecterDataSize) |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 665 | { |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 666 | std::cerr << "Request Message Error: effecterData size " |
| 667 | << effecterData.size() << "is invalid\n"; |
| 668 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 669 | return {rc, requestMsg}; |
| 670 | } |
| 671 | |
| 672 | auto stateField = parseEffecterData(effecterData, effecterCount); |
| 673 | if (!stateField) |
| 674 | { |
| 675 | std::cerr << "Failed to parse effecter data, effecterCount size " |
| 676 | << effecterCount << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 677 | auto rc = PLDM_ERROR_INVALID_DATA; |
| 678 | return {rc, requestMsg}; |
| 679 | } |
| 680 | |
| 681 | auto rc = encode_set_state_effecter_states_req( |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 682 | instanceId, effecterId, effecterCount, stateField->data(), request); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 683 | return {rc, requestMsg}; |
| 684 | } |
| 685 | |
| 686 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 687 | { |
| 688 | uint8_t completionCode = 0; |
| 689 | auto rc = decode_set_state_effecter_states_resp( |
| 690 | responsePtr, payloadLength, &completionCode); |
| 691 | |
| 692 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 693 | { |
| 694 | std::cerr << "Response Message Error: " |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 695 | << "rc=" << rc << ",cc=" << (int)completionCode << "\n"; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 699 | ordered_json data; |
| 700 | data["Response"] = "SUCCESS"; |
| 701 | pldmtool::helper::DisplayInJson(data); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | private: |
George Liu | ba4c1fb | 2020-02-05 14:13:30 +0800 | [diff] [blame] | 705 | uint16_t effecterId; |
| 706 | uint8_t effecterCount; |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 707 | std::vector<uint8_t> effecterData; |
| 708 | }; |
| 709 | |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 710 | class SetNumericEffecterValue : public CommandInterface |
| 711 | { |
| 712 | public: |
| 713 | ~SetNumericEffecterValue() = default; |
| 714 | SetNumericEffecterValue() = delete; |
| 715 | SetNumericEffecterValue(const SetNumericEffecterValue&) = delete; |
| 716 | SetNumericEffecterValue(SetNumericEffecterValue&&) = default; |
| 717 | SetNumericEffecterValue& operator=(const SetNumericEffecterValue&) = delete; |
| 718 | SetNumericEffecterValue& operator=(SetNumericEffecterValue&&) = default; |
| 719 | |
| 720 | explicit SetNumericEffecterValue(const char* type, const char* name, |
| 721 | CLI::App* app) : |
| 722 | CommandInterface(type, name, app) |
| 723 | { |
| 724 | app->add_option( |
| 725 | "-i, --id", effecterId, |
| 726 | "A handle that is used to identify and access the effecter") |
| 727 | ->required(); |
| 728 | app->add_option("-s, --size", effecterDataSize, |
| 729 | "The bit width and format of the setting value for the " |
| 730 | "effecter. enum value: {uint8, sint8, uint16, sint16, " |
| 731 | "uint32, sint32}\n") |
| 732 | ->required(); |
| 733 | app->add_option("-d,--data", maxEffecterValue, |
| 734 | "The setting value of numeric effecter being " |
| 735 | "requested\n") |
| 736 | ->required(); |
| 737 | } |
| 738 | |
| 739 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 740 | { |
| 741 | std::vector<uint8_t> requestMsg( |
| 742 | sizeof(pldm_msg_hdr) + |
| 743 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3); |
| 744 | |
| 745 | uint8_t* effecterValue = (uint8_t*)&maxEffecterValue; |
| 746 | |
| 747 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 748 | size_t payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES; |
| 749 | |
| 750 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 751 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT16) |
| 752 | { |
| 753 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1; |
| 754 | } |
| 755 | if (effecterDataSize == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 756 | effecterDataSize == PLDM_EFFECTER_DATA_SIZE_SINT32) |
| 757 | { |
| 758 | payload_length = PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3; |
| 759 | } |
| 760 | auto rc = encode_set_numeric_effecter_value_req( |
| 761 | 0, effecterId, effecterDataSize, effecterValue, request, |
| 762 | payload_length); |
| 763 | |
| 764 | return {rc, requestMsg}; |
| 765 | } |
| 766 | |
| 767 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 768 | { |
| 769 | uint8_t completionCode = 0; |
| 770 | auto rc = decode_set_numeric_effecter_value_resp( |
| 771 | responsePtr, payloadLength, &completionCode); |
| 772 | |
| 773 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 774 | { |
| 775 | std::cerr << "Response Message Error: " |
| 776 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 777 | << std::endl; |
| 778 | return; |
| 779 | } |
| 780 | |
Sridevi Ramesh | 27c512a | 2020-08-12 03:29:42 -0500 | [diff] [blame] | 781 | ordered_json data; |
| 782 | data["Response"] = "SUCCESS"; |
| 783 | pldmtool::helper::DisplayInJson(data); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | private: |
| 787 | uint16_t effecterId; |
| 788 | uint8_t effecterDataSize; |
| 789 | uint64_t maxEffecterValue; |
| 790 | }; |
| 791 | |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 792 | class GetStateSensorReadings : public CommandInterface |
| 793 | { |
| 794 | public: |
| 795 | ~GetStateSensorReadings() = default; |
| 796 | GetStateSensorReadings() = delete; |
| 797 | GetStateSensorReadings(const GetStateSensorReadings&) = delete; |
| 798 | GetStateSensorReadings(GetStateSensorReadings&&) = default; |
| 799 | GetStateSensorReadings& operator=(const GetStateSensorReadings&) = delete; |
| 800 | GetStateSensorReadings& operator=(GetStateSensorReadings&&) = default; |
| 801 | |
| 802 | explicit GetStateSensorReadings(const char* type, const char* name, |
| 803 | CLI::App* app) : |
| 804 | CommandInterface(type, name, app) |
| 805 | { |
| 806 | app->add_option( |
| 807 | "-i, --sensor_id", sensorId, |
| 808 | "Sensor ID that is used to identify and access the sensor") |
| 809 | ->required(); |
| 810 | app->add_option("-r, --rearm", sensorRearm, |
| 811 | "Each bit location in this field corresponds to a " |
| 812 | "particular sensor") |
| 813 | ->required(); |
| 814 | } |
| 815 | |
| 816 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 817 | { |
| 818 | std::vector<uint8_t> requestMsg( |
| 819 | sizeof(pldm_msg_hdr) + PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES); |
| 820 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 821 | |
| 822 | uint8_t reserved = 0; |
| 823 | bitfield8_t bf; |
| 824 | bf.byte = sensorRearm; |
| 825 | auto rc = encode_get_state_sensor_readings_req(instanceId, sensorId, bf, |
| 826 | reserved, request); |
| 827 | |
| 828 | return {rc, requestMsg}; |
| 829 | } |
| 830 | |
| 831 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 832 | { |
| 833 | uint8_t completionCode = 0; |
| 834 | uint8_t compSensorCount = 0; |
| 835 | std::array<get_sensor_state_field, 8> stateField{}; |
| 836 | auto rc = decode_get_state_sensor_readings_resp( |
| 837 | responsePtr, payloadLength, &completionCode, &compSensorCount, |
| 838 | stateField.data()); |
| 839 | |
| 840 | if (rc != PLDM_SUCCESS || completionCode != PLDM_SUCCESS) |
| 841 | { |
| 842 | std::cerr << "Response Message Error: " |
| 843 | << "rc=" << rc << ",cc=" << (int)completionCode |
| 844 | << std::endl; |
| 845 | return; |
| 846 | } |
| 847 | ordered_json output; |
| 848 | output["compositeSensorCount"] = (int)compSensorCount; |
| 849 | |
| 850 | for (size_t i = 0; i < compSensorCount; i++) |
| 851 | { |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 852 | if (sensorOpState.contains(stateField[i].sensor_op_state)) |
| 853 | { |
| 854 | output.emplace(("sensorOpState[" + std::to_string(i) + "]"), |
| 855 | sensorOpState.at(stateField[i].sensor_op_state)); |
| 856 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 857 | |
George Liu | bd5e2ea | 2021-04-22 20:33:06 +0800 | [diff] [blame] | 858 | if (sensorPresState.contains(stateField[i].present_state)) |
| 859 | { |
| 860 | output.emplace(("presentState[" + std::to_string(i) + "]"), |
| 861 | sensorPresState.at(stateField[i].present_state)); |
| 862 | } |
| 863 | |
| 864 | if (sensorPresState.contains(stateField[i].previous_state)) |
| 865 | { |
| 866 | output.emplace( |
| 867 | ("previousState[" + std::to_string(i) + "]"), |
| 868 | sensorPresState.at(stateField[i].previous_state)); |
| 869 | } |
| 870 | |
| 871 | if (sensorPresState.contains(stateField[i].event_state)) |
| 872 | { |
| 873 | output.emplace(("eventState[" + std::to_string(i) + "]"), |
| 874 | sensorPresState.at(stateField[i].event_state)); |
| 875 | } |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | pldmtool::helper::DisplayInJson(output); |
| 879 | } |
| 880 | |
| 881 | private: |
| 882 | uint16_t sensorId; |
| 883 | uint8_t sensorRearm; |
| 884 | }; |
| 885 | |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 886 | void registerCommand(CLI::App& app) |
| 887 | { |
| 888 | auto platform = app.add_subcommand("platform", "platform type command"); |
| 889 | platform->require_subcommand(1); |
| 890 | |
| 891 | auto getPDR = |
| 892 | platform->add_subcommand("GetPDR", "get platform descriptor records"); |
| 893 | commands.push_back(std::make_unique<GetPDR>("platform", "getPDR", getPDR)); |
| 894 | |
| 895 | auto setStateEffecterStates = platform->add_subcommand( |
| 896 | "SetStateEffecterStates", "set effecter states"); |
| 897 | commands.push_back(std::make_unique<SetStateEffecter>( |
| 898 | "platform", "setStateEffecterStates", setStateEffecterStates)); |
George Liu | cc9c20d | 2020-02-05 10:24:11 +0800 | [diff] [blame] | 899 | |
| 900 | auto setNumericEffecterValue = platform->add_subcommand( |
| 901 | "SetNumericEffecterValue", "set the value for a PLDM Numeric Effecter"); |
| 902 | commands.push_back(std::make_unique<SetNumericEffecterValue>( |
| 903 | "platform", "setNumericEffecterValue", setNumericEffecterValue)); |
Sridevi Ramesh | f31b504 | 2021-01-22 05:42:07 -0600 | [diff] [blame] | 904 | |
| 905 | auto getStateSensorReadings = platform->add_subcommand( |
| 906 | "GetStateSensorReadings", "get the state sensor readings"); |
| 907 | commands.push_back(std::make_unique<GetStateSensorReadings>( |
| 908 | "platform", "getStateSensorReadings", getStateSensorReadings)); |
George Liu | d664936 | 2019-11-27 19:06:51 +0800 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | } // namespace platform |
| 912 | } // namespace pldmtool |