xref: /openbmc/pldm/pldmtool/pldm_fru_cmd.cpp (revision f7f5da97f4172ec9b4528c9539f4d0e1eb00ae8a)
1*f7f5da97SDeepak Kodihalli #include "pldm_fru_cmd.hpp"
2*f7f5da97SDeepak Kodihalli 
3*f7f5da97SDeepak Kodihalli #include "pldm_cmd_helper.hpp"
4*f7f5da97SDeepak Kodihalli 
5*f7f5da97SDeepak Kodihalli namespace pldmtool
6*f7f5da97SDeepak Kodihalli {
7*f7f5da97SDeepak Kodihalli 
8*f7f5da97SDeepak Kodihalli namespace fru
9*f7f5da97SDeepak Kodihalli {
10*f7f5da97SDeepak Kodihalli 
11*f7f5da97SDeepak Kodihalli namespace
12*f7f5da97SDeepak Kodihalli {
13*f7f5da97SDeepak Kodihalli 
14*f7f5da97SDeepak Kodihalli using namespace pldmtool::helper;
15*f7f5da97SDeepak Kodihalli 
16*f7f5da97SDeepak Kodihalli std::vector<std::unique_ptr<CommandInterface>> commands;
17*f7f5da97SDeepak Kodihalli 
18*f7f5da97SDeepak Kodihalli } // namespace
19*f7f5da97SDeepak Kodihalli 
20*f7f5da97SDeepak Kodihalli class GetFruRecordTableMetadata : public CommandInterface
21*f7f5da97SDeepak Kodihalli {
22*f7f5da97SDeepak Kodihalli   public:
23*f7f5da97SDeepak Kodihalli     ~GetFruRecordTableMetadata() = default;
24*f7f5da97SDeepak Kodihalli     GetFruRecordTableMetadata() = delete;
25*f7f5da97SDeepak Kodihalli     GetFruRecordTableMetadata(const GetFruRecordTableMetadata&) = delete;
26*f7f5da97SDeepak Kodihalli     GetFruRecordTableMetadata(GetFruRecordTableMetadata&&) = default;
27*f7f5da97SDeepak Kodihalli     GetFruRecordTableMetadata&
28*f7f5da97SDeepak Kodihalli         operator=(const GetFruRecordTableMetadata&) = delete;
29*f7f5da97SDeepak Kodihalli     GetFruRecordTableMetadata& operator=(GetFruRecordTableMetadata&&) = default;
30*f7f5da97SDeepak Kodihalli 
31*f7f5da97SDeepak Kodihalli     using CommandInterface::CommandInterface;
32*f7f5da97SDeepak Kodihalli 
33*f7f5da97SDeepak Kodihalli     std::pair<int, std::vector<uint8_t>> createRequestMsg() override
34*f7f5da97SDeepak Kodihalli     {
35*f7f5da97SDeepak Kodihalli         std::vector<uint8_t> requestMsg(sizeof(pldm_msg_hdr));
36*f7f5da97SDeepak Kodihalli         auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
37*f7f5da97SDeepak Kodihalli 
38*f7f5da97SDeepak Kodihalli         auto rc = encode_get_fru_record_table_metadata_req(
39*f7f5da97SDeepak Kodihalli             instanceId, request, PLDM_GET_FRU_RECORD_TABLE_METADATA_REQ_BYTES);
40*f7f5da97SDeepak Kodihalli         return {rc, requestMsg};
41*f7f5da97SDeepak Kodihalli     }
42*f7f5da97SDeepak Kodihalli 
43*f7f5da97SDeepak Kodihalli     void parseResponseMsg(pldm_msg* responsePtr, size_t payloadLength) override
44*f7f5da97SDeepak Kodihalli     {
45*f7f5da97SDeepak Kodihalli         uint8_t cc = 0;
46*f7f5da97SDeepak Kodihalli         uint8_t fru_data_major_version, fru_data_minor_version;
47*f7f5da97SDeepak Kodihalli         uint32_t fru_table_maximum_size, fru_table_length;
48*f7f5da97SDeepak Kodihalli         uint16_t total_record_set_identifiers, total_table_records;
49*f7f5da97SDeepak Kodihalli         uint32_t checksum;
50*f7f5da97SDeepak Kodihalli 
51*f7f5da97SDeepak Kodihalli         auto rc = decode_get_fru_record_table_metadata_resp(
52*f7f5da97SDeepak Kodihalli             responsePtr, payloadLength, &cc, &fru_data_major_version,
53*f7f5da97SDeepak Kodihalli             &fru_data_minor_version, &fru_table_maximum_size, &fru_table_length,
54*f7f5da97SDeepak Kodihalli             &total_record_set_identifiers, &total_table_records, &checksum);
55*f7f5da97SDeepak Kodihalli         if (rc != PLDM_SUCCESS || cc != PLDM_SUCCESS)
56*f7f5da97SDeepak Kodihalli         {
57*f7f5da97SDeepak Kodihalli             std::cerr << "Response Message Error: "
58*f7f5da97SDeepak Kodihalli                       << "rc=" << rc << ",cc=" << (int)cc << std::endl;
59*f7f5da97SDeepak Kodihalli             return;
60*f7f5da97SDeepak Kodihalli         }
61*f7f5da97SDeepak Kodihalli         std::cout << "FRUDATAMajorVersion : "
62*f7f5da97SDeepak Kodihalli                   << static_cast<uint32_t>(fru_data_major_version) << std::endl;
63*f7f5da97SDeepak Kodihalli         std::cout << "FRUDATAMinorVersion : "
64*f7f5da97SDeepak Kodihalli                   << static_cast<uint32_t>(fru_data_minor_version) << std::endl;
65*f7f5da97SDeepak Kodihalli         std::cout << "FRUTableMaximumSize : " << fru_table_maximum_size
66*f7f5da97SDeepak Kodihalli                   << std::endl;
67*f7f5da97SDeepak Kodihalli         std::cout << "FRUTableLength : " << fru_table_length << std::endl;
68*f7f5da97SDeepak Kodihalli         std::cout << "Total number of Record Set Identifiers in table : "
69*f7f5da97SDeepak Kodihalli                   << total_record_set_identifiers << std::endl;
70*f7f5da97SDeepak Kodihalli         std::cout << "Total number of records in table :  "
71*f7f5da97SDeepak Kodihalli                   << total_table_records << std::endl;
72*f7f5da97SDeepak Kodihalli         std::cout << "FRU DATAStructureTableIntegrityChecksum :  " << checksum
73*f7f5da97SDeepak Kodihalli                   << std::endl;
74*f7f5da97SDeepak Kodihalli     }
75*f7f5da97SDeepak Kodihalli };
76*f7f5da97SDeepak Kodihalli 
77*f7f5da97SDeepak Kodihalli void registerCommand(CLI::App& app)
78*f7f5da97SDeepak Kodihalli {
79*f7f5da97SDeepak Kodihalli     auto fru = app.add_subcommand("fru", "FRU type command");
80*f7f5da97SDeepak Kodihalli     fru->require_subcommand(1);
81*f7f5da97SDeepak Kodihalli     auto getFruRecordTableMetadata = fru->add_subcommand(
82*f7f5da97SDeepak Kodihalli         "GetFruRecordTableMetadata", "get FRU record table metadata");
83*f7f5da97SDeepak Kodihalli     commands.push_back(std::make_unique<GetFruRecordTableMetadata>(
84*f7f5da97SDeepak Kodihalli         "fru", "GetFruRecordTableMetadata", getFruRecordTableMetadata));
85*f7f5da97SDeepak Kodihalli }
86*f7f5da97SDeepak Kodihalli 
87*f7f5da97SDeepak Kodihalli } // namespace fru
88*f7f5da97SDeepak Kodihalli 
89*f7f5da97SDeepak Kodihalli } // namespace pldmtool
90