blob: 4a3ae88dc00fb67b60cec0971595a4bf8960a87d [file] [log] [blame]
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -05001#include "pldm_base_cmd.hpp"
2
George Liu6492f522020-06-16 10:34:05 +08003#include "pldm_cmd_helper.hpp"
4
George Liuc453e162022-12-21 17:16:23 +08005#include <libpldm/utils.h>
6
Sridevi Ramesh45e52542020-04-03 07:54:18 -05007#ifdef OEM_IBM
Andrew Jeffery21f128d2024-01-15 15:34:26 +10308#include <libpldm/oem/ibm/file_io.h>
9#include <libpldm/oem/ibm/host.h>
Sridevi Ramesh45e52542020-04-03 07:54:18 -050010#endif
11
Sridevi Rameshca4a8152020-08-11 09:26:19 -050012#include <string>
13
John Wang58a0e062019-11-08 15:38:15 +080014namespace pldmtool
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050015{
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050016
John Wang58a0e062019-11-08 15:38:15 +080017namespace base
Lakshminarayana R. Kammath27693a42019-06-24 00:51:47 -050018{
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050019
John Wang58a0e062019-11-08 15:38:15 +080020namespace
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -050021{
John Wang58a0e062019-11-08 15:38:15 +080022
23using namespace pldmtool::helper;
24
25std::vector<std::unique_ptr<CommandInterface>> commands;
26const std::map<const char*, pldm_supported_types> pldmTypes{
Sridevi Ramesh45e52542020-04-03 07:54:18 -050027 {"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 Wang58a0e062019-11-08 15:38:15 +080032};
33
Sridevi Ramesh66294d32020-02-21 03:52:07 -060034const 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
40const std::map<const char*, pldm_bios_commands> pldmBiosCmds{
41 {"GetBIOSTable", PLDM_GET_BIOS_TABLE},
Sridevi Ramesh8fb11c92021-06-08 08:45:01 -050042 {"SetBIOSTable", PLDM_SET_BIOS_TABLE},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060043 {"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
49const std::map<const char*, pldm_platform_commands> pldmPlatformCmds{
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000050 {"GetTerminusUID", PLDM_GET_TERMINUS_UID},
51 {"SetEventReceiver", PLDM_SET_EVENT_RECEIVER},
52 {"GetEventReceiver", PLDM_GET_EVENT_RECEIVER},
53 {"PlatformEventMessage", PLDM_PLATFORM_EVENT_MESSAGE},
54 {"PollForPlatformEventMessage", PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE},
55 {"EventMessageSupported", PLDM_EVENT_MESSAGE_SUPPORTED},
56 {"EventMessageBufferSize", PLDM_EVENT_MESSAGE_BUFFER_SIZE},
57 {"SetNumericSensorEnable", PLDM_SET_NUMERIC_SENSOR_ENABLE},
58 {"GetSensorReading", PLDM_GET_SENSOR_READING},
59 {"GetSensorThresholds", PLDM_GET_SENSOR_THRESHOLDS},
60 {"SetSensorThresholds", PLDM_SET_SENSOR_THRESHOLDS},
61 {"RestoreSensorThresholds", PLDM_RESTORE_SENSOR_THRESHOLDS},
62 {"GetSensorHysteresis", PLDM_GET_SENSOR_HYSTERESIS},
63 {"SetSensorHysteresis", PLDM_SET_SENSOR_HYSTERESIS},
64 {"InitNumericSensor", PLDM_INIT_NUMERIC_SENSOR},
65 {"SetStateSensorEnables", PLDM_SET_STATE_SENSOR_ENABLES},
66 {"GetStateSensorReadings", PLDM_GET_STATE_SENSOR_READINGS},
67 {"InitStateSensor", PLDM_INIT_STATE_SENSOR},
68 {"SetNumericEffecterEnable", PLDM_SET_NUMERIC_EFFECTER_ENABLE},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060069 {"SetNumericEffecterValue", PLDM_SET_NUMERIC_EFFECTER_VALUE},
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000070 {"GetNumericEffecterValue", PLDM_GET_NUMERIC_EFFECTER_VALUE},
71 {"SetStateEffecterEnables", PLDM_SET_STATE_EFFECTER_ENABLES},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060072 {"SetStateEffecterStates", PLDM_SET_STATE_EFFECTER_STATES},
Tal Yacobi8570fcc2024-05-28 11:11:23 +030073 {"GetStateEffecterStates", PLDM_GET_STATE_EFFECTER_STATES},
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000074 {"GetPLDMEventLogInfo", PLDM_GET_PLDM_EVENT_LOG_INFO},
75 {"EnablePLDMEventLogging", PLDM_ENABLE_PLDM_EVENT_LOGGING},
76 {"ClearPLDMEventLog", PLDM_CLEAR_PLDM_EVENT_LOG},
77 {"GetPLDMEventLogTimestamp", PLDM_GET_PLDM_EVENT_LOG_TIMESTAMP},
78 {"SetPLDMEventLogTimestamp", PLDM_SET_PLDM_EVENT_LOG_TIMESTAMP},
79 {"ReadPLDMEventLog", PLDM_READ_PLDM_EVENT_LOG},
80 {"GetPLDMEventLogPolicyInfo", PLDM_GET_PLDM_EVENT_LOG_POLICY_INFO},
81 {"SetPLDMEventLogPolicy", PLDM_SET_PLDM_EVENT_LOG_POLICY},
82 {"FindPLDMEventLogEntry", PLDM_FIND_PLDM_EVENT_LOG_ENTRY},
83 {"GetPDRRepositoryInfo", PLDM_GET_PDR_REPOSITORY_INFO},
Sridevi Ramesh8fb11c92021-06-08 08:45:01 -050084 {"GetPDR", PLDM_GET_PDR},
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000085 {"FindPDR", PLDM_FIND_PDR},
86 {"RunInitAgent", PLDM_RUN_INIT_AGENT},
87 {"GetPDRRepositorySignature", PLDM_GET_PDR_REPOSITORY_SIGNATURE}};
Sridevi Ramesh66294d32020-02-21 03:52:07 -060088
89const std::map<const char*, pldm_fru_commands> pldmFruCmds{
90 {"GetFRURecordTableMetadata", PLDM_GET_FRU_RECORD_TABLE_METADATA},
John Wang5bdde3a2020-06-16 15:02:33 +080091 {"GetFRURecordTable", PLDM_GET_FRU_RECORD_TABLE},
92 {"GetFRURecordByOption", PLDM_GET_FRU_RECORD_BY_OPTION}};
Sridevi Ramesh66294d32020-02-21 03:52:07 -060093
Sridevi Ramesh45e52542020-04-03 07:54:18 -050094#ifdef OEM_IBM
95const std::map<const char*, pldm_host_commands> pldmIBMHostCmds{
96 {"GetAlertStatus", PLDM_HOST_GET_ALERT_STATUS}};
97
98const std::map<const char*, pldm_fileio_commands> pldmIBMFileIOCmds{
99 {"GetFileTable", PLDM_GET_FILE_TABLE},
100 {"ReadFile", PLDM_READ_FILE},
101 {"WriteFile", PLDM_WRITE_FILE},
102 {"ReadFileInToMemory", PLDM_READ_FILE_INTO_MEMORY},
103 {"WriteFileFromMemory", PLDM_WRITE_FILE_FROM_MEMORY},
104 {"ReadFileByTypeIntoMemory", PLDM_READ_FILE_BY_TYPE_INTO_MEMORY},
105 {"WriteFileByTypeFromMemory", PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY},
106 {"NewFileAvailable", PLDM_NEW_FILE_AVAILABLE},
107 {"ReadFileByType", PLDM_READ_FILE_BY_TYPE},
108 {"WriteFileByType", PLDM_WRITE_FILE_BY_TYPE},
109 {"FileAck", PLDM_FILE_ACK}};
110#endif
111
John Wang58a0e062019-11-08 15:38:15 +0800112} // namespace
113
114class GetPLDMTypes : public CommandInterface
115{
116 public:
117 ~GetPLDMTypes() = default;
118 GetPLDMTypes() = delete;
119 GetPLDMTypes(const GetPLDMTypes&) = delete;
120 GetPLDMTypes(GetPLDMTypes&&) = default;
121 GetPLDMTypes& operator=(const GetPLDMTypes&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500122 GetPLDMTypes& operator=(GetPLDMTypes&&) = delete;
John Wang58a0e062019-11-08 15:38:15 +0800123
124 using CommandInterface::CommandInterface;
125
126 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500127 {
John Wang58a0e062019-11-08 15:38:15 +0800128 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
129 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600130 auto rc = encode_get_types_req(instanceId, request);
John Wang58a0e062019-11-08 15:38:15 +0800131 return {rc, requestMsg};
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500132 }
133
John Wang58a0e062019-11-08 15:38:15 +0800134 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500135 {
John Wang58a0e062019-11-08 15:38:15 +0800136 uint8_t cc = 0;
137 std::vector<bitfield8_t> types(8);
138 auto rc = decode_get_types_resp(responsePtr, payloadLength, &cc,
139 types.data());
140 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
141 {
142 std::cerr << "Response Message Error: "
Sampa Misraaa8ae722019-12-12 03:20:40 -0600143 << "rc=" << rc << ",cc=" << (int)cc << "\n";
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500144 return;
John Wang58a0e062019-11-08 15:38:15 +0800145 }
146
147 printPldmTypes(types);
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500148 }
149
John Wang58a0e062019-11-08 15:38:15 +0800150 private:
151 void printPldmTypes(std::vector<bitfield8_t>& types)
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500152 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500153 ordered_json data;
154 ordered_json jarray;
John Wang58a0e062019-11-08 15:38:15 +0800155 for (int i = 0; i < PLDM_MAX_TYPES; i++)
156 {
157 bitfield8_t b = types[i / 8];
158 if (b.byte & (1 << i % 8))
159 {
Patrick Williamsa6756622023-10-20 11:19:15 -0500160 auto it = std::find_if(
161 pldmTypes.begin(), pldmTypes.end(),
162 [i](const auto& typePair) { return typePair.second == i; });
John Wang58a0e062019-11-08 15:38:15 +0800163 if (it != pldmTypes.end())
164 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500165 jarray["PLDM Type"] = it->first;
166 jarray["PLDM Type Code"] = i;
167 data.emplace_back(jarray);
John Wang58a0e062019-11-08 15:38:15 +0800168 }
169 }
170 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500171 pldmtool::helper::DisplayInJson(data);
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500172 }
John Wang58a0e062019-11-08 15:38:15 +0800173};
174
175class GetPLDMVersion : public CommandInterface
176{
177 public:
178 ~GetPLDMVersion() = default;
179 GetPLDMVersion() = delete;
180 GetPLDMVersion(const GetPLDMVersion&) = delete;
181 GetPLDMVersion(GetPLDMVersion&&) = default;
182 GetPLDMVersion& operator=(const GetPLDMVersion&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500183 GetPLDMVersion& operator=(GetPLDMVersion&&) = delete;
John Wang58a0e062019-11-08 15:38:15 +0800184
185 explicit GetPLDMVersion(const char* type, const char* name, CLI::App* app) :
186 CommandInterface(type, name, app)
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500187 {
John Wang58a0e062019-11-08 15:38:15 +0800188 app->add_option("-t,--type", pldmType, "pldm supported type")
189 ->required()
190 ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case));
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500191 }
John Wang58a0e062019-11-08 15:38:15 +0800192 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
193 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400194 std::vector<uint8_t> requestMsg(
195 sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES);
John Wang58a0e062019-11-08 15:38:15 +0800196 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
197
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600198 auto rc = encode_get_version_req(instanceId, 0, PLDM_GET_FIRSTPART,
199 pldmType, request);
John Wang58a0e062019-11-08 15:38:15 +0800200 return {rc, requestMsg};
201 }
202
203 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
204 {
205 uint8_t cc = 0, transferFlag = 0;
206 uint32_t transferHandle = 0;
207 ver32_t version;
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400208 auto rc =
209 decode_get_version_resp(responsePtr, payloadLength, &cc,
210 &transferHandle, &transferFlag, &version);
John Wang58a0e062019-11-08 15:38:15 +0800211 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
212 {
213 std::cerr << "Response Message Error: "
Sampa Misraaa8ae722019-12-12 03:20:40 -0600214 << "rc=" << rc << ",cc=" << (int)cc << "\n";
John Wang58a0e062019-11-08 15:38:15 +0800215 return;
216 }
217 char buffer[16] = {0};
218 ver2str(&version, buffer, sizeof(buffer));
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500219 ordered_json data;
Patrick Williamsa6756622023-10-20 11:19:15 -0500220 auto it = std::find_if(
221 pldmTypes.begin(), pldmTypes.end(),
222 [&](const auto& typePair) { return typePair.second == pldmType; });
John Wang58a0e062019-11-08 15:38:15 +0800223
224 if (it != pldmTypes.end())
225 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500226 data["Response"] = buffer;
John Wang58a0e062019-11-08 15:38:15 +0800227 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500228 pldmtool::helper::DisplayInJson(data);
John Wang58a0e062019-11-08 15:38:15 +0800229 }
230
231 private:
232 pldm_supported_types pldmType;
233};
234
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600235class GetTID : public CommandInterface
236{
237 public:
238 ~GetTID() = default;
239 GetTID() = delete;
240 GetTID(const GetTID&) = delete;
241 GetTID(GetTID&&) = default;
242 GetTID& operator=(const GetTID&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500243 GetTID& operator=(GetTID&&) = delete;
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600244
245 using CommandInterface::CommandInterface;
246
247 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
248 {
249 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
250 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600251 auto rc = encode_get_tid_req(instanceId, request);
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600252 return {rc, requestMsg};
253 }
254
255 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
256 {
257 uint8_t cc = 0;
258 uint8_t tid = 0;
259 std::vector<bitfield8_t> types(8);
260 auto rc = decode_get_tid_resp(responsePtr, payloadLength, &cc, &tid);
261 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
262 {
263 std::cerr << "Response Message Error: "
264 << "rc=" << rc << ",cc=" << (int)cc << "\n";
265 return;
266 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500267 ordered_json data;
268 data["Response"] = static_cast<uint32_t>(tid);
269 pldmtool::helper::DisplayInJson(data);
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600270 }
271};
272
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600273class GetPLDMCommands : public CommandInterface
274{
275 public:
276 ~GetPLDMCommands() = default;
277 GetPLDMCommands() = delete;
278 GetPLDMCommands(const GetPLDMCommands&) = delete;
279 GetPLDMCommands(GetPLDMCommands&&) = default;
280 GetPLDMCommands& operator=(const GetPLDMCommands&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500281 GetPLDMCommands& operator=(GetPLDMCommands&&) = delete;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600282
283 explicit GetPLDMCommands(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400284 CLI::App* app) : CommandInterface(type, name, app)
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600285 {
286 app->add_option("-t,--type", pldmType, "pldm supported type")
287 ->required()
288 ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case));
Thu Nguyen6c83d3b2024-06-22 13:06:12 +0000289 app->add_option(
290 "-d,--data", inputVersion,
291 "Set PLDM type version. Which is got from GetPLDMVersion\n"
292 "eg: version 1.1.0 then data will be `0xf1 0xf1 0xf0 0x00`");
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600293 }
294
295 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
296 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400297 std::vector<uint8_t> requestMsg(
298 sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600299 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
300 ver32_t version{0xFF, 0xFF, 0xFF, 0xFF};
Thu Nguyen6c83d3b2024-06-22 13:06:12 +0000301 if (inputVersion.size() != 0)
302 {
303 if (inputVersion.size() != 4)
304 {
305 std::cerr << "Invalid version format. "
306 << "\n";
307 }
308 else
309 {
310 version.major = inputVersion[3];
311 version.minor = inputVersion[2];
312 version.update = inputVersion[1];
313 version.alpha = inputVersion[0];
314 }
315 }
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400316 auto rc =
317 encode_get_commands_req(instanceId, pldmType, version, request);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600318 return {rc, requestMsg};
319 }
320
321 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
322 {
323 uint8_t cc = 0;
324 std::vector<bitfield8_t> cmdTypes(32);
325 auto rc = decode_get_commands_resp(responsePtr, payloadLength, &cc,
326 cmdTypes.data());
327 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
328 {
329 std::cerr << "Response Message Error: "
330 << "rc=" << rc << ",cc=" << (int)cc << "\n";
331 return;
332 }
333 printPldmCommands(cmdTypes, pldmType);
334 }
335
336 private:
337 pldm_supported_types pldmType;
Thu Nguyen6c83d3b2024-06-22 13:06:12 +0000338 std::vector<uint8_t> inputVersion;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600339
340 template <typename CommandMap>
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500341 void printCommand(CommandMap& commandMap, int i, ordered_json& jarray)
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600342 {
Patrick Williamsa6756622023-10-20 11:19:15 -0500343 auto it = std::find_if(
344 commandMap.begin(), commandMap.end(),
345 [i](const auto& typePair) { return typePair.second == i; });
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600346 if (it != commandMap.end())
347 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500348 jarray["PLDM Command Code"] = i;
349 jarray["PLDM Command"] = it->first;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600350 }
351 }
352
353 void printPldmCommands(std::vector<bitfield8_t>& cmdTypes,
354 pldm_supported_types pldmType)
355 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500356 ordered_json output;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600357 for (int i = 0; i < PLDM_MAX_CMDS_PER_TYPE; i++)
358 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500359 ordered_json cmdinfo;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600360 bitfield8_t b = cmdTypes[i / 8];
361 if (b.byte & (1 << i % 8))
362 {
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600363 switch (pldmType)
364 {
365 case PLDM_BASE:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500366 printCommand(pldmBaseCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600367 break;
368 case PLDM_PLATFORM:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500369 printCommand(pldmPlatformCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600370 break;
371 case PLDM_BIOS:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500372 printCommand(pldmBiosCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600373 break;
374 case PLDM_FRU:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500375 printCommand(pldmFruCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600376 break;
Sridevi Ramesh45e52542020-04-03 07:54:18 -0500377 case PLDM_OEM:
Pavithra Barithaya6f4e9042020-04-20 23:33:46 -0500378#ifdef OEM_IBM
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500379 printCommand(pldmIBMHostCmds, i, cmdinfo);
380 printCommand(pldmIBMFileIOCmds, i, cmdinfo);
Pavithra Barithaya6f4e9042020-04-20 23:33:46 -0500381#endif
Sridevi Ramesh45e52542020-04-03 07:54:18 -0500382 break;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600383 default:
384 break;
385 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500386 output.emplace_back(cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600387 }
388 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500389 pldmtool::helper::DisplayInJson(output);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600390 }
391};
392
John Wang58a0e062019-11-08 15:38:15 +0800393void registerCommand(CLI::App& app)
394{
395 auto base = app.add_subcommand("base", "base type command");
396 base->require_subcommand(1);
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600397
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400398 auto getPLDMTypes =
399 base->add_subcommand("GetPLDMTypes", "get pldm supported types");
John Wang58a0e062019-11-08 15:38:15 +0800400 commands.push_back(
401 std::make_unique<GetPLDMTypes>("base", "GetPLDMTypes", getPLDMTypes));
402
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400403 auto getPLDMVersion =
404 base->add_subcommand("GetPLDMVersion", "get version of a certain type");
John Wang58a0e062019-11-08 15:38:15 +0800405 commands.push_back(std::make_unique<GetPLDMVersion>(
406 "base", "GetPLDMVersion", getPLDMVersion));
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600407
408 auto getPLDMTID = base->add_subcommand("GetTID", "get Terminus ID (TID)");
409 commands.push_back(std::make_unique<GetTID>("base", "GetTID", getPLDMTID));
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600410
411 auto getPLDMCommands = base->add_subcommand(
412 "GetPLDMCommands", "get supported commands of pldm type");
413 commands.push_back(std::make_unique<GetPLDMCommands>(
414 "base", "GetPLDMCommands", getPLDMCommands));
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500415}
John Wang58a0e062019-11-08 15:38:15 +0800416
417} // namespace base
418} // namespace pldmtool