blob: b66c6f5db7de63a75dcb3f22929458409d6ec1d3 [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>
George Liu7b7f25f2022-07-04 17:07:32 +080022#include <phosphor-logging/lg2.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 Mauerycbccb052018-10-24 13:52:22 -070028static auto io = std::make_shared<boost::asio::io_context>();
Vernon Mauery2085ae02021-06-10 11:51:00 -070029std::shared_ptr<boost::asio::io_context> getIo()
30{
31 return io;
32}
Tom Josephc35524e2016-08-29 08:17:59 -050033
34sd_bus* bus = nullptr;
Marri Devender Rao3ecf0a12017-07-13 08:07:22 -050035
Vernon Mauery7b98c072018-11-01 15:52:26 -070036std::shared_ptr<sdbusplus::asio::connection> sdbusp;
Vernon Maueryd0062ed2018-10-25 09:36:06 -070037
Tom Josephc35524e2016-08-29 08:17:59 -050038/*
39 * @brief Required by apphandler IPMI Provider Library
40 */
41sd_bus* ipmid_get_sd_bus_connection()
42{
43 return bus;
44}
45
46/*
Vernon Maueryd0062ed2018-10-25 09:36:06 -070047 * @brief mechanism to get at sdbusplus object
48 */
Vernon Mauery7b98c072018-11-01 15:52:26 -070049std::shared_ptr<sdbusplus::asio::connection> getSdBus()
Vernon Maueryd0062ed2018-10-25 09:36:06 -070050{
51 return sdbusp;
52}
53
Vernon Mauery052b7cf2019-05-08 15:59:41 -070054static EInterfaceIndex currentInterfaceIndex = interfaceUnknown;
55static void setInterfaceIndex(const std::string& channel)
56{
57 try
58 {
59 currentInterfaceIndex =
60 static_cast<EInterfaceIndex>(ipmi::getChannelByName(channel));
61 }
62 catch (const std::exception& e)
63 {
George Liu7b7f25f2022-07-04 17:07:32 +080064 lg2::error("Requested {NAME} is not a valid channel name: {ERROR}",
65 "NAME", channel, "ERROR", e);
Vernon Mauery052b7cf2019-05-08 15:59:41 -070066 }
67}
ssekard6f3f7d2018-08-16 17:30:28 +053068EInterfaceIndex getInterfaceIndex(void)
69{
Vernon Mauery052b7cf2019-05-08 15:59:41 -070070 return currentInterfaceIndex;
ssekard6f3f7d2018-08-16 17:30:28 +053071}
72
Vernon Maueryd92bc322019-03-15 15:24:30 -070073int main(int argc, char* argv[])
Tom Josephc35524e2016-08-29 08:17:59 -050074{
Vernon Maueryd92bc322019-03-15 15:24:30 -070075 CLI::App app("KCS RMCP+ bridge");
76 std::string channel;
77 app.add_option("-c,--channel", channel, "channel name. e.g., eth0");
78 uint16_t port = ipmi::rmcpp::defaultPort;
79 app.add_option("-p,--port", port, "port number");
80 bool verbose = false;
81 app.add_option("-v,--verbose", verbose, "print more verbose output");
82 CLI11_PARSE(app, argc, argv);
83
Tom Josephc35524e2016-08-29 08:17:59 -050084 // Connect to system bus
Vernon Mauery96a1a392018-11-08 16:54:23 -080085 auto rc = sd_bus_default_system(&bus);
Tom Josephc35524e2016-08-29 08:17:59 -050086 if (rc < 0)
87 {
George Liu7b7f25f2022-07-04 17:07:32 +080088 lg2::error("Failed to connect to system bus: {ERROR}", "ERROR",
89 strerror(-rc));
Vernon Mauerycbccb052018-10-24 13:52:22 -070090 return rc;
Tom Josephc35524e2016-08-29 08:17:59 -050091 }
Vernon Mauerycbccb052018-10-24 13:52:22 -070092 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
Ratan Gupta166c71a2018-03-23 23:05:17 +053093
Vernon Mauery052b7cf2019-05-08 15:59:41 -070094 ipmi::ipmiChannelInit();
95 if (channel.size())
96 {
97 setInterfaceIndex(channel);
98 }
99
Vernon Mauery2085ae02021-06-10 11:51:00 -0700100 session::Manager::get().managerInit(channel);
Tom Joseph83029cb2017-09-01 16:37:31 +0530101 // Register callback to update cache for a GUID change and cache the GUID
102 command::registerGUIDChangeCallback();
103 cache::guid = command::getSystemGUID();
104
Jian Zhangc936eca2022-03-22 11:25:29 +0800105 // Register callback to update cache for sol conf change
106 sol::registerSolConfChangeCallbackHandler(channel);
107
Tom Josephc35524e2016-08-29 08:17:59 -0500108 // Register the phosphor-net-ipmid session setup commands
109 command::sessionSetupCommands();
110
Tom Joseph89481cf2017-04-03 02:11:34 +0530111 // Register the phosphor-net-ipmid SOL commands
112 sol::command::registerCommands();
113
Vernon Mauery2085ae02021-06-10 11:51:00 -0700114 auto& loop = eventloop::EventLoop::get();
Vernon Maueryd92bc322019-03-15 15:24:30 -0700115 if (loop.setupSocket(sdbusp, channel))
116 {
117 return EXIT_FAILURE;
118 }
119
Tom Josephc35524e2016-08-29 08:17:59 -0500120 // Start Event Loop
Vernon Maueryd92bc322019-03-15 15:24:30 -0700121 return loop.startEventLoop();
Tom Josephc35524e2016-08-29 08:17:59 -0500122}