blob: d26e0324f8967d3ee4688f7cdc0feca3f43201c6 [file] [log] [blame]
Tom Josephc35524e2016-08-29 08:17:59 -05001#include "main.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -05002
Tom Josephc35524e2016-08-29 08:17:59 -05003#include "comm_module.hpp"
Vernon Mauery9e801a22018-10-12 13:20:49 -07004#include "command/guid.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -05005#include "command_table.hpp"
6#include "message.hpp"
7#include "message_handler.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -05008#include "socket_channel.hpp"
Tom Joseph89481cf2017-04-03 02:11:34 +05309#include "sol_module.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050010
Vernon Mauery9e801a22018-10-12 13:20:49 -070011#include <assert.h>
12#include <dirent.h>
13#include <dlfcn.h>
William A. Kennington III4f09eae2019-02-12 17:10:35 -080014#include <ipmid/api.h>
Vernon Mauery9e801a22018-10-12 13:20:49 -070015#include <systemd/sd-daemon.h>
16#include <systemd/sd-event.h>
17#include <unistd.h>
18
Vernon Maueryd92bc322019-03-15 15:24:30 -070019#include <CLI/CLI.hpp>
Vernon Maueryfc37e592018-12-19 14:55:15 -080020#include <phosphor-logging/log.hpp>
Vernon Mauerycbccb052018-10-24 13:52:22 -070021#include <sdbusplus/asio/connection.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -070022#include <tuple>
23
Vernon Maueryfc37e592018-12-19 14:55:15 -080024using namespace phosphor::logging;
25
Tom Josephc35524e2016-08-29 08:17:59 -050026// Tuple of Global Singletons
Vernon Mauerycbccb052018-10-24 13:52:22 -070027static auto io = std::make_shared<boost::asio::io_context>();
Tom Josephc35524e2016-08-29 08:17:59 -050028session::Manager manager;
29command::Table table;
Vernon Mauerycbccb052018-10-24 13:52:22 -070030eventloop::EventLoop loop(io);
Vernon Mauery7e4a6512018-11-09 08:43:36 -080031sol::Manager solManager(io);
Tom Joseph52f53d72017-03-14 15:20:19 +053032
33std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
Vernon Mauery9e801a22018-10-12 13:20:49 -070034 sol::Manager&>
35 singletonPool(manager, table, loop, solManager);
Tom Josephc35524e2016-08-29 08:17:59 -050036
37sd_bus* bus = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050038
Vernon Mauery7b98c072018-11-01 15:52:26 -070039std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070040
Tom Josephc35524e2016-08-29 08:17:59 -050041/*
42 * @brief Required by apphandler IPMI Provider Library
43 */
44sd_bus* ipmid_get_sd_bus_connection()
45{
46 return bus;
47}
48
49/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070050 * @brief mechanism to get at sdbusplus object
51 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070052std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070053{
54 return sdbusp;
55}
56
ssekard6f3f7d2018-08-16 17:30:28 +053057EInterfaceIndex getInterfaceIndex(void)
58{
59 return interfaceLAN1;
60}
61
Vernon Maueryd92bc322019-03-15 15:24:30 -070062int main(int argc, char* argv[])
Tom Josephc35524e2016-08-29 08:17:59 -050063{
Vernon Maueryd92bc322019-03-15 15:24:30 -070064 CLI::App app("KCS RMCP+ bridge");
65 std::string channel;
66 app.add_option("-c,--channel", channel, "channel name. e.g., eth0");
67 uint16_t port = ipmi::rmcpp::defaultPort;
68 app.add_option("-p,--port", port, "port number");
69 bool verbose = false;
70 app.add_option("-v,--verbose", verbose, "print more verbose output");
71 CLI11_PARSE(app, argc, argv);
72
Tom Josephc35524e2016-08-29 08:17:59 -050073 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080074 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050075 if (rc < 0)
76 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080077 log<level::ERR>("Failed to connect to system bus",
78 entry("ERROR=%s", strerror(-rc)));
Vernon Mauerycbccb052018-10-24 13:52:22 -070079 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050080 }
81
Vernon Mauerycbccb052018-10-24 13:52:22 -070082 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053083
Tom Joseph83029cb2017-09-01 16:37:31 +053084 // Register callback to update cache for a GUID change and cache the GUID
85 command::registerGUIDChangeCallback();
86 cache::guid = command::getSystemGUID();
87
Tom Josephc35524e2016-08-29 08:17:59 -050088 // Register the phosphor-net-ipmid session setup commands
89 command::sessionSetupCommands();
90
Tom Joseph89481cf2017-04-03 02:11:34 +053091 // Register the phosphor-net-ipmid SOL commands
92 sol::command::registerCommands();
93
Vernon Maueryd92bc322019-03-15 15:24:30 -070094 auto& loop = std::get<eventloop::EventLoop&>(singletonPool);
95 if (loop.setupSocket(sdbusp, channel))
96 {
97 return EXIT_FAILURE;
98 }
99
Tom Josephc35524e2016-08-29 08:17:59 -0500100 // Start Event Loop
Vernon Maueryd92bc322019-03-15 15:24:30 -0700101 return loop.startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -0500102}