blob: 1d84c3cbe3856662e70747f81f4103852fdec457 [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>
Vernon Mauery052b7cf2019-05-08 15:59:41 -070023#include <user_channel/channel_layer.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -070024
Vernon Maueryfc37e592018-12-19 14:55:15 -080025using namespace phosphor::logging;
26
Tom Josephc35524e2016-08-29 08:17:59 -050027// Tuple of Global Singletons
Vernon Mauerycbccb052018-10-24 13:52:22 -070028static auto io = std::make_shared<boost::asio::io_context>();
Tom Josephc35524e2016-08-29 08:17:59 -050029session::Manager manager;
30command::Table table;
Vernon Mauerycbccb052018-10-24 13:52:22 -070031eventloop::EventLoop loop(io);
Vernon Mauery7e4a6512018-11-09 08:43:36 -080032sol::Manager solManager(io);
Tom Joseph52f53d72017-03-14 15:20:19 +053033
34std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&,
Vernon Mauery9e801a22018-10-12 13:20:49 -070035 sol::Manager&>
36 singletonPool(manager, table, loop, solManager);
Tom Josephc35524e2016-08-29 08:17:59 -050037
38sd_bus* bus = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050039
Vernon Mauery7b98c072018-11-01 15:52:26 -070040std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070041
Tom Josephc35524e2016-08-29 08:17:59 -050042/*
43 * @brief Required by apphandler IPMI Provider Library
44 */
45sd_bus* ipmid_get_sd_bus_connection()
46{
47 return bus;
48}
49
50/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070051 * @brief mechanism to get at sdbusplus object
52 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070053std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070054{
55 return sdbusp;
56}
57
Vernon Mauery052b7cf2019-05-08 15:59:41 -070058static EInterfaceIndex currentInterfaceIndex = interfaceUnknown;
59static 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}
ssekard6f3f7d2018-08-16 17:30:28 +053073EInterfaceIndex getInterfaceIndex(void)
74{
Vernon Mauery052b7cf2019-05-08 15:59:41 -070075 return currentInterfaceIndex;
ssekard6f3f7d2018-08-16 17:30:28 +053076}
77
Vernon Maueryd92bc322019-03-15 15:24:30 -070078int main(int argc, char* argv[])
Tom Josephc35524e2016-08-29 08:17:59 -050079{
Vernon Maueryd92bc322019-03-15 15:24:30 -070080 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 Josephc35524e2016-08-29 08:17:59 -050089 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080090 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050091 if (rc < 0)
92 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080093 log<level::ERR>("Failed to connect to system bus",
94 entry("ERROR=%s", strerror(-rc)));
Vernon Mauerycbccb052018-10-24 13:52:22 -070095 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050096 }
Vernon Mauerycbccb052018-10-24 13:52:22 -070097 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053098
Vernon Mauery052b7cf2019-05-08 15:59:41 -070099 ipmi::ipmiChannelInit();
100 if (channel.size())
101 {
102 setInterfaceIndex(channel);
103 }
104
Suryakanth Sekarf8a34fc2019-06-12 20:59:18 +0530105 std::get<session::Manager&>(singletonPool).managerInit(channel);
Tom Joseph83029cb2017-09-01 16:37:31 +0530106 // Register callback to update cache for a GUID change and cache the GUID
107 command::registerGUIDChangeCallback();
108 cache::guid = command::getSystemGUID();
109
Tom Josephc35524e2016-08-29 08:17:59 -0500110 // Register the phosphor-net-ipmid session setup commands
111 command::sessionSetupCommands();
112
Tom Joseph89481cf2017-04-03 02:11:34 +0530113 // Register the phosphor-net-ipmid SOL commands
114 sol::command::registerCommands();
115
Vernon Maueryd92bc322019-03-15 15:24:30 -0700116 auto& loop = std::get<eventloop::EventLoop&>(singletonPool);
117 if (loop.setupSocket(sdbusp, channel))
118 {
119 return EXIT_FAILURE;
120 }
121
Tom Josephc35524e2016-08-29 08:17:59 -0500122 // Start Event Loop
Vernon Maueryd92bc322019-03-15 15:24:30 -0700123 return loop.startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -0500124}