blob: 06411a886805617ec890d0b3e722a9bdcf60ac8a [file] [log] [blame]
Deepak Kodihalli70e8db02019-10-21 00:59:46 -05001#pragma once
2
3#include "config.h"
4
5#include "fru_parser.hpp"
6#include "handler.hpp"
7
8#include <map>
9#include <sdbusplus/message.hpp>
10#include <string>
11#include <variant>
12#include <vector>
13
14#include "libpldm/fru.h"
15
16namespace pldm
17{
18
19namespace responder
20{
21
22namespace dbus
23{
24
25using Value =
26 std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
27 uint64_t, double, std::string, std::vector<uint8_t>>;
28using PropertyMap = std::map<Property, Value>;
29using InterfaceMap = std::map<Interface, PropertyMap>;
30using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>;
31
32} // namespace dbus
33
34/** @class FruImpl
35 *
36 * @brief Builds the PLDM FRU table containing the FRU records
37 */
38class FruImpl
39{
40 public:
41 /* @brief Header size for FRU record, it includes the FRU record set
42 * identifier, FRU record type, Number of FRU fields, Encoding type
43 * of FRU fields
44 */
45 static constexpr size_t recHeaderSize =
46 sizeof(struct pldm_fru_record_data_format) -
47 sizeof(struct pldm_fru_record_tlv);
48
49 /** @brief The FRU table is populated by processing the D-Bus inventory
50 * namespace, based on the config files for FRU. The configPath is
51 * consumed to build the FruParser object.
52 *
53 * @param[in] configPath - path to the directory containing config files
54 * for PLDM FRU
55 */
56 FruImpl(const std::string& configPath);
57
58 /** @brief Total length of the FRU table in bytes, this excludes the pad
59 * bytes and the checksum.
60 *
61 * @return size of the FRU table
62 */
63 uint32_t size() const
64 {
65 return table.size() - padBytes;
66 }
67
68 /** @brief The checksum of the contents of the FRU table
69 *
70 * @return checksum
71 */
72 uint32_t checkSum() const
73 {
74 return checksum;
75 }
76
77 /** @brief Number of record set identifiers in the FRU tables
78 *
79 * @return number of record set identifiers
80 */
81 uint16_t numRSI() const
82 {
83 return rsi;
84 }
85
86 /** @brief The number of FRU records in the table
87 *
88 * @return number of FRU records
89 */
90 uint16_t numRecords() const
91 {
92 return numRecs;
93 }
94
95 /** @brief Get the FRU table
96 *
97 * @param[out] - Populate response with the FRU table
98 */
99 void getFRUTable(Response& response);
100
101 private:
102 uint16_t nextRSI()
103 {
104 return ++rsi;
105 }
106
107 uint16_t rsi = 0;
108 uint16_t numRecs = 0;
109 uint8_t padBytes = 0;
110 std::vector<uint8_t> table;
111 uint32_t checksum = 0;
112
113 /** @brief populateRecord builds the FRU records for an instance of FRU and
114 * updates the FRU table with the FRU records.
115 *
116 * @param[in] interfaces - D-Bus interfaces and the associated property
117 * values for the FRU
118 * @param[in] recordInfos - FRU record info to build the FRU records
119 */
120 void populateRecords(const pldm::responder::dbus::InterfaceMap& interfaces,
121 const fru_parser::FruRecordInfos& recordInfos);
122};
123
Deepak Kodihallie60c5822019-10-23 03:26:15 -0500124namespace fru
125{
126
127class Handler : public CmdHandler
128{
129
130 public:
131 Handler(const std::string configPath) : impl(configPath)
132 {
133 handlers.emplace(PLDM_GET_FRU_RECORD_TABLE_METADATA,
134 [this](const pldm_msg* request, size_t payloadLength) {
135 return this->getFRURecordTableMetadata(
136 request, payloadLength);
137 });
138
139 handlers.emplace(PLDM_GET_FRU_RECORD_TABLE,
140 [this](const pldm_msg* request, size_t payloadLength) {
141 return this->getFRURecordTable(request,
142 payloadLength);
143 });
144 }
145
146 FruImpl impl;
147
148 /** @brief Handler for Get FRURecordTableMetadata
149 *
150 * @param[in] request - Request message payload
151 * @param[in] payloadLength - Request payload length
152 *
153 * @return PLDM response message
154 */
155 Response getFRURecordTableMetadata(const pldm_msg* request,
156 size_t payloadLength);
157
158 /** @brief Handler for GetFRURecordTable
159 *
160 * @param[in] request - Request message payload
161 * @param[in] payloadLength - Request payload length
162 *
163 * @return PLDM response message
164 */
165 Response getFRURecordTable(const pldm_msg* request, size_t payloadLength);
166};
167
168} // namespace fru
169
Deepak Kodihalli70e8db02019-10-21 00:59:46 -0500170} // namespace responder
171
172} // namespace pldm