blob: fc9a28c971e7961c660aa479ba4f85896a77bc8d [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 Mauery052b7cf2019-05-08 15:59:41 -070024#include <user_channel/channel_layer.hpp>
Vernon Mauery9e801a22018-10-12 13:20:49 -070025
George Liubc8958f2022-07-04 09:29:49 +080026#include <tuple>
27
Vernon Maueryfc37e592018-12-19 14:55:15 -080028using namespace phosphor::logging;
29
Vernon Mauerycbccb052018-10-24 13:52:22 -070030static auto io = std::make_shared<boost::asio::io_context>();
Vernon Mauery2085ae02021-06-10 11:51:00 -070031std::shared_ptr<boost::asio::io_context> getIo()
32{
33 return io;
34}
Tom Josephc35524e2016-08-29 08:17:59 -050035
36sd_bus* bus = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050037
Vernon Mauery7b98c072018-11-01 15:52:26 -070038std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070039
Tom Josephc35524e2016-08-29 08:17:59 -050040/*
41 * @brief Required by apphandler IPMI Provider Library
42 */
43sd_bus* ipmid_get_sd_bus_connection()
44{
45 return bus;
46}
47
48/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070049 * @brief mechanism to get at sdbusplus object
50 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070051std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070052{
53 return sdbusp;
54}
55
Vernon Mauery052b7cf2019-05-08 15:59:41 -070056static EInterfaceIndex currentInterfaceIndex = interfaceUnknown;
57static void setInterfaceIndex(const std::string& channel)
58{
59 try
60 {
61 currentInterfaceIndex =
62 static_cast<EInterfaceIndex>(ipmi::getChannelByName(channel));
63 }
64 catch (const std::exception& e)
65 {
66 log<level::ERR>("Requested channel name is not a valid channel name",
67 entry("ERROR=%s", e.what()),
68 entry("CHANNEL=%s", channel.c_str()));
69 }
70}
ssekard6f3f7d2018-08-16 17:30:28 +053071EInterfaceIndex getInterfaceIndex(void)
72{
Vernon Mauery052b7cf2019-05-08 15:59:41 -070073 return currentInterfaceIndex;
ssekard6f3f7d2018-08-16 17:30:28 +053074}
75
Vernon Maueryd92bc322019-03-15 15:24:30 -070076int main(int argc, char* argv[])
Tom Josephc35524e2016-08-29 08:17:59 -050077{
Vernon Maueryd92bc322019-03-15 15:24:30 -070078 CLI::App app("KCS RMCP+ bridge");
79 std::string channel;
80 app.add_option("-c,--channel", channel, "channel name. e.g., eth0");
81 uint16_t port = ipmi::rmcpp::defaultPort;
82 app.add_option("-p,--port", port, "port number");
83 bool verbose = false;
84 app.add_option("-v,--verbose", verbose, "print more verbose output");
85 CLI11_PARSE(app, argc, argv);
86
Tom Josephc35524e2016-08-29 08:17:59 -050087 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080088 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050089 if (rc < 0)
90 {
Vernon Maueryfc37e592018-12-19 14:55:15 -080091 log<level::ERR>("Failed to connect to system bus",
92 entry("ERROR=%s", strerror(-rc)));
Vernon Mauerycbccb052018-10-24 13:52:22 -070093 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050094 }
Vernon Mauerycbccb052018-10-24 13:52:22 -070095 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053096
Vernon Mauery052b7cf2019-05-08 15:59:41 -070097 ipmi::ipmiChannelInit();
98 if (channel.size())
99 {
100 setInterfaceIndex(channel);
101 }
102
Vernon Mauery2085ae02021-06-10 11:51:00 -0700103 session::Manager::get().managerInit(channel);
Tom Joseph83029cb2017-09-01 16:37:31 +0530104 // Register callback to update cache for a GUID change and cache the GUID
105 command::registerGUIDChangeCallback();
106 cache::guid = command::getSystemGUID();
107
Jian Zhangc936eca2022-03-22 11:25:29 +0800108 // Register callback to update cache for sol conf change
109 sol::registerSolConfChangeCallbackHandler(channel);
110
Tom Josephc35524e2016-08-29 08:17:59 -0500111 // Register the phosphor-net-ipmid session setup commands
112 command::sessionSetupCommands();
113
Tom Joseph89481cf2017-04-03 02:11:34 +0530114 // Register the phosphor-net-ipmid SOL commands
115 sol::command::registerCommands();
116
Vernon Mauery2085ae02021-06-10 11:51:00 -0700117 auto& loop = eventloop::EventLoop::get();
Vernon Maueryd92bc322019-03-15 15:24:30 -0700118 if (loop.setupSocket(sdbusp, channel))
119 {
120 return EXIT_FAILURE;
121 }
122
Tom Josephc35524e2016-08-29 08:17:59 -0500123 // Start Event Loop
Vernon Maueryd92bc322019-03-15 15:24:30 -0700124 return loop.startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -0500125}