blob: 55978fb6246816c40acb2193cbed9e15af81ebbe [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
90/** @brief Sets the property value of the given object.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053091 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053092 * @param[in] service - Dbus service name.
93 * @param[in] objPath - Dbus object path.
94 * @param[in] interface - Dbus interface.
95 * @param[in] property - name of the property.
96 * @param[in] value - value which needs to be set.
97 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053098void setDbusProperty(sdbusplus::bus::bus& bus,
99 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +0530100 const std::string& objPath,
101 const std::string& interface,
102 const std::string& property,
103 const Value& value);
104
Ratan Guptab8e99552017-07-27 07:07:48 +0530105/** @brief Gets all the dbus objects from the given service root
106 * which matches the object identifier.
107 * @param[in] bus - DBUS Bus Object.
108 * @param[in] serviceRoot - Service root path.
109 * @param[in] interface - Dbus interface.
110 * @param[in] match - Identifier for a path.
111 * @returns map of object path and service info.
112 */
113ObjectTree getAllDbusObjects(sdbusplus::bus::bus& bus,
114 const std::string& serviceRoot,
115 const std::string& interface,
116 const std::string& match);
117
118/** @brief Deletes all the dbus objects from the given service root
119 which matches the object identifier.
120 * @param[in] bus - DBUS Bus Object.
121 * @param[in] serviceRoot - Service root path.
122 * @param[in] interface - Dbus interface.
123 * @param[in] match - Identifier for object.
124 */
125void deleteAllDbusObjects(sdbusplus::bus::bus& bus,
126 const std::string& serviceRoot,
127 const std::string& interface,
128 const std::string& match = {});
129
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530130/** @brief Gets the ancestor objects of the given object
131 which implements the given interface.
132 * @param[in] bus - Dbus bus object.
133 * @param[in] path - Child Dbus object path.
134 * @param[in] interfaces - Dbus interface list.
135 * @return map of object path and service info.
136 */
137ObjectTree getAllAncestors(sdbusplus::bus::bus& bus,
138 const std::string& path,
139 InterfaceList&& interfaces);
140
Ratan Guptab8e99552017-07-27 07:07:48 +0530141namespace method_no_args
142{
143
144/** @brief Calls the Dbus method which waits for response.
145 * @param[in] bus - DBUS Bus Object.
146 * @param[in] service - Dbus service name.
147 * @param[in] objPath - Dbus object path.
148 * @param[in] interface - Dbus interface.
149 * @param[in] method - Dbus method.
150 */
151void callDbusMethod(sdbusplus::bus::bus& bus,
152 const std::string& service,
153 const std::string& objPath,
154 const std::string& interface,
155 const std::string& method);
156
157} //namespace method_no_args
158
159namespace network
160{
161
162constexpr auto ROOT = "/xyz/openbmc_project/network";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530163constexpr auto SERVICE = "xyz.openbmc_project.Network";
Ratan Guptab8e99552017-07-27 07:07:48 +0530164constexpr auto INTERFACE = "eth0";
165constexpr auto IP_TYPE = "ipv4";
Nagaraju Goruganti1fe5c832017-09-21 07:44:17 -0500166constexpr auto IPV4_PREFIX = "169.254";
167constexpr auto IPV6_PREFIX = "fe80";
Ratan Guptab8e99552017-07-27 07:07:48 +0530168constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
169constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
170constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration";
171constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface";
172constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530173constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create";
174constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN";
Ratan Guptab8e99552017-07-27 07:07:48 +0530175
176/* @brief converts the given subnet into prefix notation.
177 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
178 * @param[in] mask - Subnet Mask.
179 * @returns prefix.
180 */
181uint8_t toPrefix(int addressFamily, const std::string& subnetMask);
182
183
184/** @brief Sets the ip on the system.
185 * @param[in] bus - DBUS Bus Object.
186 * @param[in] service - Dbus service name.
187 * @param[in] objPath - Dbus object path.
188 * @param[in] protocolType - Protocol type
189 * @param[in] ipaddress - IPaddress.
190 * @param[in] prefix - Prefix length.
191 */
192void createIP(sdbusplus::bus::bus& bus,
193 const std::string& service,
194 const std::string& objPath,
195 const std::string& protocolType,
196 const std::string& ipaddress,
197 uint8_t prefix);
198
Ratan Gupta533d03b2017-07-30 10:39:22 +0530199/** @brief Creates the VLAN on the given interface.
200 * @param[in] bus - DBUS Bus Object.
201 * @param[in] service - Dbus service name.
202 * @param[in] objPath - Dbus object path.
203 * @param[in] interface - EthernetInterface.
204 * @param[in] vlanID - Vlan ID.
205 */
206void createVLAN(sdbusplus::bus::bus& bus,
207 const std::string& service,
208 const std::string& objPath,
209 const std::string& interface,
210 uint32_t vlanID);
Ratan Guptab8e99552017-07-27 07:07:48 +0530211
Ratan Gupta533d03b2017-07-30 10:39:22 +0530212/** @brief Gets the vlan id from the given object path.
213 * @param[in] path - Dbus object path.
214 */
215uint32_t getVLAN(const std::string& path);
216
217} //namespace network
Tom Josephbe703f72017-03-09 12:34:35 +0530218} // namespace ipmi
219
220