1324234b4SBen Tyner #pragma once
2324234b4SBen Tyner
3324234b4SBen Tyner #include <sdbusplus/bus.hpp>
41315968cSBen Tyner #include <util/ffdc_file.hpp>
5a92dc027SDeepa Karthikeyan #include <util/trace.hpp>
6324234b4SBen Tyner
7324234b4SBen Tyner #include <string>
8324234b4SBen Tyner #include <variant>
9324234b4SBen Tyner #include <vector>
10324234b4SBen Tyner
11324234b4SBen Tyner namespace util
12324234b4SBen Tyner {
13324234b4SBen Tyner namespace dbus
14324234b4SBen Tyner {
15324234b4SBen Tyner using DBusValue = std::variant<std::string, bool, std::vector<uint8_t>,
162b26b2bbSBen Tyner std::vector<std::string>, int32_t>;
17324234b4SBen Tyner using DBusProperty = std::string;
18324234b4SBen Tyner using DBusInterface = std::string;
19324234b4SBen Tyner using DBusService = std::string;
20324234b4SBen Tyner using DBusPath = std::string;
21324234b4SBen Tyner using DBusInterfaceList = std::vector<DBusInterface>;
22324234b4SBen Tyner using DBusSubTree =
23324234b4SBen Tyner std::map<DBusPath, std::map<DBusService, DBusInterfaceList>>;
24324234b4SBen Tyner
25324234b4SBen Tyner /**
26324234b4SBen Tyner * Find the dbus object path and service that implements the given interface
27324234b4SBen Tyner *
28324234b4SBen Tyner * @param[in] i_interface Interface to search for
29324234b4SBen Tyner * @param[out] o_path Path of dbus object implementing the interface
30324234b4SBen Tyner * @param[out] o_service Service implementing the dbus object path
31324234b4SBen Tyner * @return non-zero on error
32324234b4SBen Tyner */
33324234b4SBen Tyner int find(const std::string& i_interface, std::string& o_path,
34324234b4SBen Tyner std::string& o_service);
35324234b4SBen Tyner
36324234b4SBen Tyner /**
37324234b4SBen Tyner * Find the dbus service that implements the given dbus object and interface
38324234b4SBen Tyner *
39324234b4SBen Tyner * @param[in] i_interface Interface that maps to the service
40324234b4SBen Tyner * @param[in] i_path Path that maps to the service
41324234b4SBen Tyner * @param[out] o_service Service implementing the dbus object and interface
42324234b4SBen Tyner * @return non-zer on error
43324234b4SBen Tyner */
44324234b4SBen Tyner int findService(const std::string& i_interface, const std::string& i_path,
45324234b4SBen Tyner std::string& o_service);
46324234b4SBen Tyner
47324234b4SBen Tyner /**
48324234b4SBen Tyner * Read a property from a dbus object interface
49324234b4SBen Tyner *
50324234b4SBen Tyner * @param[in] i_interface Interface implementing the property
51324234b4SBen Tyner * @param[in] i_path Path of the dbus object
52324234b4SBen Tyner * @param[in] i_service Service implementing the dbus object and interface
53324234b4SBen Tyner * @param[in] i_property Property to read
54324234b4SBen Tyner * @return non-zero on error
55324234b4SBen Tyner */
56324234b4SBen Tyner int getProperty(const std::string& i_interface, const std::string& i_path,
57324234b4SBen Tyner const std::string& i_service, const std::string& i_property,
58324234b4SBen Tyner DBusValue& o_response);
59324234b4SBen Tyner
60a92dc027SDeepa Karthikeyan template <typename T>
setProperty(const std::string & service,const std::string & object,const std::string & interface,const std::string & propertyName,const std::variant<T> & propertyValue)61a92dc027SDeepa Karthikeyan void setProperty(const std::string& service, const std::string& object,
62a92dc027SDeepa Karthikeyan const std::string& interface, const std::string& propertyName,
63a92dc027SDeepa Karthikeyan const std::variant<T>& propertyValue)
64a92dc027SDeepa Karthikeyan {
65a92dc027SDeepa Karthikeyan try
66a92dc027SDeepa Karthikeyan {
67a92dc027SDeepa Karthikeyan auto bus = sdbusplus::bus::new_default();
68a0c724d3SPatrick Williams auto method =
69a0c724d3SPatrick Williams bus.new_method_call(service.c_str(), object.c_str(),
70a0c724d3SPatrick Williams "org.freedesktop.DBus.Properties", "Set");
71a92dc027SDeepa Karthikeyan method.append(interface);
72a92dc027SDeepa Karthikeyan method.append(propertyName);
73a92dc027SDeepa Karthikeyan method.append(propertyValue);
74a92dc027SDeepa Karthikeyan
75a92dc027SDeepa Karthikeyan bus.call(method);
76a92dc027SDeepa Karthikeyan }
77a92dc027SDeepa Karthikeyan catch (const sdbusplus::exception::SdBusError& e)
78a92dc027SDeepa Karthikeyan {
79a92dc027SDeepa Karthikeyan trace::err("util::dbus::setProperty exception");
80a92dc027SDeepa Karthikeyan std::string traceMsg = std::string(e.what());
81a92dc027SDeepa Karthikeyan trace::err(traceMsg.c_str());
82a92dc027SDeepa Karthikeyan }
83a92dc027SDeepa Karthikeyan }
84a92dc027SDeepa Karthikeyan
85324234b4SBen Tyner /**
86324234b4SBen Tyner * Get the IBM compatible names defined for this system
87324234b4SBen Tyner *
88324234b4SBen Tyner * @return A vector of strings containing the system names
89324234b4SBen Tyner */
90324234b4SBen Tyner std::vector<std::string> systemNames();
91324234b4SBen Tyner
92fe2c50d7SBen Tyner /** @brief Host transition states for host transition operations */
939306716dSBen Tyner enum class HostState
949306716dSBen Tyner {
959306716dSBen Tyner Quiesce,
969306716dSBen Tyner Diagnostic,
979306716dSBen Tyner Crash
989306716dSBen Tyner };
999306716dSBen Tyner
1009306716dSBen Tyner /**
1019306716dSBen Tyner * @brief Transition the host state
1029306716dSBen Tyner *
1039306716dSBen Tyner * We will transition the host state by starting the appropriate dbus target.
1049306716dSBen Tyner *
1059306716dSBen Tyner * @param i_hostState the state to transition the host to
1069306716dSBen Tyner */
1079306716dSBen Tyner void transitionHost(const HostState i_hostState);
1089306716dSBen Tyner
109ffb4867fSBen Tyner /**
11039fcf65dSBen Tyner * @brief Read autoRebootEnabled property
111ffb4867fSBen Tyner *
11239fcf65dSBen Tyner * @return false if autoRebootEnabled policy false, else true
113ffb4867fSBen Tyner */
114ffb4867fSBen Tyner bool autoRebootEnabled();
115ffb4867fSBen Tyner
116fe2c50d7SBen Tyner /** @brief Host running states for host running operations */
117fe2c50d7SBen Tyner enum class HostRunningState
118fe2c50d7SBen Tyner {
119fe2c50d7SBen Tyner Unknown,
120fe2c50d7SBen Tyner NotStarted,
1211ff926e0SAndrew Geissler Started,
1221ff926e0SAndrew Geissler Stopping
123fe2c50d7SBen Tyner };
124fe2c50d7SBen Tyner
125fe2c50d7SBen Tyner /**
126fe2c50d7SBen Tyner * Get the host running state
127fe2c50d7SBen Tyner *
128fe2c50d7SBen Tyner * Use host boot progress to determine if a host has been started. If host
129fe2c50d7SBen Tyner * boot progress can not be determined then host state will be unknown.
130fe2c50d7SBen Tyner *
131fe2c50d7SBen Tyner * @return HostType == "Unknown", "Started or "NotStarted"
132fe2c50d7SBen Tyner */
133fe2c50d7SBen Tyner HostRunningState hostRunningState();
134fe2c50d7SBen Tyner
13539fcf65dSBen Tyner /**
13639fcf65dSBen Tyner * @brief Read dumpPolicyEnabled property
13739fcf65dSBen Tyner *
13839fcf65dSBen Tyner * @return false if dumpPolicyEnabled property is false, else true
13939fcf65dSBen Tyner */
14039fcf65dSBen Tyner bool dumpPolicyEnabled();
14139fcf65dSBen Tyner
1421315968cSBen Tyner /**
1431315968cSBen Tyner * Create a PEL
1441315968cSBen Tyner *
1451315968cSBen Tyner * The additional data provided in the map will be placed in a user data
1461315968cSBen Tyner * section of the PEL and may additionally contain key words to trigger
1471315968cSBen Tyner * certain behaviors by the backend logging code. Each set of data described
1481315968cSBen Tyner * in the vector of ffdc data will be placed in additional user data
1491315968cSBen Tyner * sections. Note that the PID of the caller will be added to the additional
1501315968cSBen Tyner * data map with key "_PID".
1511315968cSBen Tyner *
1521315968cSBen Tyner * @param i_message - the event type
1531315968cSBen Tyner * @param i_severity - the severity level
1541315968cSBen Tyner * @param io_additional - map of additional data
1551315968cSBen Tyner * @param i_ffdc - vector of ffdc data
1561315968cSBen Tyner * @return Platform log id or 0 if error
1571315968cSBen Tyner */
1581315968cSBen Tyner uint32_t createPel(const std::string& i_message, const std::string& i_severity,
1591315968cSBen Tyner std::map<std::string, std::string>& io_additional,
1601315968cSBen Tyner const std::vector<FFDCTuple>& i_ffdc);
1611315968cSBen Tyner
162626270afSCaleb Palmer /** @brief Machine ID definitions */
163626270afSCaleb Palmer enum class MachineType
164626270afSCaleb Palmer {
165626270afSCaleb Palmer Rainier_2S4U,
166626270afSCaleb Palmer Rainier_2S2U,
167626270afSCaleb Palmer Rainier_1S4U,
168626270afSCaleb Palmer Rainier_1S2U,
169626270afSCaleb Palmer Everest,
170a7dc66baSZane Shelley Bonnell,
171626270afSCaleb Palmer };
172626270afSCaleb Palmer
173626270afSCaleb Palmer /**
174626270afSCaleb Palmer * @brief Read the System IM keyword to get the machine type
175626270afSCaleb Palmer *
176626270afSCaleb Palmer * @return An enum representing the machine type
177626270afSCaleb Palmer */
178626270afSCaleb Palmer MachineType getMachineType();
179626270afSCaleb Palmer
18088b10093SBen Tyner /** @brief Get list of state sensor PDRs
18188b10093SBen Tyner *
18288b10093SBen Tyner * @param[out] pdrList - list of PDRs
18388b10093SBen Tyner * @param[in] stateSetId - ID of the state set of interest
18488b10093SBen Tyner *
18588b10093SBen Tyner * @return true if successful otherwise false
18688b10093SBen Tyner */
18788b10093SBen Tyner bool getStateSensorPdrs(std::vector<std::vector<uint8_t>>& pdrList,
18888b10093SBen Tyner uint16_t stateSetId);
189324234b4SBen Tyner
19088b10093SBen Tyner /** @brief Get list of state effecter PDRs
19188b10093SBen Tyner *
19288b10093SBen Tyner * @param[out] pdrList - list of PDRs
19388b10093SBen Tyner * @param[in] stateSetId - ID of the state set of interest
19488b10093SBen Tyner *
19588b10093SBen Tyner * @return true if successful otherwise false
19688b10093SBen Tyner */
19788b10093SBen Tyner bool getStateEffecterPdrs(std::vector<std::vector<uint8_t>>& pdrList,
19888b10093SBen Tyner uint16_t stateSetId);
19988b10093SBen Tyner
20088b10093SBen Tyner /**
201*08f25b21SPavithra Barithaya * @brief Get PLDM instance ID associated with endpoint
20288b10093SBen Tyner *
203*08f25b21SPavithra Barithaya * @param[out] pldmInstanceID - PLDM instance id
20488b10093SBen Tyner * @param[in] Eid - MCTP enpoint ID
20588b10093SBen Tyner *
20688b10093SBen Tyner * @return True on success otherwise False
20788b10093SBen Tyner */
208*08f25b21SPavithra Barithaya bool getPldmInstanceID(uint8_t& pldmInstanceID, uint8_t Eid);
20988b10093SBen Tyner
2102b26b2bbSBen Tyner /**
2112b26b2bbSBen Tyner * @brief Determine if power fault was detected
2122b26b2bbSBen Tyner *
2132b26b2bbSBen Tyner * @return true if power fault or unknown, false otherwise
2142b26b2bbSBen Tyner */
2152b26b2bbSBen Tyner bool powerFault();
2162b26b2bbSBen Tyner
21788b10093SBen Tyner } // namespace dbus
218324234b4SBen Tyner } // namespace util
219