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