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 | |
| 90 | /** @brief Sets the property value of the given object. |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 91 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 92 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 98 | void setDbusProperty(sdbusplus::bus::bus& bus, |
| 99 | const std::string& service, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 100 | const std::string& objPath, |
| 101 | const std::string& interface, |
| 102 | const std::string& property, |
| 103 | const Value& value); |
| 104 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 105 | /** @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 | */ |
| 113 | ObjectTree 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 | */ |
| 125 | void deleteAllDbusObjects(sdbusplus::bus::bus& bus, |
| 126 | const std::string& serviceRoot, |
| 127 | const std::string& interface, |
| 128 | const std::string& match = {}); |
| 129 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 130 | /** @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 | */ |
| 137 | ObjectTree getAllAncestors(sdbusplus::bus::bus& bus, |
| 138 | const std::string& path, |
| 139 | InterfaceList&& interfaces); |
| 140 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 141 | namespace 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 | */ |
| 151 | void 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 | |
| 159 | namespace network |
| 160 | { |
| 161 | |
| 162 | constexpr auto ROOT = "/xyz/openbmc_project/network"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 163 | constexpr auto SERVICE = "xyz.openbmc_project.Network"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 164 | constexpr auto INTERFACE = "eth0"; |
| 165 | constexpr auto IP_TYPE = "ipv4"; |
Nagaraju Goruganti | 1fe5c83 | 2017-09-21 07:44:17 -0500 | [diff] [blame] | 166 | constexpr auto IPV4_PREFIX = "169.254"; |
| 167 | constexpr auto IPV6_PREFIX = "fe80"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 168 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 169 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 170 | constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration"; |
| 171 | constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface"; |
| 172 | constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 173 | constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create"; |
| 174 | constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 175 | |
| 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 | */ |
| 181 | uint8_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 | */ |
| 192 | void 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 199 | /** @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 | */ |
| 206 | void 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 211 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 212 | /** @brief Gets the vlan id from the given object path. |
| 213 | * @param[in] path - Dbus object path. |
| 214 | */ |
| 215 | uint32_t getVLAN(const std::string& path); |
| 216 | |
| 217 | } //namespace network |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 218 | } // namespace ipmi |
| 219 | |
| 220 | |