blob: 2acbbe1aab15b3e6100316e498d5cd3aca051318 [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{
Thu Nguyenb8e3b0d2024-11-21 02:05:20 +000035 {"SetTID", PLDM_SET_TID},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060036 {"GetTID", PLDM_GET_TID},
37 {"GetPLDMVersion", PLDM_GET_PLDM_VERSION},
38 {"GetPLDMTypes", PLDM_GET_PLDM_TYPES},
Thu Nguyenb8e3b0d2024-11-21 02:05:20 +000039 {"GetPLDMCommands", PLDM_GET_PLDM_COMMANDS},
40 {"SelectPLDMVersion", PLDM_SELECT_PLDM_VERSION},
41 {"NegotiateTransferParameters", PLDM_NEGOTIATE_TRANSFER_PARAMETERS},
42 {"MultipartSend", PLDM_MULTIPART_SEND},
43 {"MultipartReceive", PLDM_MULTIPART_RECEIVE},
44 {"GetMultipartTransferSupport", PLDM_GET_MULTIPART_TRANSFER_SUPPORT}};
Sridevi Ramesh66294d32020-02-21 03:52:07 -060045
46const std::map<const char*, pldm_bios_commands> pldmBiosCmds{
47 {"GetBIOSTable", PLDM_GET_BIOS_TABLE},
Sridevi Ramesh8fb11c92021-06-08 08:45:01 -050048 {"SetBIOSTable", PLDM_SET_BIOS_TABLE},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060049 {"SetBIOSAttributeCurrentValue", PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE},
50 {"GetBIOSAttributeCurrentValueByHandle",
51 PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE},
52 {"GetDateTime", PLDM_GET_DATE_TIME},
53 {"SetDateTime", PLDM_SET_DATE_TIME}};
54
55const std::map<const char*, pldm_platform_commands> pldmPlatformCmds{
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000056 {"GetTerminusUID", PLDM_GET_TERMINUS_UID},
57 {"SetEventReceiver", PLDM_SET_EVENT_RECEIVER},
58 {"GetEventReceiver", PLDM_GET_EVENT_RECEIVER},
59 {"PlatformEventMessage", PLDM_PLATFORM_EVENT_MESSAGE},
60 {"PollForPlatformEventMessage", PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE},
61 {"EventMessageSupported", PLDM_EVENT_MESSAGE_SUPPORTED},
62 {"EventMessageBufferSize", PLDM_EVENT_MESSAGE_BUFFER_SIZE},
63 {"SetNumericSensorEnable", PLDM_SET_NUMERIC_SENSOR_ENABLE},
64 {"GetSensorReading", PLDM_GET_SENSOR_READING},
65 {"GetSensorThresholds", PLDM_GET_SENSOR_THRESHOLDS},
66 {"SetSensorThresholds", PLDM_SET_SENSOR_THRESHOLDS},
67 {"RestoreSensorThresholds", PLDM_RESTORE_SENSOR_THRESHOLDS},
68 {"GetSensorHysteresis", PLDM_GET_SENSOR_HYSTERESIS},
69 {"SetSensorHysteresis", PLDM_SET_SENSOR_HYSTERESIS},
70 {"InitNumericSensor", PLDM_INIT_NUMERIC_SENSOR},
71 {"SetStateSensorEnables", PLDM_SET_STATE_SENSOR_ENABLES},
72 {"GetStateSensorReadings", PLDM_GET_STATE_SENSOR_READINGS},
73 {"InitStateSensor", PLDM_INIT_STATE_SENSOR},
74 {"SetNumericEffecterEnable", PLDM_SET_NUMERIC_EFFECTER_ENABLE},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060075 {"SetNumericEffecterValue", PLDM_SET_NUMERIC_EFFECTER_VALUE},
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000076 {"GetNumericEffecterValue", PLDM_GET_NUMERIC_EFFECTER_VALUE},
77 {"SetStateEffecterEnables", PLDM_SET_STATE_EFFECTER_ENABLES},
Sridevi Ramesh66294d32020-02-21 03:52:07 -060078 {"SetStateEffecterStates", PLDM_SET_STATE_EFFECTER_STATES},
Tal Yacobi8570fcc2024-05-28 11:11:23 +030079 {"GetStateEffecterStates", PLDM_GET_STATE_EFFECTER_STATES},
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000080 {"GetPLDMEventLogInfo", PLDM_GET_PLDM_EVENT_LOG_INFO},
81 {"EnablePLDMEventLogging", PLDM_ENABLE_PLDM_EVENT_LOGGING},
82 {"ClearPLDMEventLog", PLDM_CLEAR_PLDM_EVENT_LOG},
83 {"GetPLDMEventLogTimestamp", PLDM_GET_PLDM_EVENT_LOG_TIMESTAMP},
84 {"SetPLDMEventLogTimestamp", PLDM_SET_PLDM_EVENT_LOG_TIMESTAMP},
85 {"ReadPLDMEventLog", PLDM_READ_PLDM_EVENT_LOG},
86 {"GetPLDMEventLogPolicyInfo", PLDM_GET_PLDM_EVENT_LOG_POLICY_INFO},
87 {"SetPLDMEventLogPolicy", PLDM_SET_PLDM_EVENT_LOG_POLICY},
88 {"FindPLDMEventLogEntry", PLDM_FIND_PLDM_EVENT_LOG_ENTRY},
89 {"GetPDRRepositoryInfo", PLDM_GET_PDR_REPOSITORY_INFO},
Sridevi Ramesh8fb11c92021-06-08 08:45:01 -050090 {"GetPDR", PLDM_GET_PDR},
Thu Nguyenf1c0e7c2024-11-20 15:50:21 +000091 {"FindPDR", PLDM_FIND_PDR},
92 {"RunInitAgent", PLDM_RUN_INIT_AGENT},
93 {"GetPDRRepositorySignature", PLDM_GET_PDR_REPOSITORY_SIGNATURE}};
Sridevi Ramesh66294d32020-02-21 03:52:07 -060094
95const std::map<const char*, pldm_fru_commands> pldmFruCmds{
96 {"GetFRURecordTableMetadata", PLDM_GET_FRU_RECORD_TABLE_METADATA},
John Wang5bdde3a2020-06-16 15:02:33 +080097 {"GetFRURecordTable", PLDM_GET_FRU_RECORD_TABLE},
98 {"GetFRURecordByOption", PLDM_GET_FRU_RECORD_BY_OPTION}};
Sridevi Ramesh66294d32020-02-21 03:52:07 -060099
Sridevi Ramesh45e52542020-04-03 07:54:18 -0500100#ifdef OEM_IBM
101const std::map<const char*, pldm_host_commands> pldmIBMHostCmds{
102 {"GetAlertStatus", PLDM_HOST_GET_ALERT_STATUS}};
103
104const std::map<const char*, pldm_fileio_commands> pldmIBMFileIOCmds{
105 {"GetFileTable", PLDM_GET_FILE_TABLE},
106 {"ReadFile", PLDM_READ_FILE},
107 {"WriteFile", PLDM_WRITE_FILE},
108 {"ReadFileInToMemory", PLDM_READ_FILE_INTO_MEMORY},
109 {"WriteFileFromMemory", PLDM_WRITE_FILE_FROM_MEMORY},
110 {"ReadFileByTypeIntoMemory", PLDM_READ_FILE_BY_TYPE_INTO_MEMORY},
111 {"WriteFileByTypeFromMemory", PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY},
112 {"NewFileAvailable", PLDM_NEW_FILE_AVAILABLE},
113 {"ReadFileByType", PLDM_READ_FILE_BY_TYPE},
114 {"WriteFileByType", PLDM_WRITE_FILE_BY_TYPE},
115 {"FileAck", PLDM_FILE_ACK}};
116#endif
117
John Wang58a0e062019-11-08 15:38:15 +0800118} // namespace
119
120class GetPLDMTypes : public CommandInterface
121{
122 public:
123 ~GetPLDMTypes() = default;
124 GetPLDMTypes() = delete;
125 GetPLDMTypes(const GetPLDMTypes&) = delete;
126 GetPLDMTypes(GetPLDMTypes&&) = default;
127 GetPLDMTypes& operator=(const GetPLDMTypes&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500128 GetPLDMTypes& operator=(GetPLDMTypes&&) = delete;
John Wang58a0e062019-11-08 15:38:15 +0800129
130 using CommandInterface::CommandInterface;
131
132 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500133 {
John Wang58a0e062019-11-08 15:38:15 +0800134 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
135 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600136 auto rc = encode_get_types_req(instanceId, request);
John Wang58a0e062019-11-08 15:38:15 +0800137 return {rc, requestMsg};
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500138 }
139
John Wang58a0e062019-11-08 15:38:15 +0800140 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500141 {
John Wang58a0e062019-11-08 15:38:15 +0800142 uint8_t cc = 0;
143 std::vector<bitfield8_t> types(8);
144 auto rc = decode_get_types_resp(responsePtr, payloadLength, &cc,
145 types.data());
146 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
147 {
148 std::cerr << "Response Message Error: "
Sampa Misraaa8ae722019-12-12 03:20:40 -0600149 << "rc=" << rc << ",cc=" << (int)cc << "\n";
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500150 return;
John Wang58a0e062019-11-08 15:38:15 +0800151 }
152
153 printPldmTypes(types);
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500154 }
155
John Wang58a0e062019-11-08 15:38:15 +0800156 private:
157 void printPldmTypes(std::vector<bitfield8_t>& types)
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500158 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500159 ordered_json data;
160 ordered_json jarray;
John Wang58a0e062019-11-08 15:38:15 +0800161 for (int i = 0; i < PLDM_MAX_TYPES; i++)
162 {
163 bitfield8_t b = types[i / 8];
164 if (b.byte & (1 << i % 8))
165 {
Patrick Williamsa6756622023-10-20 11:19:15 -0500166 auto it = std::find_if(
167 pldmTypes.begin(), pldmTypes.end(),
168 [i](const auto& typePair) { return typePair.second == i; });
John Wang58a0e062019-11-08 15:38:15 +0800169 if (it != pldmTypes.end())
170 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500171 jarray["PLDM Type"] = it->first;
172 jarray["PLDM Type Code"] = i;
173 data.emplace_back(jarray);
John Wang58a0e062019-11-08 15:38:15 +0800174 }
175 }
176 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500177 pldmtool::helper::DisplayInJson(data);
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500178 }
John Wang58a0e062019-11-08 15:38:15 +0800179};
180
181class GetPLDMVersion : public CommandInterface
182{
183 public:
184 ~GetPLDMVersion() = default;
185 GetPLDMVersion() = delete;
186 GetPLDMVersion(const GetPLDMVersion&) = delete;
187 GetPLDMVersion(GetPLDMVersion&&) = default;
188 GetPLDMVersion& operator=(const GetPLDMVersion&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500189 GetPLDMVersion& operator=(GetPLDMVersion&&) = delete;
John Wang58a0e062019-11-08 15:38:15 +0800190
191 explicit GetPLDMVersion(const char* type, const char* name, CLI::App* app) :
192 CommandInterface(type, name, app)
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500193 {
John Wang58a0e062019-11-08 15:38:15 +0800194 app->add_option("-t,--type", pldmType, "pldm supported type")
195 ->required()
196 ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case));
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500197 }
John Wang58a0e062019-11-08 15:38:15 +0800198 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
199 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400200 std::vector<uint8_t> requestMsg(
201 sizeof(pldm_msg_hdr) + PLDM_GET_VERSION_REQ_BYTES);
John Wang58a0e062019-11-08 15:38:15 +0800202 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
203
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600204 auto rc = encode_get_version_req(instanceId, 0, PLDM_GET_FIRSTPART,
205 pldmType, request);
John Wang58a0e062019-11-08 15:38:15 +0800206 return {rc, requestMsg};
207 }
208
209 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
210 {
211 uint8_t cc = 0, transferFlag = 0;
212 uint32_t transferHandle = 0;
213 ver32_t version;
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400214 auto rc =
215 decode_get_version_resp(responsePtr, payloadLength, &cc,
216 &transferHandle, &transferFlag, &version);
John Wang58a0e062019-11-08 15:38:15 +0800217 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
218 {
219 std::cerr << "Response Message Error: "
Sampa Misraaa8ae722019-12-12 03:20:40 -0600220 << "rc=" << rc << ",cc=" << (int)cc << "\n";
John Wang58a0e062019-11-08 15:38:15 +0800221 return;
222 }
223 char buffer[16] = {0};
224 ver2str(&version, buffer, sizeof(buffer));
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500225 ordered_json data;
Patrick Williamsa6756622023-10-20 11:19:15 -0500226 auto it = std::find_if(
227 pldmTypes.begin(), pldmTypes.end(),
228 [&](const auto& typePair) { return typePair.second == pldmType; });
John Wang58a0e062019-11-08 15:38:15 +0800229
230 if (it != pldmTypes.end())
231 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500232 data["Response"] = buffer;
John Wang58a0e062019-11-08 15:38:15 +0800233 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500234 pldmtool::helper::DisplayInJson(data);
John Wang58a0e062019-11-08 15:38:15 +0800235 }
236
237 private:
238 pldm_supported_types pldmType;
239};
240
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600241class GetTID : public CommandInterface
242{
243 public:
244 ~GetTID() = default;
245 GetTID() = delete;
246 GetTID(const GetTID&) = delete;
247 GetTID(GetTID&&) = default;
248 GetTID& operator=(const GetTID&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500249 GetTID& operator=(GetTID&&) = delete;
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600250
251 using CommandInterface::CommandInterface;
252
253 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
254 {
255 std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
256 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
Pavithra Barithayaac3c45a2020-03-05 02:28:26 -0600257 auto rc = encode_get_tid_req(instanceId, request);
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600258 return {rc, requestMsg};
259 }
260
261 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
262 {
263 uint8_t cc = 0;
264 uint8_t tid = 0;
265 std::vector<bitfield8_t> types(8);
266 auto rc = decode_get_tid_resp(responsePtr, payloadLength, &cc, &tid);
267 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
268 {
269 std::cerr << "Response Message Error: "
270 << "rc=" << rc << ",cc=" << (int)cc << "\n";
271 return;
272 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500273 ordered_json data;
274 data["Response"] = static_cast<uint32_t>(tid);
275 pldmtool::helper::DisplayInJson(data);
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600276 }
277};
278
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600279class GetPLDMCommands : public CommandInterface
280{
281 public:
282 ~GetPLDMCommands() = default;
283 GetPLDMCommands() = delete;
284 GetPLDMCommands(const GetPLDMCommands&) = delete;
285 GetPLDMCommands(GetPLDMCommands&&) = default;
286 GetPLDMCommands& operator=(const GetPLDMCommands&) = delete;
Pavithra Barithayaa7dbca52023-07-07 04:19:37 -0500287 GetPLDMCommands& operator=(GetPLDMCommands&&) = delete;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600288
289 explicit GetPLDMCommands(const char* type, const char* name,
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400290 CLI::App* app) : CommandInterface(type, name, app)
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600291 {
292 app->add_option("-t,--type", pldmType, "pldm supported type")
293 ->required()
294 ->transform(CLI::CheckedTransformer(pldmTypes, CLI::ignore_case));
Thu Nguyen6c83d3b2024-06-22 13:06:12 +0000295 app->add_option(
296 "-d,--data", inputVersion,
297 "Set PLDM type version. Which is got from GetPLDMVersion\n"
298 "eg: version 1.1.0 then data will be `0xf1 0xf1 0xf0 0x00`");
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600299 }
300
301 std::pair<int, std::vector<uint8_t>> createRequestMsg() override
302 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400303 std::vector<uint8_t> requestMsg(
304 sizeof(pldm_msg_hdr) + PLDM_GET_COMMANDS_REQ_BYTES);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600305 auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
306 ver32_t version{0xFF, 0xFF, 0xFF, 0xFF};
Thu Nguyen6c83d3b2024-06-22 13:06:12 +0000307 if (inputVersion.size() != 0)
308 {
309 if (inputVersion.size() != 4)
310 {
311 std::cerr << "Invalid version format. "
312 << "\n";
313 }
314 else
315 {
316 version.major = inputVersion[3];
317 version.minor = inputVersion[2];
318 version.update = inputVersion[1];
319 version.alpha = inputVersion[0];
320 }
321 }
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400322 auto rc =
323 encode_get_commands_req(instanceId, pldmType, version, request);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600324 return {rc, requestMsg};
325 }
326
327 void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
328 {
329 uint8_t cc = 0;
330 std::vector<bitfield8_t> cmdTypes(32);
331 auto rc = decode_get_commands_resp(responsePtr, payloadLength, &cc,
332 cmdTypes.data());
333 if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
334 {
335 std::cerr << "Response Message Error: "
336 << "rc=" << rc << ",cc=" << (int)cc << "\n";
337 return;
338 }
339 printPldmCommands(cmdTypes, pldmType);
340 }
341
342 private:
343 pldm_supported_types pldmType;
Thu Nguyen6c83d3b2024-06-22 13:06:12 +0000344 std::vector<uint8_t> inputVersion;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600345
346 template <typename CommandMap>
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500347 void printCommand(CommandMap& commandMap, int i, ordered_json& jarray)
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600348 {
Patrick Williamsa6756622023-10-20 11:19:15 -0500349 auto it = std::find_if(
350 commandMap.begin(), commandMap.end(),
351 [i](const auto& typePair) { return typePair.second == i; });
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600352 if (it != commandMap.end())
353 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500354 jarray["PLDM Command Code"] = i;
355 jarray["PLDM Command"] = it->first;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600356 }
357 }
358
359 void printPldmCommands(std::vector<bitfield8_t>& cmdTypes,
360 pldm_supported_types pldmType)
361 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500362 ordered_json output;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600363 for (int i = 0; i < PLDM_MAX_CMDS_PER_TYPE; i++)
364 {
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500365 ordered_json cmdinfo;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600366 bitfield8_t b = cmdTypes[i / 8];
367 if (b.byte & (1 << i % 8))
368 {
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600369 switch (pldmType)
370 {
371 case PLDM_BASE:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500372 printCommand(pldmBaseCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600373 break;
374 case PLDM_PLATFORM:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500375 printCommand(pldmPlatformCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600376 break;
377 case PLDM_BIOS:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500378 printCommand(pldmBiosCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600379 break;
380 case PLDM_FRU:
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500381 printCommand(pldmFruCmds, i, cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600382 break;
Sridevi Ramesh45e52542020-04-03 07:54:18 -0500383 case PLDM_OEM:
Pavithra Barithaya6f4e9042020-04-20 23:33:46 -0500384#ifdef OEM_IBM
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500385 printCommand(pldmIBMHostCmds, i, cmdinfo);
386 printCommand(pldmIBMFileIOCmds, i, cmdinfo);
Pavithra Barithaya6f4e9042020-04-20 23:33:46 -0500387#endif
Sridevi Ramesh45e52542020-04-03 07:54:18 -0500388 break;
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600389 default:
390 break;
391 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500392 output.emplace_back(cmdinfo);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600393 }
394 }
Sridevi Rameshca4a8152020-08-11 09:26:19 -0500395 pldmtool::helper::DisplayInJson(output);
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600396 }
397};
398
John Wang58a0e062019-11-08 15:38:15 +0800399void registerCommand(CLI::App& app)
400{
401 auto base = app.add_subcommand("base", "base type command");
402 base->require_subcommand(1);
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600403
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400404 auto getPLDMTypes =
405 base->add_subcommand("GetPLDMTypes", "get pldm supported types");
John Wang58a0e062019-11-08 15:38:15 +0800406 commands.push_back(
407 std::make_unique<GetPLDMTypes>("base", "GetPLDMTypes", getPLDMTypes));
408
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400409 auto getPLDMVersion =
410 base->add_subcommand("GetPLDMVersion", "get version of a certain type");
John Wang58a0e062019-11-08 15:38:15 +0800411 commands.push_back(std::make_unique<GetPLDMVersion>(
412 "base", "GetPLDMVersion", getPLDMVersion));
Sridevi Rameshadd56f02020-01-20 23:44:22 -0600413
414 auto getPLDMTID = base->add_subcommand("GetTID", "get Terminus ID (TID)");
415 commands.push_back(std::make_unique<GetTID>("base", "GetTID", getPLDMTID));
Sridevi Ramesh66294d32020-02-21 03:52:07 -0600416
417 auto getPLDMCommands = base->add_subcommand(
418 "GetPLDMCommands", "get supported commands of pldm type");
419 commands.push_back(std::make_unique<GetPLDMCommands>(
420 "base", "GetPLDMCommands", getPLDMCommands));
Lakshminarayana R. Kammath58229b22019-08-09 06:30:04 -0500421}
John Wang58a0e062019-11-08 15:38:15 +0800422
423} // namespace base
424} // namespace pldmtool