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