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 |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 8 | #include <libpldm/file_io.h> |
| 9 | #include <libpldm/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}, |
Sridevi Ramesh | 8fb11c9 | 2021-06-08 08:45:01 -0500 | [diff] [blame] | 52 | {"GetPDR", PLDM_GET_PDR}, |
| 53 | {"GetNumericEffecterValue", PLDM_GET_NUMERIC_EFFECTER_VALUE}, |
| 54 | {"SetEventReceiver", PLDM_SET_EVENT_RECEIVER}, |
| 55 | {"GetSensorReading", PLDM_GET_SENSOR_READING}, |
| 56 | {"GetStateSensorReadings", PLDM_GET_STATE_SENSOR_READINGS}, |
| 57 | {"PlatformEventMessage", PLDM_PLATFORM_EVENT_MESSAGE}}; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 58 | |
| 59 | const std::map<const char*, pldm_fru_commands> pldmFruCmds{ |
| 60 | {"GetFRURecordTableMetadata", PLDM_GET_FRU_RECORD_TABLE_METADATA}, |
John Wang | 5bdde3a | 2020-06-16 15:02:33 +0800 | [diff] [blame] | 61 | {"GetFRURecordTable", PLDM_GET_FRU_RECORD_TABLE}, |
| 62 | {"GetFRURecordByOption", PLDM_GET_FRU_RECORD_BY_OPTION}}; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 63 | |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 64 | #ifdef OEM_IBM |
| 65 | const std::map<const char*, pldm_host_commands> pldmIBMHostCmds{ |
| 66 | {"GetAlertStatus", PLDM_HOST_GET_ALERT_STATUS}}; |
| 67 | |
| 68 | const std::map<const char*, pldm_fileio_commands> pldmIBMFileIOCmds{ |
| 69 | {"GetFileTable", PLDM_GET_FILE_TABLE}, |
| 70 | {"ReadFile", PLDM_READ_FILE}, |
| 71 | {"WriteFile", PLDM_WRITE_FILE}, |
| 72 | {"ReadFileInToMemory", PLDM_READ_FILE_INTO_MEMORY}, |
| 73 | {"WriteFileFromMemory", PLDM_WRITE_FILE_FROM_MEMORY}, |
| 74 | {"ReadFileByTypeIntoMemory", PLDM_READ_FILE_BY_TYPE_INTO_MEMORY}, |
| 75 | {"WriteFileByTypeFromMemory", PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY}, |
| 76 | {"NewFileAvailable", PLDM_NEW_FILE_AVAILABLE}, |
| 77 | {"ReadFileByType", PLDM_READ_FILE_BY_TYPE}, |
| 78 | {"WriteFileByType", PLDM_WRITE_FILE_BY_TYPE}, |
| 79 | {"FileAck", PLDM_FILE_ACK}}; |
| 80 | #endif |
| 81 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 82 | } // namespace |
| 83 | |
| 84 | class GetPLDMTypes : public CommandInterface |
| 85 | { |
| 86 | public: |
| 87 | ~GetPLDMTypes() = default; |
| 88 | GetPLDMTypes() = delete; |
| 89 | GetPLDMTypes(const GetPLDMTypes&) = delete; |
| 90 | GetPLDMTypes(GetPLDMTypes&&) = default; |
| 91 | GetPLDMTypes& operator=(const GetPLDMTypes&) = delete; |
| 92 | GetPLDMTypes& operator=(GetPLDMTypes&&) = default; |
| 93 | |
| 94 | using CommandInterface::CommandInterface; |
| 95 | |
| 96 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 97 | { |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 98 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr)); |
| 99 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 100 | auto rc = encode_get_types_req(instanceId, request); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 101 | return {rc, requestMsg}; |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 102 | } |
| 103 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 104 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 105 | { |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 106 | uint8_t cc = 0; |
| 107 | std::vector<bitfield8_t> types(8); |
| 108 | auto rc = decode_get_types_resp(responsePtr, payloadLength, &cc, |
| 109 | types.data()); |
| 110 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 111 | { |
| 112 | std::cerr << "Response Message Error: " |
Sampa Misra | aa8ae72 | 2019-12-12 03:20:40 -0600 | [diff] [blame] | 113 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 114 | return; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | printPldmTypes(types); |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 118 | } |
| 119 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 120 | private: |
| 121 | void printPldmTypes(std::vector<bitfield8_t>& types) |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 122 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 123 | ordered_json data; |
| 124 | ordered_json jarray; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 125 | for (int i = 0; i < PLDM_MAX_TYPES; i++) |
| 126 | { |
| 127 | bitfield8_t b = types[i / 8]; |
| 128 | if (b.byte & (1 << i % 8)) |
| 129 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 130 | auto it = std::find_if(pldmTypes.begin(), pldmTypes.end(), |
| 131 | [i](const auto& typePair) { |
| 132 | return typePair.second == i; |
| 133 | }); |
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; |
| 154 | GetPLDMVersion& operator=(GetPLDMVersion&&) = default; |
| 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 | { |
| 165 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 166 | PLDM_GET_VERSION_REQ_BYTES); |
| 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 | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 179 | auto rc = decode_get_version_resp(responsePtr, payloadLength, &cc, |
| 180 | &transferHandle, &transferFlag, |
| 181 | &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 | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 191 | auto it = std::find_if(pldmTypes.begin(), pldmTypes.end(), |
| 192 | [&](const auto& typePair) { |
| 193 | return typePair.second == pldmType; |
| 194 | }); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 195 | |
| 196 | if (it != pldmTypes.end()) |
| 197 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 198 | data["Response"] = buffer; |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 199 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 200 | pldmtool::helper::DisplayInJson(data); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | private: |
| 204 | pldm_supported_types pldmType; |
| 205 | }; |
| 206 | |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 207 | class GetTID : public CommandInterface |
| 208 | { |
| 209 | public: |
| 210 | ~GetTID() = default; |
| 211 | GetTID() = delete; |
| 212 | GetTID(const GetTID&) = delete; |
| 213 | GetTID(GetTID&&) = default; |
| 214 | GetTID& operator=(const GetTID&) = delete; |
| 215 | GetTID& operator=(GetTID&&) = default; |
| 216 | |
| 217 | using CommandInterface::CommandInterface; |
| 218 | |
| 219 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 220 | { |
| 221 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr)); |
| 222 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
Pavithra Barithaya | ac3c45a | 2020-03-05 02:28:26 -0600 | [diff] [blame] | 223 | auto rc = encode_get_tid_req(instanceId, request); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 224 | return {rc, requestMsg}; |
| 225 | } |
| 226 | |
| 227 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 228 | { |
| 229 | uint8_t cc = 0; |
| 230 | uint8_t tid = 0; |
| 231 | std::vector<bitfield8_t> types(8); |
| 232 | auto rc = decode_get_tid_resp(responsePtr, payloadLength, &cc, &tid); |
| 233 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 234 | { |
| 235 | std::cerr << "Response Message Error: " |
| 236 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
| 237 | return; |
| 238 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 239 | ordered_json data; |
| 240 | data["Response"] = static_cast<uint32_t>(tid); |
| 241 | pldmtool::helper::DisplayInJson(data); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 242 | } |
| 243 | }; |
| 244 | |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 245 | class GetPLDMCommands : public CommandInterface |
| 246 | { |
| 247 | public: |
| 248 | ~GetPLDMCommands() = default; |
| 249 | GetPLDMCommands() = delete; |
| 250 | GetPLDMCommands(const GetPLDMCommands&) = delete; |
| 251 | GetPLDMCommands(GetPLDMCommands&&) = default; |
| 252 | GetPLDMCommands& operator=(const GetPLDMCommands&) = delete; |
| 253 | GetPLDMCommands& operator=(GetPLDMCommands&&) = default; |
| 254 | |
| 255 | explicit GetPLDMCommands(const char* type, const char* name, |
| 256 | CLI::App* app) : |
| 257 | CommandInterface(type, name, app) |
| 258 | { |
| 259 | app->add_option("-t,--type", pldmType, "pldm supported type") |
| 260 | ->required() |
| 261 | ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case)); |
| 262 | } |
| 263 | |
| 264 | std::pair<int, std::vector<uint8_t>> createRequestMsg() override |
| 265 | { |
| 266 | std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr) + |
| 267 | PLDM_GET_COMMANDS_REQ_BYTES); |
| 268 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 269 | ver32_t version{0xFF, 0xFF, 0xFF, 0xFF}; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 270 | auto rc = encode_get_commands_req(instanceId, pldmType, version, |
| 271 | request); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 272 | return {rc, requestMsg}; |
| 273 | } |
| 274 | |
| 275 | void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override |
| 276 | { |
| 277 | uint8_t cc = 0; |
| 278 | std::vector<bitfield8_t> cmdTypes(32); |
| 279 | auto rc = decode_get_commands_resp(responsePtr, payloadLength, &cc, |
| 280 | cmdTypes.data()); |
| 281 | if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS) |
| 282 | { |
| 283 | std::cerr << "Response Message Error: " |
| 284 | << "rc=" << rc << ",cc=" << (int)cc << "\n"; |
| 285 | return; |
| 286 | } |
| 287 | printPldmCommands(cmdTypes, pldmType); |
| 288 | } |
| 289 | |
| 290 | private: |
| 291 | pldm_supported_types pldmType; |
| 292 | |
| 293 | template <typename CommandMap> |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 294 | void printCommand(CommandMap& commandMap, int i, ordered_json& jarray) |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 295 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 296 | auto it = std::find_if(commandMap.begin(), commandMap.end(), |
| 297 | [i](const auto& typePair) { |
| 298 | return typePair.second == i; |
| 299 | }); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 300 | if (it != commandMap.end()) |
| 301 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 302 | jarray["PLDM Command Code"] = i; |
| 303 | jarray["PLDM Command"] = it->first; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | void printPldmCommands(std::vector<bitfield8_t>& cmdTypes, |
| 308 | pldm_supported_types pldmType) |
| 309 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 310 | ordered_json output; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 311 | for (int i = 0; i < PLDM_MAX_CMDS_PER_TYPE; i++) |
| 312 | { |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 313 | ordered_json cmdinfo; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 314 | bitfield8_t b = cmdTypes[i / 8]; |
| 315 | if (b.byte & (1 << i % 8)) |
| 316 | { |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 317 | switch (pldmType) |
| 318 | { |
| 319 | case PLDM_BASE: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 320 | printCommand(pldmBaseCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 321 | break; |
| 322 | case PLDM_PLATFORM: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 323 | printCommand(pldmPlatformCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 324 | break; |
| 325 | case PLDM_BIOS: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 326 | printCommand(pldmBiosCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 327 | break; |
| 328 | case PLDM_FRU: |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 329 | printCommand(pldmFruCmds, i, cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 330 | break; |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 331 | case PLDM_OEM: |
Pavithra Barithaya | 6f4e904 | 2020-04-20 23:33:46 -0500 | [diff] [blame] | 332 | #ifdef OEM_IBM |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 333 | printCommand(pldmIBMHostCmds, i, cmdinfo); |
| 334 | printCommand(pldmIBMFileIOCmds, i, cmdinfo); |
Pavithra Barithaya | 6f4e904 | 2020-04-20 23:33:46 -0500 | [diff] [blame] | 335 | #endif |
Sridevi Ramesh | 45e5254 | 2020-04-03 07:54:18 -0500 | [diff] [blame] | 336 | break; |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 337 | default: |
| 338 | break; |
| 339 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 340 | output.emplace_back(cmdinfo); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 341 | } |
| 342 | } |
Sridevi Ramesh | ca4a815 | 2020-08-11 09:26:19 -0500 | [diff] [blame] | 343 | pldmtool::helper::DisplayInJson(output); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 344 | } |
| 345 | }; |
| 346 | |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 347 | void registerCommand(CLI::App& app) |
| 348 | { |
| 349 | auto base = app.add_subcommand("base", "base type command"); |
| 350 | base->require_subcommand(1); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 351 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 352 | auto getPLDMTypes = base->add_subcommand("GetPLDMTypes", |
| 353 | "get pldm supported types"); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 354 | commands.push_back( |
| 355 | std::make_unique<GetPLDMTypes>("base", "GetPLDMTypes", getPLDMTypes)); |
| 356 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 357 | auto getPLDMVersion = base->add_subcommand("GetPLDMVersion", |
| 358 | "get version of a certain type"); |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 359 | commands.push_back(std::make_unique<GetPLDMVersion>( |
| 360 | "base", "GetPLDMVersion", getPLDMVersion)); |
Sridevi Ramesh | add56f0 | 2020-01-20 23:44:22 -0600 | [diff] [blame] | 361 | |
| 362 | auto getPLDMTID = base->add_subcommand("GetTID", "get Terminus ID (TID)"); |
| 363 | commands.push_back(std::make_unique<GetTID>("base", "GetTID", getPLDMTID)); |
Sridevi Ramesh | 66294d3 | 2020-02-21 03:52:07 -0600 | [diff] [blame] | 364 | |
| 365 | auto getPLDMCommands = base->add_subcommand( |
| 366 | "GetPLDMCommands", "get supported commands of pldm type"); |
| 367 | commands.push_back(std::make_unique<GetPLDMCommands>( |
| 368 | "base", "GetPLDMCommands", getPLDMCommands)); |
Lakshminarayana R. Kammath | 58229b2 | 2019-08-09 06:30:04 -0500 | [diff] [blame] | 369 | } |
John Wang | 58a0e06 | 2019-11-08 15:38:15 +0800 | [diff] [blame] | 370 | |
| 371 | } // namespace base |
| 372 | } // namespace pldmtool |