PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 3 | #include "editor_impl.hpp" |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 4 | #include "ibm_vpd_utils.hpp" |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 5 | #include "types.hpp" |
| 6 | |
| 7 | #include <nlohmann/json.hpp> |
PriyangaRamasamy | 887a42a | 2020-09-03 00:33:57 +0530 | [diff] [blame] | 8 | #include <string> |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 9 | |
| 10 | using json = nlohmann::json; |
| 11 | |
| 12 | class VpdTool |
| 13 | { |
| 14 | private: |
| 15 | const std::string fruPath; |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 16 | const std::string recordName; |
| 17 | const std::string keyword; |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 18 | const std::string value; |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 19 | bool objFound = true; |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 20 | |
Alpana Kumari | b6965f1 | 2020-06-01 00:32:21 -0500 | [diff] [blame] | 21 | // Store Type of FRU |
| 22 | std::string fruType; |
| 23 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 24 | /** |
| 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 | /** |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 45 | * @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 |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 50 | * |
| 51 | * @return json output which gives the properties under invPath's VINI |
| 52 | * interface |
| 53 | */ |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 54 | json getVINIProperties(std::string invPath); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 55 | |
| 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. |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 64 | * @param[out] output - output json which has the properties under invPath's |
| 65 | * extra interface. |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 66 | */ |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 67 | void getExtraInterfaceProperties(const string& invPath, |
| 68 | const string& extraInterface, |
| 69 | const json& prop, json& output); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 70 | |
| 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 | |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 100 | /** |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 101 | * @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 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 110 | /** |
| 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 | */ |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 117 | void printReturnCode(int returnCode); |
| 118 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 119 | /** |
| 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 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 126 | 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 | /** |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 142 | * @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 | /** |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 150 | * @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 | /** |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 158 | * @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 | /** |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 168 | * @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(); |
PriyangaRamasamy | 887a42a | 2020-09-03 00:33:57 +0530 | [diff] [blame] | 175 | |
| 176 | /** |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 177 | * @brief Constructor |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 178 | * Constructor is called during the |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 179 | * object instantiation for dumpInventory option and |
| 180 | * forceReset option. |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 181 | */ |
| 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 | } |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 194 | |
| 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 | } |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 206 | |
| 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 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 220 | }; |