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