blob: b50fde722241ac8e872d2ca46ebf711e17386705 [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
48/** @brief Gets the value associated with the given object
49 * and the interface.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053050 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053051 * @param[in] service - Dbus service name.
52 * @param[in] objPath - Dbus object path.
53 * @param[in] interface - Dbus interface.
54 * @param[in] property - name of the property.
55 * @return On success returns the value of the property.
56 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053057Value getDbusProperty(sdbusplus::bus::bus& bus,
58 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +053059 const std::string& objPath,
60 const std::string& interface,
61 const std::string& property);
62
63/** @brief Gets all the properties associated with the given object
64 * and the interface.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053065 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053066 * @param[in] service - Dbus service name.
67 * @param[in] objPath - Dbus object path.
68 * @param[in] interface - Dbus interface.
69 * @return On success returns the map of name value pair.
70 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053071PropertyMap getAllDbusProperties(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
76/** @brief Sets the property value of the given object.
Ratan Gupta01d4bd12017-08-07 15:53:25 +053077 * @param[in] bus - DBUS Bus Object.
Ratan Guptacc8feb42017-07-25 21:52:10 +053078 * @param[in] service - Dbus service name.
79 * @param[in] objPath - Dbus object path.
80 * @param[in] interface - Dbus interface.
81 * @param[in] property - name of the property.
82 * @param[in] value - value which needs to be set.
83 */
Ratan Gupta01d4bd12017-08-07 15:53:25 +053084void setDbusProperty(sdbusplus::bus::bus& bus,
85 const std::string& service,
Ratan Guptacc8feb42017-07-25 21:52:10 +053086 const std::string& objPath,
87 const std::string& interface,
88 const std::string& property,
89 const Value& value);
90
Ratan Guptab8e99552017-07-27 07:07:48 +053091/** @brief Gets all the dbus objects from the given service root
92 * which matches the object identifier.
93 * @param[in] bus - DBUS Bus Object.
94 * @param[in] serviceRoot - Service root path.
95 * @param[in] interface - Dbus interface.
96 * @param[in] match - Identifier for a path.
97 * @returns map of object path and service info.
98 */
99ObjectTree getAllDbusObjects(sdbusplus::bus::bus& bus,
100 const std::string& serviceRoot,
101 const std::string& interface,
102 const std::string& match);
103
104/** @brief Deletes all the dbus objects from the given service root
105 which matches the object identifier.
106 * @param[in] bus - DBUS Bus Object.
107 * @param[in] serviceRoot - Service root path.
108 * @param[in] interface - Dbus interface.
109 * @param[in] match - Identifier for object.
110 */
111void deleteAllDbusObjects(sdbusplus::bus::bus& bus,
112 const std::string& serviceRoot,
113 const std::string& interface,
114 const std::string& match = {});
115
Ratan Guptacc6cdbf2017-09-01 23:06:25 +0530116/** @brief Gets the ancestor objects of the given object
117 which implements the given interface.
118 * @param[in] bus - Dbus bus object.
119 * @param[in] path - Child Dbus object path.
120 * @param[in] interfaces - Dbus interface list.
121 * @return map of object path and service info.
122 */
123ObjectTree getAllAncestors(sdbusplus::bus::bus& bus,
124 const std::string& path,
125 InterfaceList&& interfaces);
126
Ratan Guptab8e99552017-07-27 07:07:48 +0530127namespace method_no_args
128{
129
130/** @brief Calls the Dbus method which waits for response.
131 * @param[in] bus - DBUS Bus Object.
132 * @param[in] service - Dbus service name.
133 * @param[in] objPath - Dbus object path.
134 * @param[in] interface - Dbus interface.
135 * @param[in] method - Dbus method.
136 */
137void callDbusMethod(sdbusplus::bus::bus& bus,
138 const std::string& service,
139 const std::string& objPath,
140 const std::string& interface,
141 const std::string& method);
142
143} //namespace method_no_args
144
145namespace network
146{
147
148constexpr auto ROOT = "/xyz/openbmc_project/network";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530149constexpr auto SERVICE = "xyz.openbmc_project.Network";
Ratan Guptab8e99552017-07-27 07:07:48 +0530150constexpr auto INTERFACE = "eth0";
151constexpr auto IP_TYPE = "ipv4";
152constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
153constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
154constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration";
155constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface";
156constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530157constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create";
158constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN";
Ratan Guptab8e99552017-07-27 07:07:48 +0530159
160/* @brief converts the given subnet into prefix notation.
161 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
162 * @param[in] mask - Subnet Mask.
163 * @returns prefix.
164 */
165uint8_t toPrefix(int addressFamily, const std::string& subnetMask);
166
167
168/** @brief Sets the ip on the system.
169 * @param[in] bus - DBUS Bus Object.
170 * @param[in] service - Dbus service name.
171 * @param[in] objPath - Dbus object path.
172 * @param[in] protocolType - Protocol type
173 * @param[in] ipaddress - IPaddress.
174 * @param[in] prefix - Prefix length.
175 */
176void createIP(sdbusplus::bus::bus& bus,
177 const std::string& service,
178 const std::string& objPath,
179 const std::string& protocolType,
180 const std::string& ipaddress,
181 uint8_t prefix);
182
Ratan Gupta533d03b2017-07-30 10:39:22 +0530183/** @brief Creates the VLAN on the given interface.
184 * @param[in] bus - DBUS Bus Object.
185 * @param[in] service - Dbus service name.
186 * @param[in] objPath - Dbus object path.
187 * @param[in] interface - EthernetInterface.
188 * @param[in] vlanID - Vlan ID.
189 */
190void createVLAN(sdbusplus::bus::bus& bus,
191 const std::string& service,
192 const std::string& objPath,
193 const std::string& interface,
194 uint32_t vlanID);
Ratan Guptab8e99552017-07-27 07:07:48 +0530195
Ratan Gupta533d03b2017-07-30 10:39:22 +0530196/** @brief Gets the vlan id from the given object path.
197 * @param[in] path - Dbus object path.
198 */
199uint32_t getVLAN(const std::string& path);
200
201} //namespace network
Tom Josephbe703f72017-03-09 12:34:35 +0530202} // namespace ipmi
203
204