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