blob: ac0b2f540555381348ee4c2240d856f85de86eda [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
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530126 public:
127 /**
128 * @brief Dump the complete inventory in JSON format
129 *
130 * @param[in] jsObject - Inventory JSON specified in configure file.
131 */
132 void dumpInventory(const nlohmann::basic_json<>& jsObject);
133
134 /**
135 * @brief Dump the given inventory object in JSON format
136 *
137 * @param[in] jsObject - Inventory JSON specified in configure file.
138 */
139 void dumpObject(const nlohmann::basic_json<>& jsObject);
140
141 /**
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530142 * @brief Read keyword
143 * Read the given object path, record name and keyword
144 * from the inventory and display the value of the keyword
145 * in JSON format.
146 */
147 void readKeyword();
148
149 /**
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530150 * @brief Update Keyword
151 * Update the given keyword with the given value.
152 *
153 * @return return code (Success(0)/Failure(-1))
154 */
155 int updateKeyword();
156
157 /**
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530158 * @brief Force Reset
159 * Clearing the inventory cache data and restarting the
160 * phosphor inventory manager and also retriggering all the
161 * udev events.
162 *
163 * @param[in] jsObject - Inventory JSON specified in configure file.
164 */
165 void forceReset(const nlohmann::basic_json<>& jsObject);
166
167 /**
PriyangaRamasamyc0a534f2020-08-24 21:29:18 +0530168 * @brief Update Hardware
169 * If the given record-keyword pair is present in dbus_properties.json,
170 * then will update the given data in both dbus and hardware.
171 * Else update the given data only in hardware.
172 * @return returncode (success/failure).
173 */
174 int updateHardware();
PriyangaRamasamy887a42a2020-09-03 00:33:57 +0530175
176 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530177 * @brief Constructor
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530178 * Constructor is called during the
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530179 * object instantiation for dumpInventory option and
180 * forceReset option.
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530181 */
182 VpdTool()
183 {
184 }
185
186 /**
187 * @brief Constructor
188 * Constructor is called during the
189 * object instantiation for dumpObject option.
190 */
191 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
192 {
193 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530194
195 /**
196 * @brief Constructor
197 * Constructor is called during the
198 * object instantiation for readKeyword option.
199 */
200 VpdTool(const std::string&& fru, const std::string&& recName,
201 const std::string&& kw) :
202 fruPath(std::move(fru)),
203 recordName(std::move(recName)), keyword(std::move(kw))
204 {
205 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530206
207 /**
208 * @brief Constructor
209 * Constructor is called during the
210 * object instantiation for updateKeyword option.
211 */
212
213 VpdTool(const std::string&& fru, const std::string&& recName,
214 const std::string&& kw, const std::string&& val) :
215 fruPath(std::move(fru)),
216 recordName(std::move(recName)), keyword(std::move(kw)),
217 value(std::move(val))
218 {
219 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530220};