blob: a172e222e6f0cf8af78c4770dc93a006eb75a8a2 [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
116namespace method_no_args
117{
118
119/** @brief Calls the Dbus method which waits for response.
120 * @param[in] bus - DBUS Bus Object.
121 * @param[in] service - Dbus service name.
122 * @param[in] objPath - Dbus object path.
123 * @param[in] interface - Dbus interface.
124 * @param[in] method - Dbus method.
125 */
126void callDbusMethod(sdbusplus::bus::bus& bus,
127 const std::string& service,
128 const std::string& objPath,
129 const std::string& interface,
130 const std::string& method);
131
132} //namespace method_no_args
133
134namespace network
135{
136
137constexpr auto ROOT = "/xyz/openbmc_project/network";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530138constexpr auto SERVICE = "xyz.openbmc_project.Network";
Ratan Guptab8e99552017-07-27 07:07:48 +0530139constexpr auto INTERFACE = "eth0";
140constexpr auto IP_TYPE = "ipv4";
141constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP";
142constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress";
143constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration";
144constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface";
145constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create";
Ratan Gupta533d03b2017-07-30 10:39:22 +0530146constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create";
147constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN";
Ratan Guptab8e99552017-07-27 07:07:48 +0530148
149/* @brief converts the given subnet into prefix notation.
150 * @param[in] addressFamily - IP address family(AF_INET/AF_INET6).
151 * @param[in] mask - Subnet Mask.
152 * @returns prefix.
153 */
154uint8_t toPrefix(int addressFamily, const std::string& subnetMask);
155
156
157/** @brief Sets the ip on the system.
158 * @param[in] bus - DBUS Bus Object.
159 * @param[in] service - Dbus service name.
160 * @param[in] objPath - Dbus object path.
161 * @param[in] protocolType - Protocol type
162 * @param[in] ipaddress - IPaddress.
163 * @param[in] prefix - Prefix length.
164 */
165void createIP(sdbusplus::bus::bus& bus,
166 const std::string& service,
167 const std::string& objPath,
168 const std::string& protocolType,
169 const std::string& ipaddress,
170 uint8_t prefix);
171
Ratan Gupta533d03b2017-07-30 10:39:22 +0530172/** @brief Creates the VLAN on the given interface.
173 * @param[in] bus - DBUS Bus Object.
174 * @param[in] service - Dbus service name.
175 * @param[in] objPath - Dbus object path.
176 * @param[in] interface - EthernetInterface.
177 * @param[in] vlanID - Vlan ID.
178 */
179void createVLAN(sdbusplus::bus::bus& bus,
180 const std::string& service,
181 const std::string& objPath,
182 const std::string& interface,
183 uint32_t vlanID);
Ratan Guptab8e99552017-07-27 07:07:48 +0530184
Ratan Gupta533d03b2017-07-30 10:39:22 +0530185/** @brief Gets the vlan id from the given object path.
186 * @param[in] path - Dbus object path.
187 */
188uint32_t getVLAN(const std::string& path);
189
190} //namespace network
Tom Josephbe703f72017-03-09 12:34:35 +0530191} // namespace ipmi
192
193