Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 3 | #include "sol/sol_manager.hpp" |
| 4 | |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 5 | #include <systemd/sd-event.h> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 6 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 7 | #include <boost/asio/io_context.hpp> |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 8 | #include <chrono> |
| 9 | #include <map> |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 10 | #include <sdbusplus/asio/connection.hpp> |
| 11 | |
| 12 | namespace ipmi |
| 13 | { |
| 14 | namespace rmcpp |
| 15 | { |
| 16 | constexpr uint16_t defaultPort = 623; |
| 17 | } // namespace rmcpp |
| 18 | } // namespace ipmi |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 19 | |
| 20 | namespace eventloop |
| 21 | { |
Alvin Wang | 8c0bf98 | 2019-10-21 10:30:07 +0800 | [diff] [blame] | 22 | using DbusObjectPath = std::string; |
| 23 | using DbusService = std::string; |
| 24 | using DbusInterface = std::string; |
| 25 | using ObjectTree = |
| 26 | std::map<DbusObjectPath, std::map<DbusService, std::vector<DbusInterface>>>; |
| 27 | using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, |
| 28 | int64_t, uint64_t, double, std::string>; |
| 29 | // VLANs are a 12-bit value |
| 30 | constexpr uint16_t VLAN_VALUE_MASK = 0x0fff; |
| 31 | constexpr auto MAPPER_BUS_NAME = "xyz.openbmc_project.ObjectMapper"; |
| 32 | constexpr auto MAPPER_OBJ = "/xyz/openbmc_project/object_mapper"; |
| 33 | constexpr auto MAPPER_INTF = "xyz.openbmc_project.ObjectMapper"; |
| 34 | constexpr auto PATH_ROOT = "/xyz/openbmc_project/network"; |
| 35 | constexpr auto INTF_VLAN = "xyz.openbmc_project.Network.VLAN"; |
| 36 | constexpr auto INTF_ETHERNET = "xyz.openbmc_project.Network.EthernetInterface"; |
| 37 | constexpr auto METHOD_GET = "Get"; |
| 38 | constexpr auto PROP_INTF = "org.freedesktop.DBus.Properties"; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 39 | |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 40 | class EventLoop |
| 41 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 42 | public: |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 43 | explicit EventLoop(std::shared_ptr<boost::asio::io_context> io) : io(io) |
| 44 | { |
| 45 | } |
| 46 | EventLoop() = delete; |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 47 | ~EventLoop() = default; |
| 48 | EventLoop(const EventLoop&) = delete; |
| 49 | EventLoop& operator=(const EventLoop&) = delete; |
| 50 | EventLoop(EventLoop&&) = delete; |
| 51 | EventLoop& operator=(EventLoop&&) = delete; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 52 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 53 | /** @brief Initialise the event loop and add the handler for incoming |
| 54 | * IPMI packets. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 55 | * |
| 56 | * @return EXIT_SUCCESS on success and EXIT_FAILURE on failure. |
| 57 | */ |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 58 | int startEventLoop(); |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 59 | |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 60 | /** @brief Set up the socket (if systemd has not already) and |
| 61 | * make sure that the bus name matches the specified channel |
| 62 | */ |
| 63 | int setupSocket(std::shared_ptr<sdbusplus::asio::connection>& bus, |
| 64 | std::string iface, |
| 65 | uint16_t reqPort = ipmi::rmcpp::defaultPort); |
| 66 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 67 | private: |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 68 | /** @brief async handler for incoming udp packets */ |
| 69 | void handleRmcpPacket(); |
| 70 | |
| 71 | /** @brief register the async handler for incoming udp packets */ |
| 72 | void startRmcpReceive(); |
| 73 | |
Alvin Wang | 8c0bf98 | 2019-10-21 10:30:07 +0800 | [diff] [blame] | 74 | /** @brief get vlanid */ |
| 75 | int getVLANID(const std::string channel); |
| 76 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 77 | /** @brief boost::asio io context to run with |
| 78 | */ |
| 79 | std::shared_ptr<boost::asio::io_context> io; |
| 80 | |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 81 | /** @brief boost::asio udp socket |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 82 | */ |
Vernon Mauery | 7a0142c | 2018-11-09 08:38:16 -0800 | [diff] [blame] | 83 | std::shared_ptr<boost::asio::ip::udp::socket> udpSocket = nullptr; |
Tom Joseph | 807c7e8 | 2017-02-09 19:49:38 +0530 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace eventloop |