Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 1 | #include "pldm_base_cmd.hpp" |
| 2 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 3 | #include "pldm_cmd_helper.hpp" |
| 4 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 5 | #include <libpldm/utils.h> |
| 6 | |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 7 | #ifdef OEM_IBM |
Andrew Jeffery | 21f128d | 2024-01-15 15:34:26 +1030 | [diff] [blame] | 8 | #include <libpldm/oem/ibm/file_io.h> |
| 9 | #include <libpldm/oem/ibm/host.h> |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 10 | #endif |
| 11 | |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 12 | #include <string> |
| 13 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 14 | namespace pldmtool |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 15 | { |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 16 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 17 | namespace base |
Lakshminarayana R. Kammath | 27693a4 | 2019-06-24 00:51:47 -0500 | [diff] [blame] | 18 | { |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 19 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 20 | namespace |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 21 | { |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 22 | |
| 23 | using namespace pldmtool::helper; |
| 24 | |
| 25 | std::vector<std::unique_ptr<CommandInterface>> commands; |
| 26 | const std::map<const char*, pldm_supported_types> pldmTypes{ |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 27 | {"base", PLDM_BASE}, {"platform", PLDM_PLATFORM}, |
| 28 | {"bios", PLDM_BIOS}, {"fru", PLDM_FRU}, |
| 29 | #ifdef OEM_IBM |
| 30 | {"oem-ibm", PLDM_OEM}, |
| 31 | #endif |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 34 | const std::map<const char*, pldm_supported_commands> pldmBaseCmds{ |
| 35 | {"GetTID", PLDM_GET_TID}, |
| 36 | {"GetPLDMVersion", PLDM_GET_PLDM_VERSION}, |
| 37 | {"GetPLDMTypes", PLDM_GET_PLDM_TYPES}, |
| 38 | {"GetPLDMCommands", PLDM_GET_PLDM_COMMANDS}}; |
| 39 | |
| 40 | const std::map<const char*, pldm_bios_commands> pldmBiosCmds{ |
| 41 | {"GetBIOSTable", PLDM_GET_BIOS_TABLE}, |
Sridevi Ramesh | 8fb11c9 | 2021-06-08 08:45:01 -0500 | [diff] [blame] | 42 | {"SetBIOSTable", PLDM_SET_BIOS_TABLE}, |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 43 | {"SetBIOSAttributeCurrentValue", PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE}, |
| 44 | {"GetBIOSAttributeCurrentValueByHandle", |
| 45 | PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE}, |
| 46 | {"GetDateTime", PLDM_GET_DATE_TIME}, |
| 47 | {"SetDateTime", PLDM_SET_DATE_TIME}}; |
| 48 | |
| 49 | const std::map<const char*, pldm_platform_commands> pldmPlatformCmds{ |
| 50 | {"SetNumericEffecterValue", PLDM_SET_NUMERIC_EFFECTER_VALUE}, |
| 51 | {"SetStateEffecterStates", PLDM_SET_STATE_EFFECTER_STATES}, |
Tal Yacobi | 8570fcc | 2024-05-28 11:11:23 +0300 | [diff] [blame] | 52 | {"GetStateEffecterStates", PLDM_GET_STATE_EFFECTER_STATES}, |
Sridevi Ramesh | 8fb11c9 | 2021-06-08 08:45:01 -0500 | [diff] [blame] | 53 | {"GetPDR", PLDM_GET_PDR}, |
| 54 | {"GetNumericEffecterValue", PLDM_GET_NUMERIC_EFFECTER_VALUE}, |
| 55 | {"SetEventReceiver", PLDM_SET_EVENT_RECEIVER}, |
| 56 | {"GetSensorReading", PLDM_GET_SENSOR_READING}, |
| 57 | {"GetStateSensorReadings", PLDM_GET_STATE_SENSOR_READINGS}, |
| 58 | {"PlatformEventMessage", PLDM_PLATFORM_EVENT_MESSAGE}}; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 59 | |
| 60 | const std::map<const char*, pldm_fru_commands> pldmFruCmds{ |
| 61 | {"GetFRURecordTableMetadata", PLDM_GET_FRU_RECORD_TABLE_METADATA}, |
John Wang | 5bdde3a | 2020-06-16 15:02:33 +0800 | [diff] [blame] | 62 | {"GetFRURecordTable", PLDM_GET_FRU_RECORD_TABLE}, |
| 63 | {"GetFRURecordByOption", PLDM_GET_FRU_RECORD_BY_OPTION}}; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 64 | |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 65 | #ifdef OEM_IBM |
| 66 | const std::map<const char*, pldm_host_commands> pldmIBMHostCmds{ |
| 67 | {"GetAlertStatus", PLDM_HOST_GET_ALERT_STATUS}}; |
| 68 | |
| 69 | const std::map<const char*, pldm_fileio_commands> pldmIBMFileIOCmds{ |
| 70 | {"GetFileTable", PLDM_GET_FILE_TABLE}, |
| 71 | {"ReadFile", PLDM_READ_FILE}, |
| 72 | {"WriteFile", PLDM_WRITE_FILE}, |
| 73 | {"ReadFileInToMemory", PLDM_READ_FILE_INTO_MEMORY}, |
| 74 | {"WriteFileFromMemory", PLDM_WRITE_FILE_FROM_MEMORY}, |
| 75 | {"ReadFileByTypeIntoMemory", PLDM_READ_FILE_BY_TYPE_INTO_MEMORY}, |
| 76 | {"WriteFileByTypeFromMemory", PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY}, |
| 77 | {"NewFileAvailable", PLDM_NEW_FILE_AVAILABLE}, |
| 78 | {"ReadFileByType", PLDM_READ_FILE_BY_TYPE}, |
| 79 | {"WriteFileByType", PLDM_WRITE_FILE_BY_TYPE}, |
| 80 | {"FileAck", PLDM_FILE_ACK}}; |
| 81 | #endif |
| 82 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 83 | } // namespace |
| 84 | |
| 85 | class GetPLDMTypes : public CommandInterface |
| 86 | { |
| 87 | public: |
| 88 | ~GetPLDMTypes() = default; |
| 89 | GetPLDMTypes() = delete; |
| 90 | GetPLDMTypes(const GetPLDMTypes&) = delete; |
| 91 | GetPLDMTypes(GetPLDMTypes&&) = default; |
| 92 | GetPLDMTypes& operator=(const GetPLDMTypes&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 93 | GetPLDMTypes& operator=(GetPLDMTypes&&) = delete; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 94 | |
| 95 | using CommandInterface::CommandInterface; |
| 96 | |
| 97 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 98 | { |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 99 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr)); |
| 100 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 101 | auto rc = encode_get_types_req(instanceId, request); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 102 | return {rc, requestMsg}; |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 103 | } |
| 104 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 105 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 106 | { |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 107 | uint8_t cc = 0; |
| 108 | std::vector<bitfield8_t> types(8); |
| 109 | auto rc = decode_get_types_resp(responsePtr, payloadLength, &cc, |
| 110 | types.data()); |
| 111 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 112 | { |
| 113 | std::cerr << "Response Message Error: " |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 114 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 115 | return; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | printPldmTypes(types); |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 119 | } |
| 120 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 121 | private: |
| 122 | void printPldmTypes(std::vector<bitfield8_t>& types) |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 123 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 124 | ordered_json data; |
| 125 | ordered_json jarray; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 126 | for (int i = 0; i < PLDM_MAX_TYPES; i++) |
| 127 | { |
| 128 | bitfield8_t b = types[i / 8]; |
| 129 | if (b.byte & (1 << i % 8)) |
| 130 | { |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 131 | auto it = std::find_if( |
| 132 | pldmTypes.begin(), pldmTypes.end(), |
| 133 | [i](const auto& typePair) { return typePair.second == i; }); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 134 | if (it != pldmTypes.end()) |
| 135 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 136 | jarray["PLDM Type"] = it->first; |
| 137 | jarray["PLDM Type Code"] = i; |
| 138 | data.emplace_back(jarray); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 142 | pldmtool::helper::DisplayInJson(data); |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 143 | } |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | class GetPLDMVersion : public CommandInterface |
| 147 | { |
| 148 | public: |
| 149 | ~GetPLDMVersion() = default; |
| 150 | GetPLDMVersion() = delete; |
| 151 | GetPLDMVersion(const GetPLDMVersion&) = delete; |
| 152 | GetPLDMVersion(GetPLDMVersion&&) = default; |
| 153 | GetPLDMVersion& operator=(const GetPLDMVersion&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 154 | GetPLDMVersion& operator=(GetPLDMVersion&&) = delete; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 155 | |
| 156 | explicit GetPLDMVersion(const char* type, const char* name, CLI::App* app) : |
| 157 | CommandInterface(type, name, app) |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 158 | { |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 159 | app->add_option("-t,--type", pldmType, "pldm supported type") |
| 160 | ->required() |
| 161 | ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case)); |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 162 | } |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 163 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 164 | { |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 165 | std::vector<uint8_t> requestMsg( |
| 166 | sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 167 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 168 | |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 169 | auto rc = encode_get_version_req(instanceId, 0, PLDM_GET_FIRSTPART, |
| 170 | pldmType, request); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 171 | return {rc, requestMsg}; |
| 172 | } |
| 173 | |
| 174 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 175 | { |
| 176 | uint8_t cc = 0, transferFlag = 0; |
| 177 | uint32_t transferHandle = 0; |
| 178 | ver32_t version; |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 179 | auto rc = |
| 180 | decode_get_version_resp(responsePtr, payloadLength, &cc, |
| 181 | &transferHandle, &transferFlag, &version); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 182 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 183 | { |
| 184 | std::cerr << "Response Message Error: " |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 185 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | char buffer[16] = {0}; |
| 189 | ver2str(&version, buffer, sizeof(buffer)); |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 190 | ordered_json data; |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 191 | auto it = std::find_if( |
| 192 | pldmTypes.begin(), pldmTypes.end(), |
| 193 | [&](const auto& typePair) { return typePair.second == pldmType; }); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 194 | |
| 195 | if (it != pldmTypes.end()) |
| 196 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 197 | data["Response"] = buffer; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 198 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 199 | pldmtool::helper::DisplayInJson(data); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | private: |
| 203 | pldm_supported_types pldmType; |
| 204 | }; |
| 205 | |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 206 | class GetTID : public CommandInterface |
| 207 | { |
| 208 | public: |
| 209 | ~GetTID() = default; |
| 210 | GetTID() = delete; |
| 211 | GetTID(const GetTID&) = delete; |
| 212 | GetTID(GetTID&&) = default; |
| 213 | GetTID& operator=(const GetTID&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 214 | GetTID& operator=(GetTID&&) = delete; |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 215 | |
| 216 | using CommandInterface::CommandInterface; |
| 217 | |
| 218 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 219 | { |
| 220 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr)); |
| 221 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 222 | auto rc = encode_get_tid_req(instanceId, request); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 223 | return {rc, requestMsg}; |
| 224 | } |
| 225 | |
| 226 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 227 | { |
| 228 | uint8_t cc = 0; |
| 229 | uint8_t tid = 0; |
| 230 | std::vector<bitfield8_t> types(8); |
| 231 | auto rc = decode_get_tid_resp(responsePtr, payloadLength, &cc, &tid); |
| 232 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 233 | { |
| 234 | std::cerr << "Response Message Error: " |
| 235 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
| 236 | return; |
| 237 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 238 | ordered_json data; |
| 239 | data["Response"] = static_cast<uint32_t>(tid); |
| 240 | pldmtool::helper::DisplayInJson(data); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 241 | } |
| 242 | }; |
| 243 | |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 244 | class GetPLDMCommands : public CommandInterface |
| 245 | { |
| 246 | public: |
| 247 | ~GetPLDMCommands() = default; |
| 248 | GetPLDMCommands() = delete; |
| 249 | GetPLDMCommands(const GetPLDMCommands&) = delete; |
| 250 | GetPLDMCommands(GetPLDMCommands&&) = default; |
| 251 | GetPLDMCommands& operator=(const GetPLDMCommands&) = delete; |
Pavithra Barithaya | a7dbca5 | 2023-07-07 04:19:37 -0500 | [diff] [blame] | 252 | GetPLDMCommands& operator=(GetPLDMCommands&&) = delete; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 253 | |
| 254 | explicit GetPLDMCommands(const char* type, const char* name, |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 255 | CLI::App* app) : CommandInterface(type, name, app) |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 256 | { |
| 257 | app->add_option("-t,--type", pldmType, "pldm supported type") |
| 258 | ->required() |
| 259 | ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case)); |
Thu Nguyen | 6c83d3b | 2024-06-22 13:06:12 +0000 | [diff] [blame] | 260 | app->add_option( |
| 261 | "-d,--data", inputVersion, |
| 262 | "Set PLDM type version. Which is got from GetPLDMVersion\n" |
| 263 | "eg: version 1.1.0 then data will be `0xf1 0xf1 0xf0 0x00`"); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 267 | { |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 268 | std::vector<uint8_t> requestMsg( |
| 269 | sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 270 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 271 | ver32_t version{0xFF, 0xFF, 0xFF, 0xFF}; |
Thu Nguyen | 6c83d3b | 2024-06-22 13:06:12 +0000 | [diff] [blame] | 272 | if (inputVersion.size() != 0) |
| 273 | { |
| 274 | if (inputVersion.size() != 4) |
| 275 | { |
| 276 | std::cerr << "Invalid version format. " |
| 277 | << "\n"; |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | version.major = inputVersion[3]; |
| 282 | version.minor = inputVersion[2]; |
| 283 | version.update = inputVersion[1]; |
| 284 | version.alpha = inputVersion[0]; |
| 285 | } |
| 286 | } |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 287 | auto rc = |
| 288 | encode_get_commands_req(instanceId, pldmType, version, request); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 289 | return {rc, requestMsg}; |
| 290 | } |
| 291 | |
| 292 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 293 | { |
| 294 | uint8_t cc = 0; |
| 295 | std::vector<bitfield8_t> cmdTypes(32); |
| 296 | auto rc = decode_get_commands_resp(responsePtr, payloadLength, &cc, |
| 297 | cmdTypes.data()); |
| 298 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 299 | { |
| 300 | std::cerr << "Response Message Error: " |
| 301 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
| 302 | return; |
| 303 | } |
| 304 | printPldmCommands(cmdTypes, pldmType); |
| 305 | } |
| 306 | |
| 307 | private: |
| 308 | pldm_supported_types pldmType; |
Thu Nguyen | 6c83d3b | 2024-06-22 13:06:12 +0000 | [diff] [blame] | 309 | std::vector<uint8_t> inputVersion; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 310 | |
| 311 | template <typename CommandMap> |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 312 | void printCommand(CommandMap& commandMap, int i, ordered_json& jarray) |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 313 | { |
Patrick Williams | a675662 | 2023-10-20 11:19:15 -0500 | [diff] [blame] | 314 | auto it = std::find_if( |
| 315 | commandMap.begin(), commandMap.end(), |
| 316 | [i](const auto& typePair) { return typePair.second == i; }); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 317 | if (it != commandMap.end()) |
| 318 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 319 | jarray["PLDM Command Code"] = i; |
| 320 | jarray["PLDM Command"] = it->first; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | void printPldmCommands(std::vector<bitfield8_t>& cmdTypes, |
| 325 | pldm_supported_types pldmType) |
| 326 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 327 | ordered_json output; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 328 | for (int i = 0; i < PLDM_MAX_CMDS_PER_TYPE; i++) |
| 329 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 330 | ordered_json cmdinfo; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 331 | bitfield8_t b = cmdTypes[i / 8]; |
| 332 | if (b.byte & (1 << i % 8)) |
| 333 | { |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 334 | switch (pldmType) |
| 335 | { |
| 336 | case PLDM_BASE: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 337 | printCommand(pldmBaseCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 338 | break; |
| 339 | case PLDM_PLATFORM: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 340 | printCommand(pldmPlatformCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 341 | break; |
| 342 | case PLDM_BIOS: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 343 | printCommand(pldmBiosCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 344 | break; |
| 345 | case PLDM_FRU: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 346 | printCommand(pldmFruCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 347 | break; |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 348 | case PLDM_OEM: |
Pavithra Barithaya | 6f4e904 | 2020-04-20 23:33:46 -0500 | [diff] [blame] | 349 | #ifdef OEM_IBM |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 350 | printCommand(pldmIBMHostCmds, i, cmdinfo); |
| 351 | printCommand(pldmIBMFileIOCmds, i, cmdinfo); |
Pavithra Barithaya | 6f4e904 | 2020-04-20 23:33:46 -0500 | [diff] [blame] | 352 | #endif |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 353 | break; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 354 | default: |
| 355 | break; |
| 356 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 357 | output.emplace_back(cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 358 | } |
| 359 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 360 | pldmtool::helper::DisplayInJson(output); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 361 | } |
| 362 | }; |
| 363 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 364 | void registerCommand(CLI::App& app) |
| 365 | { |
| 366 | auto base = app.add_subcommand("base", "base type command"); |
| 367 | base->require_subcommand(1); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 368 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 369 | auto getPLDMTypes = |
| 370 | base->add_subcommand("GetPLDMTypes", "get pldm supported types"); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 371 | commands.push_back( |
| 372 | std::make_unique<GetPLDMTypes>("base", "GetPLDMTypes", getPLDMTypes)); |
| 373 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame] | 374 | auto getPLDMVersion = |
| 375 | base->add_subcommand("GetPLDMVersion", "get version of a certain type"); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 376 | commands.push_back(std::make_unique<GetPLDMVersion>( |
| 377 | "base", "GetPLDMVersion", getPLDMVersion)); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 378 | |
| 379 | auto getPLDMTID = base->add_subcommand("GetTID", "get Terminus ID (TID)"); |
| 380 | commands.push_back(std::make_unique<GetTID>("base", "GetTID", getPLDMTID)); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 381 | |
| 382 | auto getPLDMCommands = base->add_subcommand( |
| 383 | "GetPLDMCommands", "get supported commands of pldm type"); |
| 384 | commands.push_back(std::make_unique<GetPLDMCommands>( |
| 385 | "base", "GetPLDMCommands", getPLDMCommands)); |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 386 | } |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 387 | |
| 388 | } // namespace base |
| 389 | } // namespace pldmtool |