blob: eab9a2f24c639b1c583741f568f1cd65e42f6707 [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"
Vernon Mauery2085ae02021-06-10 11:51:00 -07008#include "sd_event_loop.hpp"
9#include "sessions_manager.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050010#include "socket_channel.hpp"
Tom Joseph89481cf2017-04-03 02:11:34 +053011#include "sol_module.hpp"
Tom Josephc35524e2016-08-29 08:17:59 -050012
Vernon Mauery9e801a22018-10-12 13:20:49 -070013#include <assert.h>
14#include <dirent.h>
15#include <dlfcn.h>
William A. Kennington III4f09eae2019-02-12 17:10:35 -080016#include <ipmid/api.h>
Vernon Mauery9e801a22018-10-12 13:20:49 -070017#include <systemd/sd-daemon.h>
18#include <systemd/sd-event.h>
19#include <unistd.h>
20
Vernon Maueryd92bc322019-03-15 15:24:30 -070021#include <CLI/CLI.hpp>
Vernon Maueryfc37e592018-12-19 14:55:15 -080022#include <phosphor-logging/log.hpp>
Vernon Mauerycbccb052018-10-24 13:52:22 -070023#include <sdbusplus/asio/connection.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -070024#include <tuple>
Vernon Mauery052b7cf2019-05-08 15:59:41 -070025#include <user_channel/channel_layer.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -070026
Vernon Maueryfc37e592018-12-19 14:55:15 -080027using namespace phosphor::logging;
28
Vernon Mauerycbccb052018-10-24 13:52:22 -070029static auto io = std::make_shared<boost::asio::io_context>();
Vernon Mauery2085ae02021-06-10 11:51:00 -070030std::shared_ptr<boost::asio::io_context> getIo()
31{
32 return io;
33}
Tom Josephc35524e2016-08-29 08:17:59 -050034
35sd_bus* bus = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050036
Vernon Mauery7b98c072018-11-01 15:52:26 -070037std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070038
Tom Josephc35524e2016-08-29 08:17:59 -050039/*
40 * @brief Required by apphandler IPMI Provider Library
41 */
42sd_bus* ipmid_get_sd_bus_connection()
43{
44 return bus;
45}
46
47/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070048 * @brief mechanism to get at sdbusplus object
49 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070050std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070051{
52 return sdbusp;
53}
54
Vernon Mauery052b7cf2019-05-08 15:59:41 -070055static EInterfaceIndex currentInterfaceIndex = interfaceUnknown;
56static 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}
ssekard6f3f7d2018-08-16 17:30:28 +053070EInterfaceIndex getInterfaceIndex(void)
71{
Vernon Mauery052b7cf2019-05-08 15:59:41 -070072 return currentInterfaceIndex;
ssekard6f3f7d2018-08-16 17:30:28 +053073}
74
Vernon Maueryd92bc322019-03-15 15:24:30 -070075int main(int argc, char* argv[])
Tom Josephc35524e2016-08-29 08:17:59 -050076{
Vernon Maueryd92bc322019-03-15 15:24:30 -070077 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 Josephc35524e2016-08-29 08:17:59 -050086 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080087 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050088 if (rc < 0)
89 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080090 log<level::ERR>("Failed to connect to system bus",
91 entry("ERROR=%s", strerror(-rc)));
Vernon Mauerycbccb052018-10-24 13:52:22 -070092 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050093 }
Vernon Mauerycbccb052018-10-24 13:52:22 -070094 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053095
Vernon Mauery052b7cf2019-05-08 15:59:41 -070096 ipmi::ipmiChannelInit();
97 if (channel.size())
98 {
99 setInterfaceIndex(channel);
100 }
101
Vernon Mauery2085ae02021-06-10 11:51:00 -0700102 session::Manager::get().managerInit(channel);
Tom Joseph83029cb2017-09-01 16:37:31 +0530103 // Register callback to update cache for a GUID change and cache the GUID
104 command::registerGUIDChangeCallback();
105 cache::guid = command::getSystemGUID();
106
Tom Josephc35524e2016-08-29 08:17:59 -0500107 // Register the phosphor-net-ipmid session setup commands
108 command::sessionSetupCommands();
109
Tom Joseph89481cf2017-04-03 02:11:34 +0530110 // Register the phosphor-net-ipmid SOL commands
111 sol::command::registerCommands();
112
Vernon Mauery2085ae02021-06-10 11:51:00 -0700113 auto& loop = eventloop::EventLoop::get();
Vernon Maueryd92bc322019-03-15 15:24:30 -0700114 if (loop.setupSocket(sdbusp, channel))
115 {
116 return EXIT_FAILURE;
117 }
118
Tom Josephc35524e2016-08-29 08:17:59 -0500119 // Start Event Loop
Vernon Maueryd92bc322019-03-15 15:24:30 -0700120 return loop.startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -0500121}