Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 3 | #include "types.hpp" |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 4 | #include <sdbusplus/server.hpp> |
| 5 | |
| 6 | namespace ipmi |
| 7 | { |
| 8 | |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 9 | constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper"; |
| 10 | constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper"; |
| 11 | constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper"; |
| 12 | |
| 13 | constexpr auto ROOT = "/"; |
| 14 | constexpr auto HOST_MATCH = "host0"; |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 15 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 16 | constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties"; |
| 17 | constexpr auto DELETE_INTERFACE = "xyz.openbmc_project.Object.Delete"; |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 18 | |
| 19 | constexpr auto METHOD_GET = "Get"; |
| 20 | constexpr auto METHOD_GET_ALL = "GetAll"; |
| 21 | constexpr auto METHOD_SET = "Set"; |
| 22 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 23 | /** |
| 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 | */ |
| 31 | std::string getService(sdbusplus::bus::bus& bus, |
| 32 | const std::string& intf, |
| 33 | const std::string& path); |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 34 | |
| 35 | /** @brief Gets the dbus object info implementing the given interface |
| 36 | * from the given subtree. |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 37 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 38 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 43 | DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus, |
| 44 | const std::string& interface, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 45 | const std::string& subtreePath = ROOT, |
| 46 | const std::string& match = {}); |
| 47 | |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 48 | /** @brief Get the ipObject of first dbus IP object of Non-LinkLocalIPAddress |
Gunnar Mills | 8991dd6 | 2017-10-25 17:11:29 -0500 | [diff] [blame] | 49 | * type from the given subtree, if not available gets IP object of |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 50 | * 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 Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 55 | * @return On success returns the object having objectpath and servicename. |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 56 | */ |
Ratan Gupta | dd64620 | 2017-11-21 17:46:59 +0530 | [diff] [blame] | 57 | DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus, |
| 58 | const std::string& interface, |
| 59 | const std::string& subtreePath, |
| 60 | const std::string& match); |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 61 | |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 62 | /** @brief Gets the value associated with the given object |
| 63 | * and the interface. |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 64 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 65 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 71 | Value getDbusProperty(sdbusplus::bus::bus& bus, |
| 72 | const std::string& service, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 73 | 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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 79 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 80 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 85 | PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus, |
| 86 | const std::string& service, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 87 | const std::string& objPath, |
| 88 | const std::string& interface); |
| 89 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 90 | /** @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 | */ |
| 97 | ObjectValueTree getManagedObjects(sdbusplus::bus::bus& bus, |
| 98 | const std::string& service, |
| 99 | const std::string& objPath); |
| 100 | |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 101 | /** @brief Sets the property value of the given object. |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 102 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 103 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 109 | void setDbusProperty(sdbusplus::bus::bus& bus, |
| 110 | const std::string& service, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 111 | const std::string& objPath, |
| 112 | const std::string& interface, |
| 113 | const std::string& property, |
| 114 | const Value& value); |
| 115 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 116 | /** @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 | */ |
| 124 | ObjectTree 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 | */ |
| 136 | void deleteAllDbusObjects(sdbusplus::bus::bus& bus, |
| 137 | const std::string& serviceRoot, |
| 138 | const std::string& interface, |
| 139 | const std::string& match = {}); |
| 140 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 141 | /** @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 | */ |
| 148 | ObjectTree getAllAncestors(sdbusplus::bus::bus& bus, |
| 149 | const std::string& path, |
| 150 | InterfaceList&& interfaces); |
| 151 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 152 | namespace 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 | */ |
| 162 | void 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 | |
| 170 | namespace network |
| 171 | { |
| 172 | |
| 173 | constexpr auto ROOT = "/xyz/openbmc_project/network"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 174 | constexpr auto SERVICE = "xyz.openbmc_project.Network"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 175 | constexpr auto IP_TYPE = "ipv4"; |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 176 | constexpr auto IPV4_PREFIX = "169.254"; |
| 177 | constexpr auto IPV6_PREFIX = "fe80"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 178 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 179 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 180 | constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration"; |
| 181 | constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface"; |
| 182 | constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 183 | constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create"; |
| 184 | constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 185 | |
| 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 | */ |
| 191 | uint8_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 | */ |
| 202 | void 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 209 | /** @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 | */ |
| 216 | void 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 221 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 222 | /** @brief Gets the vlan id from the given object path. |
| 223 | * @param[in] path - Dbus object path. |
| 224 | */ |
| 225 | uint32_t getVLAN(const std::string& path); |
| 226 | |
| 227 | } //namespace network |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 228 | } // namespace ipmi |
| 229 | |
| 230 | |