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 | |
| 48 | /** @brief Gets the value associated with the given object |
| 49 | * and the interface. |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 50 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 51 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 57 | Value getDbusProperty(sdbusplus::bus::bus& bus, |
| 58 | const std::string& service, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 59 | 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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 65 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 66 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 71 | PropertyMap getAllDbusProperties(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 | |
| 76 | /** @brief Sets the property value of the given object. |
Ratan Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 77 | * @param[in] bus - DBUS Bus Object. |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 78 | * @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 Gupta | 01d4bd1 | 2017-08-07 15:53:25 +0530 | [diff] [blame] | 84 | void setDbusProperty(sdbusplus::bus::bus& bus, |
| 85 | const std::string& service, |
Ratan Gupta | cc8feb4 | 2017-07-25 21:52:10 +0530 | [diff] [blame] | 86 | const std::string& objPath, |
| 87 | const std::string& interface, |
| 88 | const std::string& property, |
| 89 | const Value& value); |
| 90 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 91 | /** @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 | */ |
| 99 | ObjectTree 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 | */ |
| 111 | void deleteAllDbusObjects(sdbusplus::bus::bus& bus, |
| 112 | const std::string& serviceRoot, |
| 113 | const std::string& interface, |
| 114 | const std::string& match = {}); |
| 115 | |
Ratan Gupta | cc6cdbf | 2017-09-01 23:06:25 +0530 | [diff] [blame] | 116 | /** @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 | */ |
| 123 | ObjectTree getAllAncestors(sdbusplus::bus::bus& bus, |
| 124 | const std::string& path, |
| 125 | InterfaceList&& interfaces); |
| 126 | |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 127 | namespace 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 | */ |
| 137 | void 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 | |
| 145 | namespace network |
| 146 | { |
| 147 | |
| 148 | constexpr auto ROOT = "/xyz/openbmc_project/network"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 149 | constexpr auto SERVICE = "xyz.openbmc_project.Network"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 150 | constexpr auto INTERFACE = "eth0"; |
| 151 | constexpr auto IP_TYPE = "ipv4"; |
| 152 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 153 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 154 | constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration"; |
| 155 | constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface"; |
| 156 | constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 157 | constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create"; |
| 158 | constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 159 | |
| 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 | */ |
| 165 | uint8_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 | */ |
| 176 | void 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 183 | /** @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 | */ |
| 190 | void 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 195 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 196 | /** @brief Gets the vlan id from the given object path. |
| 197 | * @param[in] path - Dbus object path. |
| 198 | */ |
| 199 | uint32_t getVLAN(const std::string& path); |
| 200 | |
| 201 | } //namespace network |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 202 | } // namespace ipmi |
| 203 | |
| 204 | |