blob: b4f090fe843b693f8651f1ea4cd63f8c5f545197 [file] [log] [blame]
Tom Josephbe703f72017-03-09 12:34:35 +05301#pragma once
2
Ratan Guptacc8feb42017-07-25 21:52:10 +05303#include "types.hpp"
Tom Josephbe703f72017-03-09 12:34:35 +05304#include <sdbusplus/server.hpp>
5
6namespace ipmi
7{
8
Ratan Guptacc8feb42017-07-25 21:52:10 +05309constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper";
10constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper";
11constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper";
12
13constexpr auto ROOT = "/";
14constexpr auto HOST_MATCH = "host0";
Ratan Guptacc8feb42017-07-25 21:52:10 +053015
Ratan Guptab8e99552017-07-27 07:07:48 +053016constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties";
17constexpr auto DELETE_INTERFACE = "xyz.openbmc_project.Object.Delete";
Ratan Guptacc8feb42017-07-25 21:52:10 +053018
19constexpr auto METHOD_GET = "Get";
20constexpr auto METHOD_GET_ALL = "GetAll";
21constexpr auto METHOD_SET = "Set";
22
Tom Josephbe703f72017-03-09 12:34:35 +053023/**
24 * @brief Get the DBUS Service name for the input dbus path
25 *
26 * @param[in] bus - DBUS Bus Object
27 * @param[in] intf - DBUS Interface
28 * @param[in] path - DBUS Object Path
29 *
30 */
31std::string getService(sdbusplus::bus::bus& bus,
32 const std::string& intf,
33 const std::string& path);
Ratan Guptacc8feb42017-07-25 21:52:10 +053034
35/** @brief Gets the dbus object info implementing the given interface
36 * from the given subtree.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053037 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053038 * @param[in] interface - Dbus interface.
39 * @param[in] subtreePath - subtree from where the search should start.
40 * @param[in] match - identifier for object.
41 * @return On success returns the object having objectpath and servicename.
42 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053043DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus,
44 const std::string& interface,
Ratan Guptacc8feb42017-07-25 21:52:10 +053045 const std::string& subtreePath = ROOT,
46 const std::string& match = {});
47
Ratan Guptadd646202017-11-21 17:46:59 +053048/** @brief Get the ipObject of first dbus IP object of Non-LinkLocalIPAddress
Gunnar Mills8991dd62017-10-25 17:11:29 -050049 * type from the given subtree, if not available gets IP object of
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -050050 * LinkLocalIPAddress type.
51 * @param[in] bus - DBUS Bus Object.
52 * @param[in] interface - Dbus interface.
53 * @param[in] subtreePath - subtree from where the search should start.
54 * @param[in] match - identifier for object.
Ratan Guptadd646202017-11-21 17:46:59 +053055 * @return On success returns the object having objectpath and servicename.
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -050056 */
Ratan Guptadd646202017-11-21 17:46:59 +053057DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus,
58 const std::string& interface,
59 const std::string& subtreePath,
60 const std::string& match);
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -050061
Ratan Guptacc8feb42017-07-25 21:52:10 +053062/** @brief Gets the value associated with the given object
63 * and the interface.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053064 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053065 * @param[in] service - Dbus service name.
66 * @param[in] objPath - Dbus object path.
67 * @param[in] interface - Dbus interface.
68 * @param[in] property - name of the property.
69 * @return On success returns the value of the property.
70 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053071Value getDbusProperty(sdbusplus::bus::bus& bus,
72 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +053073 const std::string& objPath,
74 const std::string& interface,
75 const std::string& property);
76
77/** @brief Gets all the properties associated with the given object
78 * and the interface.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053079 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053080 * @param[in] service - Dbus service name.
81 * @param[in] objPath - Dbus object path.
82 * @param[in] interface - Dbus interface.
83 * @return On success returns the map of name value pair.
84 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053085PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus,
86 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +053087 const std::string& objPath,
88 const std::string& interface);
89
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -060090/** @brief Gets all managed objects associated with the given object
91 * path and service.
92 * @param[in] bus - D-Bus Bus Object.
93 * @param[in] service - D-Bus service name.
94 * @param[in] objPath - D-Bus object path.
95 * @return On success returns the map of name value pair.
96 */
97ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus,
98 const std::string& service,
99 const std::string& objPath);
100
Ratan Guptacc8feb42017-07-25 21:52:10 +0530101/** @brief Sets the property value of the given object.
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530102 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +0530103 * @param[in] service - Dbus service name.
104 * @param[in] objPath - Dbus object path.
105 * @param[in] interface - Dbus interface.
106 * @param[in] property - name of the property.
107 * @param[in] value - value which needs to be set.
108 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +0530109void setDbusProperty(sdbusplus::bus::bus& bus,
110 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530111 const std::string& objPath,
112 const std::string& interface,
113 const std::string& property,
114 const Value& value);
115
Ratan Guptab8e99552017-07-27 07:07:48 +0530116/** @brief Gets all the dbus objects from the given service root
117 * which matches the object identifier.
118 * @param[in] bus - DBUS Bus Object.
119 * @param[in] serviceRoot - Service root path.
120 * @param[in] interface - Dbus interface.
121 * @param[in] match - Identifier for a path.
122 * @returns map of object path and service info.
123 */
124ObjectTree getAllDbusObjects(sdbusplus::bus::bus& bus,
125 const std::string& serviceRoot,
126 const std::string& interface,
127 const std::string& match);
128
129/** @brief Deletes all the dbus objects from the given service root
130 which matches the object identifier.
131 * @param[in] bus - DBUS Bus Object.
132 * @param[in] serviceRoot - Service root path.
133 * @param[in] interface - Dbus interface.
134 * @param[in] match - Identifier for object.
135 */
136void deleteAllDbusObjects(sdbusplus::bus::bus& bus,
137 const std::string& serviceRoot,
138 const std::string& interface,
139 const std::string& match = {});
140
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530141/** @brief Gets the ancestor objects of the given object
142 which implements the given interface.
143 * @param[in] bus - Dbus bus object.
144 * @param[in] path - Child Dbus object path.
145 * @param[in] interfaces - Dbus interface list.
146 * @return map of object path and service info.
147 */
148ObjectTree getAllAncestors(sdbusplus::bus::bus& bus,
149 const std::string& path,
150 InterfaceList&& interfaces);
151
Ratan Guptab8e99552017-07-27 07:07:48 +0530152namespace method_no_args
153{
154
155/** @brief Calls the Dbus method which waits for response.
156 * @param[in] bus - DBUS Bus Object.
157 * @param[in] service - Dbus service name.
158 * @param[in] objPath - Dbus object path.
159 * @param[in] interface - Dbus interface.
160 * @param[in] method - Dbus method.
161 */
162void callDbusMethod(sdbusplus::bus::bus& bus,
163 const std::string& service,
164 const std::string& objPath,
165 const std::string& interface,
166 const std::string& method);
167
168} //namespace method_no_args
169
170namespace network
171{
172
173constexpr auto ROOT = "/xyz/openbmc_project/network";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530174constexpr auto SERVICE = "xyz.openbmc_project.Network";
Ratan Guptab8e99552017-07-27 07:07:48 +0530175constexpr auto IP_TYPE = "ipv4";
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -0500176constexpr auto IPV4_PREFIX = "169.254";
177constexpr auto IPV6_PREFIX = "fe80";
Ratan Guptab8e99552017-07-27 07:07:48 +0530178constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
179constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
180constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration";
181constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface";
182constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530183constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create";
184constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN";
Ratan Guptab8e99552017-07-27 07:07:48 +0530185
186/* @brief converts the given subnet into prefix notation.
187 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
188 * @param[in] mask - Subnet Mask.
189 * @returns prefix.
190 */
191uint8_t toPrefix(int addressFamily, const std::string& subnetMask);
192
193
194/** @brief Sets the ip on the system.
195 * @param[in] bus - DBUS Bus Object.
196 * @param[in] service - Dbus service name.
197 * @param[in] objPath - Dbus object path.
198 * @param[in] protocolType - Protocol type
199 * @param[in] ipaddress - IPaddress.
200 * @param[in] prefix - Prefix length.
201 */
202void createIP(sdbusplus::bus::bus& bus,
203 const std::string& service,
204 const std::string& objPath,
205 const std::string& protocolType,
206 const std::string& ipaddress,
207 uint8_t prefix);
208
Ratan Gupta533d03b2017-07-30 10:39:22 +0530209/** @brief Creates the VLAN on the given interface.
210 * @param[in] bus - DBUS Bus Object.
211 * @param[in] service - Dbus service name.
212 * @param[in] objPath - Dbus object path.
213 * @param[in] interface - EthernetInterface.
214 * @param[in] vlanID - Vlan ID.
215 */
216void createVLAN(sdbusplus::bus::bus& bus,
217 const std::string& service,
218 const std::string& objPath,
219 const std::string& interface,
220 uint32_t vlanID);
Ratan Guptab8e99552017-07-27 07:07:48 +0530221
Ratan Gupta533d03b2017-07-30 10:39:22 +0530222/** @brief Gets the vlan id from the given object path.
223 * @param[in] path - Dbus object path.
224 */
225uint32_t getVLAN(const std::string& path);
226
227} //namespace network
Tom Josephbe703f72017-03-09 12:34:35 +0530228} // namespace ipmi
229
230