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> |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 22 | #include <phosphor-logging/log.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 | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 28 | using namespace phosphor::logging; |
| 29 | |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 30 | static auto io = std::make_shared<boost::asio::io_context>(); |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 31 | std::shared_ptr<boost::asio::io_context> getIo() |
| 32 | { |
| 33 | return io; |
| 34 | } |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 35 | |
| 36 | sd_bus* bus = nullptr; |
Marri Devender Rao | 3ecf0a1 | 2017-07-13 08:07:22 -0500 | [diff] [blame] | 37 | |
Vernon Mauery | 7b98c07 | 2018-11-01 15:52:26 -0700 | [diff] [blame] | 38 | std::shared_ptr<sdbusplus::asio::connection> sdbusp; |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 39 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 40 | /* |
| 41 | * @brief Required by apphandler IPMI Provider Library |
| 42 | */ |
| 43 | sd_bus* ipmid_get_sd_bus_connection() |
| 44 | { |
| 45 | return bus; |
| 46 | } |
| 47 | |
| 48 | /* |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 49 | * @brief mechanism to get at sdbusplus object |
| 50 | */ |
Vernon Mauery | 7b98c07 | 2018-11-01 15:52:26 -0700 | [diff] [blame] | 51 | std::shared_ptr<sdbusplus::asio::connection> getSdBus() |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame] | 52 | { |
| 53 | return sdbusp; |
| 54 | } |
| 55 | |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 56 | static EInterfaceIndex currentInterfaceIndex = interfaceUnknown; |
| 57 | static void setInterfaceIndex(const std::string& channel) |
| 58 | { |
| 59 | try |
| 60 | { |
| 61 | currentInterfaceIndex = |
| 62 | static_cast<EInterfaceIndex>(ipmi::getChannelByName(channel)); |
| 63 | } |
| 64 | catch (const std::exception& e) |
| 65 | { |
| 66 | log<level::ERR>("Requested channel name is not a valid channel name", |
| 67 | entry("ERROR=%s", e.what()), |
| 68 | entry("CHANNEL=%s", channel.c_str())); |
| 69 | } |
| 70 | } |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 71 | EInterfaceIndex getInterfaceIndex(void) |
| 72 | { |
Vernon Mauery | 052b7cf | 2019-05-08 15:59:41 -0700 | [diff] [blame] | 73 | return currentInterfaceIndex; |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 74 | } |
| 75 | |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 76 | int main(int argc, char* argv[]) |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 77 | { |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 78 | CLI::App app("KCS RMCP+ bridge"); |
| 79 | std::string channel; |
| 80 | app.add_option("-c,--channel", channel, "channel name. e.g., eth0"); |
| 81 | uint16_t port = ipmi::rmcpp::defaultPort; |
| 82 | app.add_option("-p,--port", port, "port number"); |
| 83 | bool verbose = false; |
| 84 | app.add_option("-v,--verbose", verbose, "print more verbose output"); |
| 85 | CLI11_PARSE(app, argc, argv); |
| 86 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 87 | // Connect to system bus |
Vernon Mauery | 96a1a39 | 2018-11-08 16:54:23 -0800 | [diff] [blame] | 88 | auto rc = sd_bus_default_system(&bus); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 89 | if (rc < 0) |
| 90 | { |
Vernon Mauery | fc37e59 | 2018-12-19 14:55:15 -0800 | [diff] [blame] | 91 | log<level::ERR>("Failed to connect to system bus", |
| 92 | entry("ERROR=%s", strerror(-rc))); |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 93 | return rc; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 94 | } |
Vernon Mauery | cbccb05 | 2018-10-24 13:52:22 -0700 | [diff] [blame] | 95 | sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus); |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 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(); |
| 106 | cache::guid = command::getSystemGUID(); |
| 107 | |
Jian Zhang | c936eca | 2022-03-22 11:25:29 +0800 | [diff] [blame] | 108 | // Register callback to update cache for sol conf change |
| 109 | sol::registerSolConfChangeCallbackHandler(channel); |
| 110 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 111 | // Register the phosphor-net-ipmid session setup commands |
| 112 | command::sessionSetupCommands(); |
| 113 | |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 114 | // Register the phosphor-net-ipmid SOL commands |
| 115 | sol::command::registerCommands(); |
| 116 | |
Vernon Mauery | 2085ae0 | 2021-06-10 11:51:00 -0700 | [diff] [blame] | 117 | auto& loop = eventloop::EventLoop::get(); |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 118 | if (loop.setupSocket(sdbusp, channel)) |
| 119 | { |
| 120 | return EXIT_FAILURE; |
| 121 | } |
| 122 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 123 | // Start Event Loop |
Vernon Mauery | d92bc32 | 2019-03-15 15:24:30 -0700 | [diff] [blame] | 124 | return loop.startEventLoop(); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 125 | } |