blob: 8b1207db72663d4c3e2b58f6aafc5a22f8772423 [file] [log] [blame]
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +05301#include "config.h"
2
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +05303#include "editor_impl.hpp"
Sunny Srivastava6c71c9d2021-04-15 04:43:54 -05004#include "ibm_vpd_utils.hpp"
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +05305#include "types.hpp"
6
7#include <nlohmann/json.hpp>
PriyangaRamasamy887a42a2020-09-03 00:33:57 +05308#include <string>
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +05309
10using json = nlohmann::json;
11
12class VpdTool
13{
14 private:
15 const std::string fruPath;
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +053016 const std::string recordName;
17 const std::string keyword;
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +053018 const std::string value;
PriyangaRamasamy8cc5b152021-06-03 13:05:17 -050019 bool objFound = true;
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053020
Alpana Kumarib6965f12020-06-01 00:32:21 -050021 // Store Type of FRU
22 std::string fruType;
23
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053024 /**
25 * @brief Debugger
26 * Displays the output in JSON.
27 *
28 * @param[in] output - json output to be displayed
29 */
30 void debugger(json output);
31
32 /**
33 * @brief make Dbus Call
34 *
35 * @param[in] objectName - dbus Object
36 * @param[in] interface - dbus Interface
37 * @param[in] kw - keyword under the interface
38 *
39 * @return dbus call response
40 */
41 auto makeDBusCall(const std::string& objectName,
42 const std::string& interface, const std::string& kw);
43
44 /**
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053045 * @brief Get VINI properties
46 * Making a dbus call for properties [SN, PN, CC, FN, DR]
47 * under VINI interface.
48 *
49 * @param[in] invPath - Value of inventory Path
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053050 *
51 * @return json output which gives the properties under invPath's VINI
52 * interface
53 */
PriyangaRamasamy8cc5b152021-06-03 13:05:17 -050054 json getVINIProperties(std::string invPath);
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053055
56 /**
57 * @brief Get ExtraInterface Properties
58 * Making a dbus call for those properties under extraInterfaces.
59 *
60 * @param[in] invPath - Value of inventory path
61 * @param[in] extraInterface - One of the invPath's extraInterfaces whose
62 * value is not null
63 * @param[in] prop - All properties of the extraInterface.
PriyangaRamasamy8cc5b152021-06-03 13:05:17 -050064 * @param[out] output - output json which has the properties under invPath's
65 * extra interface.
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053066 */
PriyangaRamasamy8cc5b152021-06-03 13:05:17 -050067 void getExtraInterfaceProperties(const string& invPath,
68 const string& extraInterface,
69 const json& prop, json& output);
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053070
71 /**
72 * @brief Interface Decider
73 * Decides whether to make the dbus call for
74 * getting properites from extraInterface or from
75 * VINI interface, depending on the value of
76 * extraInterfaces object in the inventory json.
77 *
78 * @param[in] itemEEPROM - holds the reference of one of the EEPROM objects.
79 *
80 * @return json output for one of the EEPROM objects.
81 */
82 json interfaceDecider(json& itemEEPROM);
83
84 /**
85 * @brief Parse Inventory JSON
86 * Parses the complete inventory json and depending upon
87 * the user option makes the dbuscall for the frus
88 * via interfaceDecider function.
89 *
90 * @param[in] jsObject - Inventory json object
91 * @param[in] flag - flag which tells about the user option(either
92 * dumpInventory or dumpObject)
93 * @param[in] fruPath - fruPath is empty for dumpInventory option and holds
94 * valid fruPath for dumpObject option.
95 *
96 * @return output json
97 */
98 json parseInvJson(const json& jsObject, char flag, std::string fruPath);
99
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530100 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530101 * @brief eraseInventoryPath
102 * Remove the INVENTORY_PATH - "/xyz/openbmc_project/inventory"
103 * for code convenience.
104 *
105 * @param[out] fru - Reference to the fru path whose INVENTORY_PATH is
106 * stripped off.
107 */
108 void eraseInventoryPath(std::string& fru);
109
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530110 /**
111 * @brief printReturnCode
112 * Prints the return code of the program in console output, whenever
113 * the program fails to exit successfully.
114 *
115 * @param[in] returnCode - return code of the program.
116 */
PriyangaRamasamy6ee637a2021-02-12 04:49:02 -0600117 void printReturnCode(int returnCode);
118
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530119 /**
120 * @brief Convert hex/ascii values to Binary
121 * @param[in] - value in hex/ascii.
122 * @param[out] - value in binary.
123 */
124 openpower::vpd::Binary toBinary(const std::string& value);
125
Priyanga Ramasamy0086dd12021-09-28 10:31:50 -0500126 /**
127 * @brief Get the json which has Present property value of the given fru.
128 * @param[in] invPath - inventory path of the fru.
129 * @param[out] parentPresence - Update the parent fru's present property.
130 * @return output json which has the Present property value.
131 */
132 json getPresentPropJson(const std::string& invPath,
133 std::string& parentPresence);
134
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530135 public:
136 /**
137 * @brief Dump the complete inventory in JSON format
138 *
139 * @param[in] jsObject - Inventory JSON specified in configure file.
140 */
141 void dumpInventory(const nlohmann::basic_json<>& jsObject);
142
143 /**
144 * @brief Dump the given inventory object in JSON format
145 *
146 * @param[in] jsObject - Inventory JSON specified in configure file.
147 */
148 void dumpObject(const nlohmann::basic_json<>& jsObject);
149
150 /**
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530151 * @brief Read keyword
152 * Read the given object path, record name and keyword
153 * from the inventory and display the value of the keyword
154 * in JSON format.
155 */
156 void readKeyword();
157
158 /**
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530159 * @brief Update Keyword
160 * Update the given keyword with the given value.
161 *
162 * @return return code (Success(0)/Failure(-1))
163 */
164 int updateKeyword();
165
166 /**
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530167 * @brief Force Reset
168 * Clearing the inventory cache data and restarting the
169 * phosphor inventory manager and also retriggering all the
170 * udev events.
171 *
172 * @param[in] jsObject - Inventory JSON specified in configure file.
173 */
174 void forceReset(const nlohmann::basic_json<>& jsObject);
175
176 /**
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530177 * @brief Update Hardware
178 * If the given record-keyword pair is present in dbus_properties.json,
179 * then will update the given data in both dbus and hardware.
180 * Else update the given data only in hardware.
181 * @return returncode (success/failure).
182 */
183 int updateHardware();
PriyangaRamasamy887a42a2020-09-03 00:33:57 +0530184
185 /**
Priyanga Ramasamy38031312021-10-07 16:39:13 -0500186 * @brief Read Keyword from Hardware
187 * This api is to read a keyword directly from the hardware. The hardware
188 * path, record name and keyword name are received at the time of
189 * initialising the constructor.
190 */
191 void readKwFromHw();
192
193 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530194 * @brief Constructor
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530195 * Constructor is called during the
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530196 * object instantiation for dumpInventory option and
197 * forceReset option.
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530198 */
199 VpdTool()
200 {
201 }
202
203 /**
204 * @brief Constructor
205 * Constructor is called during the
206 * object instantiation for dumpObject option.
207 */
208 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
209 {
210 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530211
212 /**
213 * @brief Constructor
214 * Constructor is called during the
215 * object instantiation for readKeyword option.
216 */
217 VpdTool(const std::string&& fru, const std::string&& recName,
218 const std::string&& kw) :
219 fruPath(std::move(fru)),
220 recordName(std::move(recName)), keyword(std::move(kw))
221 {
222 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530223
224 /**
225 * @brief Constructor
226 * Constructor is called during the
227 * object instantiation for updateKeyword option.
228 */
229
230 VpdTool(const std::string&& fru, const std::string&& recName,
231 const std::string&& kw, const std::string&& val) :
232 fruPath(std::move(fru)),
233 recordName(std::move(recName)), keyword(std::move(kw)),
234 value(std::move(val))
235 {
236 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530237};