Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 3 | #include "const.hpp" |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 4 | #include "store.hpp" |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 5 | #include "types.hpp" |
| 6 | |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 7 | #include <iostream> |
| 8 | |
| 9 | using namespace std; |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 10 | |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 11 | namespace openpower |
| 12 | { |
| 13 | namespace vpd |
| 14 | { |
SunnySrivastava1984 | 945a02d | 2020-05-06 01:55:41 -0500 | [diff] [blame] | 15 | |
Santosh Puranik | bd011b2 | 2020-01-23 04:05:25 -0600 | [diff] [blame] | 16 | /** @brief Return the hex representation of the incoming byte |
| 17 | * |
| 18 | * @param [in] c - The input byte |
| 19 | * @returns The hex representation of the byte as a character. |
| 20 | */ |
| 21 | constexpr auto toHex(size_t c) |
| 22 | { |
| 23 | constexpr auto map = "0123456789abcdef"; |
| 24 | return map[c]; |
| 25 | } |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 26 | |
| 27 | namespace inventory |
| 28 | { |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 29 | /** @brief Api to obtain a dictionary of path -> services |
| 30 | * where path is in subtree and services is of the type |
| 31 | * returned by the GetObject method. |
| 32 | * |
| 33 | * @param [in] root - Root path for object subtree |
| 34 | * @param [in] depth - Maximum subtree depth required |
| 35 | * @param [in] interfaces - Array to interfaces for which |
| 36 | * result is required. |
| 37 | * @return A dictionary of Path -> services |
| 38 | */ |
| 39 | MapperResponse |
| 40 | getObjectSubtreeForInterfaces(const std::string& root, const int32_t depth, |
| 41 | const std::vector<std::string>& interfaces); |
| 42 | |
Deepak Kodihalli | 7679449 | 2017-02-16 23:48:18 -0600 | [diff] [blame] | 43 | } // namespace inventory |
| 44 | |
SunnySrivastava1984 | f6d541e | 2020-02-04 12:50:40 -0600 | [diff] [blame] | 45 | /**@brief This API reads 2 Bytes of data and swap the read data |
| 46 | * @param[in] iterator- Pointer pointing to the data to be read |
| 47 | * @return returns 2 Byte data read at the given pointer |
| 48 | */ |
| 49 | openpower::vpd::constants::LE2ByteData |
| 50 | readUInt16LE(Binary::const_iterator iterator); |
| 51 | |
SunnySrivastava1984 | d076da8 | 2020-03-05 05:33:35 -0600 | [diff] [blame] | 52 | /** @brief Encodes a keyword for D-Bus. |
| 53 | * @param[in] kw - kwd data in string format |
| 54 | * @param[in] encoding - required for kwd data |
| 55 | */ |
| 56 | string encodeKeyword(const string& kw, const string& encoding); |
SunnySrivastava1984 | 4330654 | 2020-04-01 02:50:20 -0500 | [diff] [blame] | 57 | |
| 58 | /** @brief Reads a property from the inventory manager given object path, |
| 59 | * intreface and property. |
| 60 | * @param[in] obj - object path |
| 61 | * @param[in] inf - interface |
| 62 | * @param[in] prop - property whose value is fetched |
| 63 | * @return [out] - value of the property |
| 64 | */ |
| 65 | string readBusProperty(const string& obj, const string& inf, |
| 66 | const string& prop); |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * @brief API to create PEL entry |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 70 | * @param[in] additionalData - Map holding the additional data |
| 71 | * @param[in] sev - Severity |
| 72 | * @param[in] errIntf - error interface |
SunnySrivastava1984 | a20be8e | 2020-08-26 02:00:50 -0500 | [diff] [blame] | 73 | */ |
| 74 | void createPEL(const std::map<std::string, std::string>& additionalData, |
Sunny Srivastava | 0746eee | 2021-03-22 13:36:54 -0500 | [diff] [blame] | 75 | const constants::PelSeverity& sev, const std::string& errIntf); |
SunnySrivastava1984 | 9094d4f | 2020-08-05 09:32:29 -0500 | [diff] [blame] | 76 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 77 | /** |
| 78 | * @brief getVpdFilePath |
| 79 | * Get vpd file path corresponding to the given object path. |
| 80 | * @param[in] - json file path |
| 81 | * @param[in] - Object path |
| 82 | * @return - Vpd file path |
| 83 | */ |
| 84 | inventory::VPDfilepath getVpdFilePath(const string& jsonFile, |
| 85 | const std::string& ObjPath); |
| 86 | |
| 87 | /** |
| 88 | * @brief isPathInJson |
| 89 | * API which checks for the presence of the given eeprom path in the given json. |
| 90 | * @param[in] - eepromPath |
| 91 | * @return - true if the eeprom is present in the json; false otherwise |
| 92 | */ |
| 93 | bool isPathInJson(const std::string& eepromPath); |
| 94 | |
| 95 | /** |
| 96 | * @brief isRecKwInDbusJson |
| 97 | * API which checks whether the given keyword under the given record is to be |
| 98 | * published on dbus or not. Checks against the keywords present in |
| 99 | * dbus_property.json. |
| 100 | * @param[in] - record name |
| 101 | * @param[in] - keyword name |
| 102 | * @return - true if the record-keyword pair is present in dbus_property.json; |
| 103 | * false otherwise. |
| 104 | */ |
| 105 | bool isRecKwInDbusJson(const std::string& record, const std::string& keyword); |
| 106 | |
Sunny Srivastava | 6c71c9d | 2021-04-15 04:43:54 -0500 | [diff] [blame] | 107 | /** |
| 108 | * @brief Check the type of VPD. |
| 109 | * |
| 110 | * Checks the type of vpd based on the start tag. |
| 111 | * @param[in] vector - Vpd data in vector format |
| 112 | * |
| 113 | * @return enum of type vpdType |
| 114 | */ |
| 115 | constants::vpdType vpdTypeCheck(const Binary& vector); |
| 116 | |
SunnySrivastava1984 | 9a19554 | 2020-09-07 06:04:50 -0500 | [diff] [blame] | 117 | /* |
| 118 | * @brief This method does nothing. Just an empty function to return null |
| 119 | * at the end of variadic template args |
| 120 | */ |
| 121 | inline string getCommand() |
| 122 | { |
| 123 | return ""; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * @brief This function to arrange all arguments to make commandy |
| 128 | * @param[in] arguments to create the command |
| 129 | * @return cmd - command string |
| 130 | */ |
| 131 | template <typename T, typename... Types> |
| 132 | inline string getCommand(T arg1, Types... args) |
| 133 | { |
| 134 | string cmd = " " + arg1 + getCommand(args...); |
| 135 | |
| 136 | return cmd; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @brief This API takes arguments, creates a shell command line and executes |
| 141 | * them. |
| 142 | * @param[in] arguments for command |
| 143 | * @returns output of that command |
| 144 | */ |
| 145 | template <typename T, typename... Types> |
| 146 | inline vector<string> executeCmd(T&& path, Types... args) |
| 147 | { |
| 148 | vector<string> stdOutput; |
| 149 | array<char, 128> buffer; |
| 150 | |
| 151 | string cmd = path + getCommand(args...); |
| 152 | |
| 153 | unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose); |
| 154 | if (!pipe) |
| 155 | { |
| 156 | throw runtime_error("popen() failed!"); |
| 157 | } |
| 158 | while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) |
| 159 | { |
| 160 | stdOutput.emplace_back(buffer.data()); |
| 161 | } |
| 162 | |
| 163 | return stdOutput; |
| 164 | } |
| 165 | |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 166 | /** @brief This API checks for IM and HW keywords, and based |
| 167 | * on these values decides which system json to be used. |
| 168 | * @param[in] vpdMap - parsed vpd |
| 169 | * @returns System json path |
| 170 | */ |
| 171 | string getSystemsJson(const Parsed& vpdMap); |
| 172 | |
| 173 | /** @brief Reads HW Keyword from the vpd |
| 174 | * @param[in] vpdMap - parsed vpd |
| 175 | * @returns value of HW Keyword |
| 176 | */ |
| 177 | const string getHW(const Parsed& vpdMap); |
| 178 | |
| 179 | /** @brief Reads IM Keyword from the vpd |
| 180 | * @param[in] vpdMap - parsed vpd |
| 181 | * @returns value of IM Keyword |
| 182 | */ |
| 183 | const string getIM(const Parsed& vpdMap); |
| 184 | |
PriyangaRamasamy | 647868e | 2020-09-08 17:03:19 +0530 | [diff] [blame] | 185 | /** @brief Translate udev event generated path to a generic /sys/bus eeprom path |
| 186 | * @param[io] file - path generated from udev event. |
| 187 | */ |
| 188 | void udevToGenericPath(string& file); |
Patrick Venture | c83c4dc | 2018-11-01 16:29:18 -0700 | [diff] [blame] | 189 | } // namespace vpd |
Alpana Kumari | f05effd | 2021-04-07 07:32:53 -0500 | [diff] [blame] | 190 | } // namespace openpower |