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 | |
| 116 | namespace 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 | */ |
| 126 | void 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 | |
| 134 | namespace network |
| 135 | { |
| 136 | |
| 137 | constexpr auto ROOT = "/xyz/openbmc_project/network"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 138 | constexpr auto SERVICE = "xyz.openbmc_project.Network"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 139 | constexpr auto INTERFACE = "eth0"; |
| 140 | constexpr auto IP_TYPE = "ipv4"; |
| 141 | constexpr auto IP_INTERFACE = "xyz.openbmc_project.Network.IP"; |
| 142 | constexpr auto MAC_INTERFACE = "xyz.openbmc_project.Network.MACAddress"; |
| 143 | constexpr auto SYSTEMCONFIG_INTERFACE = "xyz.openbmc_project.Network.SystemConfiguration"; |
| 144 | constexpr auto ETHERNET_INTERFACE = "xyz.openbmc_project.Network.EthernetInterface"; |
| 145 | constexpr auto IP_CREATE_INTERFACE = "xyz.openbmc_project.Network.IP.Create"; |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 146 | constexpr auto VLAN_CREATE_INTERFACE = "xyz.openbmc_project.Network.VLAN.Create"; |
| 147 | constexpr auto VLAN_INTERFACE = "xyz.openbmc_project.Network.VLAN"; |
Ratan Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 148 | |
| 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 | */ |
| 154 | uint8_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 | */ |
| 165 | void 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 Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 172 | /** @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 | */ |
| 179 | void 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 Gupta | b8e9955 | 2017-07-27 07:07:48 +0530 | [diff] [blame] | 184 | |
Ratan Gupta | 533d03b | 2017-07-30 10:39:22 +0530 | [diff] [blame] | 185 | /** @brief Gets the vlan id from the given object path. |
| 186 | * @param[in] path - Dbus object path. |
| 187 | */ |
| 188 | uint32_t getVLAN(const std::string& path); |
| 189 | |
| 190 | } //namespace network |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 191 | } // namespace ipmi |
| 192 | |
| 193 | |