blob: c1dc252958da96c6af2356f8649a0cc9ef48e7fd [file] [log] [blame]
Ben Tyner324234b2021-06-28 17:01:17 -05001#pragma once
2
3#include <sdbusplus/bus.hpp>
Ben Tyner13159682022-02-16 14:55:38 -06004#include <util/ffdc_file.hpp>
Deepa Karthikeyana92dc022024-04-16 03:45:57 -05005#include <util/trace.hpp>
Ben Tyner324234b2021-06-28 17:01:17 -05006
7#include <string>
8#include <variant>
9#include <vector>
10
11namespace util
12{
Ben Tyner324234b2021-06-28 17:01:17 -050013namespace dbus
14{
Patrick Williams27dd6362023-05-10 07:51:20 -050015using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>,
Ben Tyner2b26b2b2022-12-15 15:42:02 -060016 std::vector<std::string>, int32_t>;
Patrick Williams27dd6362023-05-10 07:51:20 -050017using DBusProperty = std::string;
18using DBusInterface = std::string;
19using DBusService = std::string;
20using DBusPath = std::string;
Ben Tyner324234b2021-06-28 17:01:17 -050021using DBusInterfaceList = std::vector<DBusInterface>;
22using 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 */
33int 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 */
44int 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 */
56int 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 Karthikeyana92dc022024-04-16 03:45:57 -050060template <typename T>
61void 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 Tyner324234b2021-06-28 17:01:17 -050085/**
86 * Get the IBM compatible names defined for this system
87 *
88 * @return A vector of strings containing the system names
89 */
90std::vector<std::string> systemNames();
91
Ben Tynerfe2c50d2021-07-23 13:38:53 -050092/** @brief Host transition states for host transition operations */
Ben Tyner93067162021-07-23 10:39:30 -050093enum 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 */
107void transitionHost(const HostState i_hostState);
108
Ben Tynerffb48672021-07-23 12:29:03 -0500109/**
Ben Tyner39fcf652021-10-19 20:38:29 -0500110 * @brief Read autoRebootEnabled property
Ben Tynerffb48672021-07-23 12:29:03 -0500111 *
Ben Tyner39fcf652021-10-19 20:38:29 -0500112 * @return false if autoRebootEnabled policy false, else true
Ben Tynerffb48672021-07-23 12:29:03 -0500113 */
114bool autoRebootEnabled();
115
Ben Tynerfe2c50d2021-07-23 13:38:53 -0500116/** @brief Host running states for host running operations */
117enum class HostRunningState
118{
119 Unknown,
120 NotStarted,
Andrew Geissler1ff926e2023-01-26 08:14:22 -0700121 Started,
122 Stopping
Ben Tynerfe2c50d2021-07-23 13:38:53 -0500123};
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 */
133HostRunningState hostRunningState();
134
Ben Tyner39fcf652021-10-19 20:38:29 -0500135/**
136 * @brief Read dumpPolicyEnabled property
137 *
138 * @return false if dumpPolicyEnabled property is false, else true
139 */
140bool dumpPolicyEnabled();
141
Ben Tyner13159682022-02-16 14:55:38 -0600142/**
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 */
158uint32_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 Palmer626270a2022-02-21 11:05:08 -0600162/** @brief Machine ID definitions */
163enum class MachineType
164{
165 Rainier_2S4U,
166 Rainier_2S2U,
167 Rainier_1S4U,
168 Rainier_1S2U,
169 Everest,
Zane Shelleya7dc66b2023-11-06 14:01:18 -0600170 Bonnell,
Caleb Palmer626270a2022-02-21 11:05:08 -0600171};
172
173/**
174 * @brief Read the System IM keyword to get the machine type
175 *
176 * @return An enum representing the machine type
177 */
178MachineType getMachineType();
179
Ben Tyner88b10092022-12-14 20:43:50 -0600180/** @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 */
187bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList,
188 uint16_t stateSetId);
Ben Tyner324234b2021-06-28 17:01:17 -0500189
Ben Tyner88b10092022-12-14 20:43:50 -0600190/** @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 */
197bool 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 */
208bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid);
209
Ben Tyner2b26b2b2022-12-15 15:42:02 -0600210/**
211 * @brief Determine if power fault was detected
212 *
213 * @return true if power fault or unknown, false otherwise
214 */
215bool powerFault();
216
Ben Tyner88b10092022-12-14 20:43:50 -0600217} // namespace dbus
Ben Tyner324234b2021-06-28 17:01:17 -0500218} // namespace util