1 #include "main.hpp" 2 3 #include "comm_module.hpp" 4 #include "command/guid.hpp" 5 #include "command_table.hpp" 6 #include "message.hpp" 7 #include "message_handler.hpp" 8 #include "sd_event_loop.hpp" 9 #include "sessions_manager.hpp" 10 #include "socket_channel.hpp" 11 #include "sol_module.hpp" 12 13 #include <assert.h> 14 #include <dirent.h> 15 #include <dlfcn.h> 16 #include <ipmid/api.h> 17 #include <systemd/sd-daemon.h> 18 #include <systemd/sd-event.h> 19 #include <unistd.h> 20 21 #include <CLI/CLI.hpp> 22 #include <phosphor-logging/log.hpp> 23 #include <sdbusplus/asio/connection.hpp> 24 #include <user_channel/channel_layer.hpp> 25 26 #include <tuple> 27 28 using namespace phosphor::logging; 29 30 static auto io = std::make_shared<boost::asio::io_context>(); 31 std::shared_ptr<boost::asio::io_context> getIo() 32 { 33 return io; 34 } 35 36 sd_bus* bus = nullptr; 37 38 std::shared_ptr<sdbusplus::asio::connection> sdbusp; 39 40 /* 41 * @brief Required by apphandler IPMI Provider Library 42 */ 43 sd_bus* ipmid_get_sd_bus_connection() 44 { 45 return bus; 46 } 47 48 /* 49 * @brief mechanism to get at sdbusplus object 50 */ 51 std::shared_ptr<sdbusplus::asio::connection> getSdBus() 52 { 53 return sdbusp; 54 } 55 56 static EInterfaceIndex currentInterfaceIndex = interfaceUnknown; 57 static 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 } 71 EInterfaceIndex getInterfaceIndex(void) 72 { 73 return currentInterfaceIndex; 74 } 75 76 int main(int argc, char* argv[]) 77 { 78 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 87 // Connect to system bus 88 auto rc = sd_bus_default_system(&bus); 89 if (rc < 0) 90 { 91 log<level::ERR>("Failed to connect to system bus", 92 entry("ERROR=%s", strerror(-rc))); 93 return rc; 94 } 95 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus); 96 97 ipmi::ipmiChannelInit(); 98 if (channel.size()) 99 { 100 setInterfaceIndex(channel); 101 } 102 103 session::Manager::get().managerInit(channel); 104 // Register callback to update cache for a GUID change and cache the GUID 105 command::registerGUIDChangeCallback(); 106 cache::guid = command::getSystemGUID(); 107 108 // Register callback to update cache for sol conf change 109 sol::registerSolConfChangeCallbackHandler(channel); 110 111 // Register the phosphor-net-ipmid session setup commands 112 command::sessionSetupCommands(); 113 114 // Register the phosphor-net-ipmid SOL commands 115 sol::command::registerCommands(); 116 117 auto& loop = eventloop::EventLoop::get(); 118 if (loop.setupSocket(sdbusp, channel)) 119 { 120 return EXIT_FAILURE; 121 } 122 123 // Start Event Loop 124 return loop.startEventLoop(); 125 } 126