blob: bbc50ad6f4a0171f068af5e3b9482e318dc9615c [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>
Ben Tyner324234b2021-06-28 17:01:17 -05005
6#include <string>
7#include <variant>
8#include <vector>
9
10namespace util
11{
Ben Tyner324234b2021-06-28 17:01:17 -050012namespace dbus
13{
Ben Tyner324234b2021-06-28 17:01:17 -050014using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>,
Ben Tyner2b26b2b2022-12-15 15:42:02 -060015 std::vector<std::string>, int32_t>;
Ben Tyner324234b2021-06-28 17:01:17 -050016using DBusProperty = std::string;
17using DBusInterface = std::string;
18using DBusService = std::string;
19using DBusPath = std::string;
20using DBusInterfaceList = std::vector<DBusInterface>;
21using DBusSubTree =
22 std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>;
23
24/**
25 * Find the dbus object path and service that implements the given interface
26 *
27 * @param[in] i_interface Interface to search for
28 * @param[out] o_path Path of dbus object implementing the interface
29 * @param[out] o_service Service implementing the dbus object path
30 * @return non-zero on error
31 */
32int find(const std::string& i_interface, std::string& o_path,
33 std::string& o_service);
34
35/**
36 * Find the dbus service that implements the given dbus object and interface
37 *
38 * @param[in] i_interface Interface that maps to the service
39 * @param[in] i_path Path that maps to the service
40 * @param[out] o_service Service implementing the dbus object and interface
41 * @return non-zer on error
42 */
43int findService(const std::string& i_interface, const std::string& i_path,
44 std::string& o_service);
45
46/**
47 * Read a property from a dbus object interface
48 *
49 * @param[in] i_interface Interface implementing the property
50 * @param[in] i_path Path of the dbus object
51 * @param[in] i_service Service implementing the dbus object and interface
52 * @param[in] i_property Property to read
53 * @return non-zero on error
54 */
55int getProperty(const std::string& i_interface, const std::string& i_path,
56 const std::string& i_service, const std::string& i_property,
57 DBusValue& o_response);
58
59/**
60 * Get the IBM compatible names defined for this system
61 *
62 * @return A vector of strings containing the system names
63 */
64std::vector<std::string> systemNames();
65
Ben Tynerfe2c50d2021-07-23 13:38:53 -050066/** @brief Host transition states for host transition operations */
Ben Tyner93067162021-07-23 10:39:30 -050067enum class HostState
68{
69 Quiesce,
70 Diagnostic,
71 Crash
72};
73
74/**
75 * @brief Transition the host state
76 *
77 * We will transition the host state by starting the appropriate dbus target.
78 *
79 * @param i_hostState the state to transition the host to
80 */
81void transitionHost(const HostState i_hostState);
82
Ben Tynerffb48672021-07-23 12:29:03 -050083/**
Ben Tyner39fcf652021-10-19 20:38:29 -050084 * @brief Read autoRebootEnabled property
Ben Tynerffb48672021-07-23 12:29:03 -050085 *
Ben Tyner39fcf652021-10-19 20:38:29 -050086 * @return false if autoRebootEnabled policy false, else true
Ben Tynerffb48672021-07-23 12:29:03 -050087 */
88bool autoRebootEnabled();
89
Ben Tynerfe2c50d2021-07-23 13:38:53 -050090/** @brief Host running states for host running operations */
91enum class HostRunningState
92{
93 Unknown,
94 NotStarted,
Andrew Geissler1ff926e2023-01-26 08:14:22 -070095 Started,
96 Stopping
Ben Tynerfe2c50d2021-07-23 13:38:53 -050097};
98
99/**
100 * Get the host running state
101 *
102 * Use host boot progress to determine if a host has been started. If host
103 * boot progress can not be determined then host state will be unknown.
104 *
105 * @return HostType == "Unknown", "Started or "NotStarted"
106 */
107HostRunningState hostRunningState();
108
Ben Tyner39fcf652021-10-19 20:38:29 -0500109/**
110 * @brief Read dumpPolicyEnabled property
111 *
112 * @return false if dumpPolicyEnabled property is false, else true
113 */
114bool dumpPolicyEnabled();
115
Ben Tyner13159682022-02-16 14:55:38 -0600116/**
117 * Create a PEL
118 *
119 * The additional data provided in the map will be placed in a user data
120 * section of the PEL and may additionally contain key words to trigger
121 * certain behaviors by the backend logging code. Each set of data described
122 * in the vector of ffdc data will be placed in additional user data
123 * sections. Note that the PID of the caller will be added to the additional
124 * data map with key "_PID".
125 *
126 * @param i_message - the event type
127 * @param i_severity - the severity level
128 * @param io_additional - map of additional data
129 * @param i_ffdc - vector of ffdc data
130 * @return Platform log id or 0 if error
131 */
132uint32_t createPel(const std::string& i_message, const std::string& i_severity,
133 std::map<std::string, std::string>& io_additional,
134 const std::vector<FFDCTuple>& i_ffdc);
135
Caleb Palmer626270a2022-02-21 11:05:08 -0600136/** @brief Machine ID definitions */
137enum class MachineType
138{
139 Rainier_2S4U,
140 Rainier_2S2U,
141 Rainier_1S4U,
142 Rainier_1S2U,
143 Everest,
144};
145
146/**
147 * @brief Read the System IM keyword to get the machine type
148 *
149 * @return An enum representing the machine type
150 */
151MachineType getMachineType();
152
Ben Tyner88b10092022-12-14 20:43:50 -0600153/** @brief Get list of state sensor PDRs
154 *
155 * @param[out] pdrList - list of PDRs
156 * @param[in] stateSetId - ID of the state set of interest
157 *
158 * @return true if successful otherwise false
159 */
160bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList,
161 uint16_t stateSetId);
Ben Tyner324234b2021-06-28 17:01:17 -0500162
Ben Tyner88b10092022-12-14 20:43:50 -0600163/** @brief Get list of state effecter PDRs
164 *
165 * @param[out] pdrList - list of PDRs
166 * @param[in] stateSetId - ID of the state set of interest
167 *
168 * @return true if successful otherwise false
169 */
170bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList,
171 uint16_t stateSetId);
172
173/**
174 * @brief Get MCTP instance ID associated with endpoint
175 *
176 * @param[out] mctpInstance - instance of MCTP
177 * @param[in] Eid - MCTP enpoint ID
178 *
179 * @return True on success otherwise False
180 */
181bool getMctpInstance(uint8_t& mctpInstance, uint8_t Eid);
182
Ben Tyner2b26b2b2022-12-15 15:42:02 -0600183/**
184 * @brief Determine if power fault was detected
185 *
186 * @return true if power fault or unknown, false otherwise
187 */
188bool powerFault();
189
Ben Tyner88b10092022-12-14 20:43:50 -0600190} // namespace dbus
Ben Tyner324234b2021-06-28 17:01:17 -0500191} // namespace util