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 <tuple> 25 #include <user_channel/channel_layer.hpp> 26 27 using namespace phosphor::logging; 28 29 static auto io = std::make_shared<boost::asio::io_context>(); 30 std::shared_ptr<boost::asio::io_context> getIo() 31 { 32 return io; 33 } 34 35 sd_bus* bus = nullptr; 36 37 std::shared_ptr<sdbusplus::asio::connection> sdbusp; 38 39 /* 40 * @brief Required by apphandler IPMI Provider Library 41 */ 42 sd_bus* ipmid_get_sd_bus_connection() 43 { 44 return bus; 45 } 46 47 /* 48 * @brief mechanism to get at sdbusplus object 49 */ 50 std::shared_ptr<sdbusplus::asio::connection> getSdBus() 51 { 52 return sdbusp; 53 } 54 55 static EInterfaceIndex currentInterfaceIndex = interfaceUnknown; 56 static 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 } 70 EInterfaceIndex getInterfaceIndex(void) 71 { 72 return currentInterfaceIndex; 73 } 74 75 int main(int argc, char* argv[]) 76 { 77 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 86 // Connect to system bus 87 auto rc = sd_bus_default_system(&bus); 88 if (rc < 0) 89 { 90 log<level::ERR>("Failed to connect to system bus", 91 entry("ERROR=%s", strerror(-rc))); 92 return rc; 93 } 94 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus); 95 96 ipmi::ipmiChannelInit(); 97 if (channel.size()) 98 { 99 setInterfaceIndex(channel); 100 } 101 102 session::Manager::get().managerInit(channel); 103 // Register callback to update cache for a GUID change and cache the GUID 104 command::registerGUIDChangeCallback(); 105 cache::guid = command::getSystemGUID(); 106 107 // Register the phosphor-net-ipmid session setup commands 108 command::sessionSetupCommands(); 109 110 // Register the phosphor-net-ipmid SOL commands 111 sol::command::registerCommands(); 112 113 auto& loop = eventloop::EventLoop::get(); 114 if (loop.setupSocket(sdbusp, channel)) 115 { 116 return EXIT_FAILURE; 117 } 118 119 // Start Event Loop 120 return loop.startEventLoop(); 121 } 122