xref: /openbmc/pldm/pldmtool/pldmtool.cpp (revision 16c2a0a03e5daac77e204eb99e00711490fb6e26)
1f7f5da97SDeepak Kodihalli #include "pldm_base_cmd.hpp"
2f7f5da97SDeepak Kodihalli #include "pldm_bios_cmd.hpp"
3f7f5da97SDeepak Kodihalli #include "pldm_cmd_helper.hpp"
4f7f5da97SDeepak Kodihalli #include "pldm_fru_cmd.hpp"
5eea835a9STom Joseph #include "pldm_fw_update_cmd.hpp"
6f7f5da97SDeepak Kodihalli #include "pldm_platform_cmd.hpp"
7c4e80ccaSPavithra Barithaya #include "pldmtool/oem/ibm/pldm_oem_ibm.hpp"
8f7f5da97SDeepak Kodihalli 
9f7f5da97SDeepak Kodihalli #include <CLI/CLI.hpp>
10f7f5da97SDeepak Kodihalli 
11f7f5da97SDeepak Kodihalli namespace pldmtool
12f7f5da97SDeepak Kodihalli {
13f7f5da97SDeepak Kodihalli 
14f7f5da97SDeepak Kodihalli namespace raw
15f7f5da97SDeepak Kodihalli {
16f7f5da97SDeepak Kodihalli 
17f7f5da97SDeepak Kodihalli using namespace pldmtool::helper;
18f7f5da97SDeepak Kodihalli 
19f7f5da97SDeepak Kodihalli namespace
20f7f5da97SDeepak Kodihalli {
21f7f5da97SDeepak Kodihalli std::vector<std::unique_ptr<CommandInterface>> commands;
22f7f5da97SDeepak Kodihalli }
23f7f5da97SDeepak Kodihalli 
24f7f5da97SDeepak Kodihalli class RawOp : public CommandInterface
25f7f5da97SDeepak Kodihalli {
26f7f5da97SDeepak Kodihalli   public:
27f7f5da97SDeepak Kodihalli     ~RawOp() = default;
28f7f5da97SDeepak Kodihalli     RawOp() = delete;
29f7f5da97SDeepak Kodihalli     RawOp(const RawOp&) = delete;
30f7f5da97SDeepak Kodihalli     RawOp(RawOp&&) = default;
31f7f5da97SDeepak Kodihalli     RawOp& operator=(const RawOp&) = delete;
32a7dbca53SPavithra Barithaya     RawOp& operator=(RawOp&&) = delete;
33f7f5da97SDeepak Kodihalli 
RawOp(const char * type,const char * name,CLI::App * app)34f7f5da97SDeepak Kodihalli     explicit RawOp(const char* type, const char* name, CLI::App* app) :
35f7f5da97SDeepak Kodihalli         CommandInterface(type, name, app)
36f7f5da97SDeepak Kodihalli     {
37f7f5da97SDeepak Kodihalli         app->add_option("-d,--data", rawData, "raw data")
38f7f5da97SDeepak Kodihalli             ->required()
39f7f5da97SDeepak Kodihalli             ->expected(-3);
40f7f5da97SDeepak Kodihalli     }
createRequestMsg()41f7f5da97SDeepak Kodihalli     std::pair<int, std::vector<uint8_t>> createRequestMsg() override
42f7f5da97SDeepak Kodihalli 
43f7f5da97SDeepak Kodihalli     {
4466871b4dSThu Nguyen         rawData[0] = (rawData[0] & 0xe0) | instanceId;
45f7f5da97SDeepak Kodihalli         return {PLDM_SUCCESS, rawData};
46f7f5da97SDeepak Kodihalli     }
47f7f5da97SDeepak Kodihalli 
parseResponseMsg(pldm_msg *,size_t)48f7f5da97SDeepak Kodihalli     void parseResponseMsg(pldm_msg* /* responsePtr */,
49f7f5da97SDeepak Kodihalli                           size_t /* payloadLength */) override
50f7f5da97SDeepak Kodihalli     {}
51f7f5da97SDeepak Kodihalli 
52f7f5da97SDeepak Kodihalli   private:
53f7f5da97SDeepak Kodihalli     std::vector<uint8_t> rawData;
54f7f5da97SDeepak Kodihalli };
55f7f5da97SDeepak Kodihalli 
registerCommand(CLI::App & app)56f7f5da97SDeepak Kodihalli void registerCommand(CLI::App& app)
57f7f5da97SDeepak Kodihalli {
58*16c2a0a0SPatrick Williams     auto raw =
59*16c2a0a0SPatrick Williams         app.add_subcommand("raw", "send a raw request and print response");
60f7f5da97SDeepak Kodihalli     commands.push_back(std::make_unique<RawOp>("raw", "raw", raw));
61f7f5da97SDeepak Kodihalli }
62f7f5da97SDeepak Kodihalli 
63f7f5da97SDeepak Kodihalli } // namespace raw
64f7f5da97SDeepak Kodihalli } // namespace pldmtool
65f7f5da97SDeepak Kodihalli 
main(int argc,char ** argv)66f7f5da97SDeepak Kodihalli int main(int argc, char** argv)
67f7f5da97SDeepak Kodihalli {
68f7f5da97SDeepak Kodihalli     CLI::App app{"PLDM requester tool for OpenBMC"};
69f7f5da97SDeepak Kodihalli     app.require_subcommand(1)->ignore_case();
70f7f5da97SDeepak Kodihalli 
71f7f5da97SDeepak Kodihalli     pldmtool::raw::registerCommand(app);
72f7f5da97SDeepak Kodihalli     pldmtool::base::registerCommand(app);
73f7f5da97SDeepak Kodihalli     pldmtool::bios::registerCommand(app);
74f7f5da97SDeepak Kodihalli     pldmtool::platform::registerCommand(app);
75f7f5da97SDeepak Kodihalli     pldmtool::fru::registerCommand(app);
76eea835a9STom Joseph     pldmtool::fw_update::registerCommand(app);
77f7f5da97SDeepak Kodihalli 
78f7f5da97SDeepak Kodihalli #ifdef OEM_IBM
79c4e80ccaSPavithra Barithaya     pldmtool::oem_ibm::registerCommand(app);
80f7f5da97SDeepak Kodihalli #endif
81f7f5da97SDeepak Kodihalli 
82f7f5da97SDeepak Kodihalli     CLI11_PARSE(app, argc, argv);
83a340eed8SPavithra Barithaya     pldmtool::platform::parseGetPDROption();
84f7f5da97SDeepak Kodihalli     return 0;
85f7f5da97SDeepak Kodihalli }
86