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