Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <sdbusplus/bus.hpp> |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 4 | #include <util/ffdc_file.hpp> |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame] | 5 | #include <util/trace.hpp> |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 6 | |
| 7 | #include <string> |
| 8 | #include <variant> |
| 9 | #include <vector> |
| 10 | |
| 11 | namespace util |
| 12 | { |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 13 | namespace dbus |
| 14 | { |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 15 | using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>, |
Ben Tyner | 2b26b2b | 2022-12-15 15:42:02 -0600 | [diff] [blame] | 16 | std::vector<std::string>, int32_t>; |
Patrick Williams | 27dd636 | 2023-05-10 07:51:20 -0500 | [diff] [blame] | 17 | using DBusProperty = std::string; |
| 18 | using DBusInterface = std::string; |
| 19 | using DBusService = std::string; |
| 20 | using DBusPath = std::string; |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 21 | using DBusInterfaceList = std::vector<DBusInterface>; |
| 22 | using DBusSubTree = |
| 23 | std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>; |
| 24 | |
| 25 | /** |
| 26 | * Find the dbus object path and service that implements the given interface |
| 27 | * |
| 28 | * @param[in] i_interface Interface to search for |
| 29 | * @param[out] o_path Path of dbus object implementing the interface |
| 30 | * @param[out] o_service Service implementing the dbus object path |
| 31 | * @return non-zero on error |
| 32 | */ |
| 33 | int find(const std::string& i_interface, std::string& o_path, |
| 34 | std::string& o_service); |
| 35 | |
| 36 | /** |
| 37 | * Find the dbus service that implements the given dbus object and interface |
| 38 | * |
| 39 | * @param[in] i_interface Interface that maps to the service |
| 40 | * @param[in] i_path Path that maps to the service |
| 41 | * @param[out] o_service Service implementing the dbus object and interface |
| 42 | * @return non-zer on error |
| 43 | */ |
| 44 | int findService(const std::string& i_interface, const std::string& i_path, |
| 45 | std::string& o_service); |
| 46 | |
| 47 | /** |
| 48 | * Read a property from a dbus object interface |
| 49 | * |
| 50 | * @param[in] i_interface Interface implementing the property |
| 51 | * @param[in] i_path Path of the dbus object |
| 52 | * @param[in] i_service Service implementing the dbus object and interface |
| 53 | * @param[in] i_property Property to read |
| 54 | * @return non-zero on error |
| 55 | */ |
| 56 | int getProperty(const std::string& i_interface, const std::string& i_path, |
| 57 | const std::string& i_service, const std::string& i_property, |
| 58 | DBusValue& o_response); |
| 59 | |
Deepa Karthikeyan | a92dc02 | 2024-04-16 03:45:57 -0500 | [diff] [blame] | 60 | template <typename T> |
| 61 | void setProperty(const std::string& service, const std::string& object, |
| 62 | const std::string& interface, const std::string& propertyName, |
| 63 | const std::variant<T>& propertyValue) |
| 64 | { |
| 65 | try |
| 66 | { |
| 67 | auto bus = sdbusplus::bus::new_default(); |
| 68 | auto method = bus.new_method_call(service.c_str(), object.c_str(), |
| 69 | "org.freedesktop.DBus.Properties", |
| 70 | "Set"); |
| 71 | method.append(interface); |
| 72 | method.append(propertyName); |
| 73 | method.append(propertyValue); |
| 74 | |
| 75 | bus.call(method); |
| 76 | } |
| 77 | catch (const sdbusplus::exception::SdBusError& e) |
| 78 | { |
| 79 | trace::err("util::dbus::setProperty exception"); |
| 80 | std::string traceMsg = std::string(e.what()); |
| 81 | trace::err(traceMsg.c_str()); |
| 82 | } |
| 83 | } |
| 84 | |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 85 | /** |
| 86 | * Get the IBM compatible names defined for this system |
| 87 | * |
| 88 | * @return A vector of strings containing the system names |
| 89 | */ |
| 90 | std::vector<std::string> systemNames(); |
| 91 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 92 | /** @brief Host transition states for host transition operations */ |
Ben Tyner | 9306716 | 2021-07-23 10:39:30 -0500 | [diff] [blame] | 93 | enum class HostState |
| 94 | { |
| 95 | Quiesce, |
| 96 | Diagnostic, |
| 97 | Crash |
| 98 | }; |
| 99 | |
| 100 | /** |
| 101 | * @brief Transition the host state |
| 102 | * |
| 103 | * We will transition the host state by starting the appropriate dbus target. |
| 104 | * |
| 105 | * @param i_hostState the state to transition the host to |
| 106 | */ |
| 107 | void transitionHost(const HostState i_hostState); |
| 108 | |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 109 | /** |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 110 | * @brief Read autoRebootEnabled property |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 111 | * |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 112 | * @return false if autoRebootEnabled policy false, else true |
Ben Tyner | ffb4867 | 2021-07-23 12:29:03 -0500 | [diff] [blame] | 113 | */ |
| 114 | bool autoRebootEnabled(); |
| 115 | |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 116 | /** @brief Host running states for host running operations */ |
| 117 | enum class HostRunningState |
| 118 | { |
| 119 | Unknown, |
| 120 | NotStarted, |
Andrew Geissler | 1ff926e | 2023-01-26 08:14:22 -0700 | [diff] [blame] | 121 | Started, |
| 122 | Stopping |
Ben Tyner | fe2c50d | 2021-07-23 13:38:53 -0500 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /** |
| 126 | * Get the host running state |
| 127 | * |
| 128 | * Use host boot progress to determine if a host has been started. If host |
| 129 | * boot progress can not be determined then host state will be unknown. |
| 130 | * |
| 131 | * @return HostType == "Unknown", "Started or "NotStarted" |
| 132 | */ |
| 133 | HostRunningState hostRunningState(); |
| 134 | |
Ben Tyner | 39fcf65 | 2021-10-19 20:38:29 -0500 | [diff] [blame] | 135 | /** |
| 136 | * @brief Read dumpPolicyEnabled property |
| 137 | * |
| 138 | * @return false if dumpPolicyEnabled property is false, else true |
| 139 | */ |
| 140 | bool dumpPolicyEnabled(); |
| 141 | |
Ben Tyner | 1315968 | 2022-02-16 14:55:38 -0600 | [diff] [blame] | 142 | /** |
| 143 | * Create a PEL |
| 144 | * |
| 145 | * The additional data provided in the map will be placed in a user data |
| 146 | * section of the PEL and may additionally contain key words to trigger |
| 147 | * certain behaviors by the backend logging code. Each set of data described |
| 148 | * in the vector of ffdc data will be placed in additional user data |
| 149 | * sections. Note that the PID of the caller will be added to the additional |
| 150 | * data map with key "_PID". |
| 151 | * |
| 152 | * @param i_message - the event type |
| 153 | * @param i_severity - the severity level |
| 154 | * @param io_additional - map of additional data |
| 155 | * @param i_ffdc - vector of ffdc data |
| 156 | * @return Platform log id or 0 if error |
| 157 | */ |
| 158 | uint32_t createPel(const std::string& i_message, const std::string& i_severity, |
| 159 | std::map<std::string, std::string>& io_additional, |
| 160 | const std::vector<FFDCTuple>& i_ffdc); |
| 161 | |
Caleb Palmer | 626270a | 2022-02-21 11:05:08 -0600 | [diff] [blame] | 162 | /** @brief Machine ID definitions */ |
| 163 | enum class MachineType |
| 164 | { |
| 165 | Rainier_2S4U, |
| 166 | Rainier_2S2U, |
| 167 | Rainier_1S4U, |
| 168 | Rainier_1S2U, |
| 169 | Everest, |
Zane Shelley | a7dc66b | 2023-11-06 14:01:18 -0600 | [diff] [blame] | 170 | Bonnell, |
Caleb Palmer | 626270a | 2022-02-21 11:05:08 -0600 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | /** |
| 174 | * @brief Read the System IM keyword to get the machine type |
| 175 | * |
| 176 | * @return An enum representing the machine type |
| 177 | */ |
| 178 | MachineType getMachineType(); |
| 179 | |
Ben Tyner | 88b1009 | 2022-12-14 20:43:50 -0600 | [diff] [blame] | 180 | /** @brief Get list of state sensor PDRs |
| 181 | * |
| 182 | * @param[out] pdrList - list of PDRs |
| 183 | * @param[in] stateSetId - ID of the state set of interest |
| 184 | * |
| 185 | * @return true if successful otherwise false |
| 186 | */ |
| 187 | bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList, |
| 188 | uint16_t stateSetId); |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 189 | |
Ben Tyner | 88b1009 | 2022-12-14 20:43:50 -0600 | [diff] [blame] | 190 | /** @brief Get list of state effecter PDRs |
| 191 | * |
| 192 | * @param[out] pdrList - list of PDRs |
| 193 | * @param[in] stateSetId - ID of the state set of interest |
| 194 | * |
| 195 | * @return true if successful otherwise false |
| 196 | */ |
| 197 | bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList, |
| 198 | uint16_t stateSetId); |
| 199 | |
| 200 | /** |
| 201 | * @brief Get MCTP instance ID associated with endpoint |
| 202 | * |
| 203 | * @param[out] mctpInstance - instance of MCTP |
| 204 | * @param[in] Eid - MCTP enpoint ID |
| 205 | * |
| 206 | * @return True on success otherwise False |
| 207 | */ |
| 208 | bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid); |
| 209 | |
Ben Tyner | 2b26b2b | 2022-12-15 15:42:02 -0600 | [diff] [blame] | 210 | /** |
| 211 | * @brief Determine if power fault was detected |
| 212 | * |
| 213 | * @return true if power fault or unknown, false otherwise |
| 214 | */ |
| 215 | bool powerFault(); |
| 216 | |
Ben Tyner | 88b1009 | 2022-12-14 20:43:50 -0600 | [diff] [blame] | 217 | } // namespace dbus |
Ben Tyner | 324234b | 2021-06-28 17:01:17 -0500 | [diff] [blame] | 218 | } // namespace util |