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 "provider_registration.hpp" 9 #include "socket_channel.hpp" 10 #include "sol_module.hpp" 11 12 #include <assert.h> 13 #include <dirent.h> 14 #include <dlfcn.h> 15 #include <host-ipmid/ipmid-api.h> 16 #include <systemd/sd-daemon.h> 17 #include <systemd/sd-event.h> 18 #include <unistd.h> 19 20 #include <phosphor-logging/log.hpp> 21 #include <sdbusplus/asio/connection.hpp> 22 #include <sdbusplus/timer.hpp> 23 #include <tuple> 24 25 using namespace phosphor::logging; 26 27 // Tuple of Global Singletons 28 static auto io = std::make_shared<boost::asio::io_context>(); 29 session::Manager manager; 30 command::Table table; 31 eventloop::EventLoop loop(io); 32 sol::Manager solManager; 33 34 std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&, 35 sol::Manager&> 36 singletonPool(manager, table, loop, solManager); 37 38 sd_bus* bus = nullptr; 39 sd_event* events = nullptr; 40 41 // Global timer for network changes 42 std::unique_ptr<phosphor::Timer> networkTimer = nullptr; 43 44 FILE* ipmidbus = nullptr; 45 static unsigned short selReservationID = 0xFFFF; 46 static bool selReservationValid = false; 47 sd_bus_slot* ipmid_slot = nullptr; 48 49 std::shared_ptr<sdbusplus::bus::bus> sdbusp; 50 51 /* 52 * @brief Required by apphandler IPMI Provider Library 53 */ 54 sd_bus* ipmid_get_sd_bus_connection() 55 { 56 return bus; 57 } 58 59 /* 60 * @brief mechanism to get at sdbusplus object 61 */ 62 std::shared_ptr<sdbusplus::bus::bus> getSdBus() 63 { 64 return sdbusp; 65 } 66 67 /* 68 * @brief Required by apphandler IPMI Provider Library 69 */ 70 sd_event* ipmid_get_sd_event_connection() 71 { 72 return events; 73 } 74 75 /* 76 * @brief Required by apphandler IPMI Provider Library 77 */ 78 unsigned short reserveSel(void) 79 { 80 // IPMI spec, Reservation ID, the value simply increases against each 81 // execution of the Reserve SEL command. 82 if (++selReservationID == 0) 83 { 84 selReservationID = 1; 85 } 86 selReservationValid = true; 87 return selReservationID; 88 } 89 90 /* 91 * @brief Required by apphandler IPMI Provider Library 92 */ 93 bool checkSELReservation(unsigned short id) 94 { 95 return (selReservationValid && selReservationID == id); 96 } 97 98 /* 99 * @brief Required by apphandler IPMI Provider Library 100 */ 101 void cancelSELReservation(void) 102 { 103 selReservationValid = false; 104 } 105 106 EInterfaceIndex getInterfaceIndex(void) 107 { 108 return interfaceLAN1; 109 } 110 111 int main() 112 { 113 /* 114 * Required by apphandler IPMI Provider Library for logging. 115 */ 116 ipmidbus = fopen("/dev/null", "w"); 117 118 // Connect to system bus 119 auto rc = sd_bus_default_system(&bus); 120 if (rc < 0) 121 { 122 log<level::ERR>("Failed to connect to system bus", 123 entry("ERROR=%s", strerror(-rc))); 124 return rc; 125 } 126 127 /* Get an sd event handler */ 128 rc = sd_event_default(&events); 129 if (rc < 0) 130 { 131 log<level::ERR>("Failure to create sd_event", 132 entry("ERROR=%s", strerror(-rc))); 133 return EXIT_FAILURE; 134 } 135 sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus); 136 137 // Register callback to update cache for a GUID change and cache the GUID 138 command::registerGUIDChangeCallback(); 139 cache::guid = command::getSystemGUID(); 140 141 // Register all the IPMI provider libraries applicable for net-ipmid 142 provider::registerCallbackHandlers(NET_IPMID_LIB_PATH); 143 144 // Register the phosphor-net-ipmid session setup commands 145 command::sessionSetupCommands(); 146 147 // Register the phosphor-net-ipmid SOL commands 148 sol::command::registerCommands(); 149 150 // Start Event Loop 151 return std::get<eventloop::EventLoop&>(singletonPool).startEventLoop(); 152 } 153