Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 1 | #include "main.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 2 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 3 | #include "comm_module.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 4 | #include "command/guid.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 5 | #include "command_table.hpp" |
| 6 | #include "message.hpp" |
| 7 | #include "message_handler.hpp" |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 8 | #include "sd_event_loop.hpp" |
| 9 | #include "sessions_manager.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 10 | #include "socket_channel.hpp" |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 11 | #include "sol_module.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 12 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 13 | #include <assert.h> |
| 14 | #include <dirent.h> |
| 15 | #include <dlfcn.h> |
William A. Kennington III | 4f09eae | 2019-02-12 17:10:35 -0800 | [diff] [blame] | 16 | #include <ipmid/api.h> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 17 | #include <systemd/sd-daemon.h> |
| 18 | #include <systemd/sd-event.h> |
| 19 | #include <unistd.h> |
| 20 | |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 21 | #include <CLI/CLI.hpp> |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 22 | #include <phosphor-logging/lg2.hpp> |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 23 | #include <sdbusplus/asio/connection.hpp> |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 24 | #include <user_channel/channel_layer.hpp> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 25 | |
George Liu | bc8958f | 2022-07-04 09:29:49 +0800 | [diff] [blame] | 26 | #include <tuple> |
| 27 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 28 | static auto io = std::make_shared<boost::asio::io_context>(); |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 29 | std::shared_ptr<boost::asio::io_context> getIo() |
| 30 | { |
| 31 | return io; |
| 32 | } |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 33 | |
| 34 | sd_bus* bus = nullptr; |
Marri Devender Rao | 3ecf0a1 | 2017-07-13 08:07:22 -0500 | [diff] [blame] | 35 | |
Vernon Mauery | 7b98c07 | 2018-11-01 15:52:26 -0700 | [diff] [blame] | 36 | std::shared_ptr<sdbusplus::asio::connection> sdbusp; |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 37 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 38 | /* |
| 39 | * @brief Required by apphandler IPMI Provider Library |
| 40 | */ |
| 41 | sd_bus* ipmid_get_sd_bus_connection() |
| 42 | { |
| 43 | return bus; |
| 44 | } |
| 45 | |
| 46 | /* |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 47 | * @brief mechanism to get at sdbusplus object |
| 48 | */ |
Vernon Mauery | 7b98c07 | 2018-11-01 15:52:26 -0700 | [diff] [blame] | 49 | std::shared_ptr<sdbusplus::asio::connection> getSdBus() |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 50 | { |
| 51 | return sdbusp; |
| 52 | } |
| 53 | |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 54 | static EInterfaceIndex currentInterfaceIndex = interfaceUnknown; |
| 55 | static void setInterfaceIndex(const std::string& channel) |
| 56 | { |
| 57 | try |
| 58 | { |
| 59 | currentInterfaceIndex = |
| 60 | static_cast<EInterfaceIndex>(ipmi::getChannelByName(channel)); |
| 61 | } |
| 62 | catch (const std::exception& e) |
| 63 | { |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 64 | lg2::error("Requested {NAME} is not a valid channel name: {ERROR}", |
| 65 | "NAME", channel, "ERROR", e); |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 68 | EInterfaceIndex getInterfaceIndex(void) |
| 69 | { |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 70 | return currentInterfaceIndex; |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 71 | } |
| 72 | |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 73 | int main(int argc, char* argv[]) |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 74 | { |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 75 | CLI::App app("KCS RMCP+ bridge"); |
| 76 | std::string channel; |
| 77 | app.add_option("-c,--channel", channel, "channel name. e.g., eth0"); |
| 78 | uint16_t port = ipmi::rmcpp::defaultPort; |
| 79 | app.add_option("-p,--port", port, "port number"); |
| 80 | bool verbose = false; |
| 81 | app.add_option("-v,--verbose", verbose, "print more verbose output"); |
| 82 | CLI11_PARSE(app, argc, argv); |
| 83 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 84 | // Connect to system bus |
Vernon Mauery | 96a1a39 | 2018-11-08 16:54:23 -0800 | [diff] [blame] | 85 | auto rc = sd_bus_default_system(&bus); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 86 | if (rc < 0) |
| 87 | { |
George Liu | 7b7f25f | 2022-07-04 17:07:32 +0800 | [diff] [blame] | 88 | lg2::error("Failed to connect to system bus: {ERROR}", "ERROR", |
| 89 | strerror(-rc)); |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 90 | return rc; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 91 | } |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 92 | sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus); |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 93 | |
George Liu | afac94d | 2024-10-24 11:03:07 +0800 | [diff] [blame^] | 94 | auto& loop = eventloop::EventLoop::get(); |
| 95 | loop.setupSignal(); |
| 96 | |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 97 | ipmi::ipmiChannelInit(); |
| 98 | if (channel.size()) |
| 99 | { |
| 100 | setInterfaceIndex(channel); |
| 101 | } |
| 102 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 103 | session::Manager::get().managerInit(channel); |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 104 | // Register callback to update cache for a GUID change and cache the GUID |
| 105 | command::registerGUIDChangeCallback(); |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 106 | |
Jian Zhang | c936eca | 2022-03-22 11:25:29 +0800 | [diff] [blame] | 107 | // Register callback to update cache for sol conf change |
| 108 | sol::registerSolConfChangeCallbackHandler(channel); |
| 109 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 110 | // Register the phosphor-net-ipmid session setup commands |
| 111 | command::sessionSetupCommands(); |
| 112 | |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 113 | // Register the phosphor-net-ipmid SOL commands |
| 114 | sol::command::registerCommands(); |
| 115 | |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 116 | if (loop.setupSocket(sdbusp, channel)) |
| 117 | { |
| 118 | return EXIT_FAILURE; |
| 119 | } |
| 120 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 121 | // Start Event Loop |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 122 | return loop.startEventLoop(); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 123 | } |