Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 1 | #include "main.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 2 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 3 | #include "comm_module.hpp" |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 4 | #include "command/guid.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 5 | #include "command_table.hpp" |
| 6 | #include "message.hpp" |
| 7 | #include "message_handler.hpp" |
Tom | 485038e | 2016-12-02 13:44:45 +0530 | [diff] [blame] | 8 | #include "provider_registration.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 9 | #include "socket_channel.hpp" |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 10 | #include "sol_module.hpp" |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 11 | |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 12 | #include <assert.h> |
| 13 | #include <dirent.h> |
| 14 | #include <dlfcn.h> |
| 15 | #include <host-ipmid/ipmid-api.h> |
| 16 | #include <systemd/sd-bus.h> |
| 17 | #include <systemd/sd-daemon.h> |
| 18 | #include <systemd/sd-event.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | #include <iostream> |
Vernon Mauery | b108806 | 2018-10-24 12:49:30 -0700 | [diff] [blame] | 22 | #include <sdbusplus/timer.hpp> |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 23 | #include <tuple> |
| 24 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 25 | // Tuple of Global Singletons |
| 26 | session::Manager manager; |
| 27 | command::Table table; |
Tom Joseph | 52f53d7 | 2017-03-14 15:20:19 +0530 | [diff] [blame] | 28 | eventloop::EventLoop loop; |
| 29 | sol::Manager solManager; |
| 30 | |
| 31 | std::tuple<session::Manager&, command::Table&, eventloop::EventLoop&, |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 32 | sol::Manager&> |
| 33 | singletonPool(manager, table, loop, solManager); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 34 | |
| 35 | sd_bus* bus = nullptr; |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 36 | sd_event* events = nullptr; |
Marri Devender Rao | 3ecf0a1 | 2017-07-13 08:07:22 -0500 | [diff] [blame] | 37 | |
Ratan Gupta | 4080136 | 2018-03-12 16:21:37 +0530 | [diff] [blame] | 38 | // Global timer for network changes |
Vernon Mauery | b108806 | 2018-10-24 12:49:30 -0700 | [diff] [blame] | 39 | std::unique_ptr<phosphor::Timer> networkTimer = nullptr; |
Ratan Gupta | 4080136 | 2018-03-12 16:21:37 +0530 | [diff] [blame] | 40 | |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 41 | FILE* ipmidbus = nullptr; |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 42 | static unsigned short selReservationID = 0xFFFF; |
| 43 | static bool selReservationValid = false; |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 44 | sd_bus_slot* ipmid_slot = nullptr; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * @brief Required by apphandler IPMI Provider Library |
| 48 | */ |
| 49 | sd_bus* ipmid_get_sd_bus_connection() |
| 50 | { |
| 51 | return bus; |
| 52 | } |
| 53 | |
| 54 | /* |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 55 | * @brief Required by apphandler IPMI Provider Library |
| 56 | */ |
Ratan Gupta | 04edb9b | 2018-03-20 23:06:06 +0530 | [diff] [blame] | 57 | sd_event* ipmid_get_sd_event_connection() |
| 58 | { |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 59 | return events; |
Ratan Gupta | 04edb9b | 2018-03-20 23:06:06 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /* |
| 63 | * @brief Required by apphandler IPMI Provider Library |
| 64 | */ |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 65 | unsigned short reserveSel(void) |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 66 | { |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 67 | // IPMI spec, Reservation ID, the value simply increases against each |
| 68 | // execution of the Reserve SEL command. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 69 | if (++selReservationID == 0) |
| 70 | { |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 71 | selReservationID = 1; |
| 72 | } |
| 73 | selReservationValid = true; |
| 74 | return selReservationID; |
| 75 | } |
| 76 | |
| 77 | /* |
| 78 | * @brief Required by apphandler IPMI Provider Library |
| 79 | */ |
| 80 | bool checkSELReservation(unsigned short id) |
| 81 | { |
| 82 | return (selReservationValid && selReservationID == id); |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * @brief Required by apphandler IPMI Provider Library |
| 87 | */ |
| 88 | void cancelSELReservation(void) |
| 89 | { |
| 90 | selReservationValid = false; |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 91 | } |
| 92 | |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 93 | EInterfaceIndex getInterfaceIndex(void) |
| 94 | { |
| 95 | return interfaceLAN1; |
| 96 | } |
| 97 | |
Vernon Mauery | cc7b1cb | 2018-10-24 13:13:46 -0700 | [diff] [blame] | 98 | int main() |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 99 | { |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 100 | /* |
| 101 | * Required by apphandler IPMI Provider Library for logging. |
| 102 | */ |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 103 | ipmidbus = fopen("/dev/null", "w"); |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 104 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 105 | // Connect to system bus |
Vernon Mauery | 96a1a39 | 2018-11-08 16:54:23 -0800 | [diff] [blame] | 106 | auto rc = sd_bus_default_system(&bus); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 107 | if (rc < 0) |
| 108 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 109 | std::cerr << "Failed to connect to system bus:" << strerror(-rc) |
| 110 | << "\n"; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 111 | goto finish; |
| 112 | } |
| 113 | |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 114 | /* Get an sd event handler */ |
| 115 | rc = sd_event_default(&events); |
| 116 | if (rc < 0) |
| 117 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 118 | std::cerr << "Failure to create sd_event" << strerror(-rc) << "\n"; |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 119 | goto finish; |
| 120 | } |
| 121 | |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 122 | // Register callback to update cache for a GUID change and cache the GUID |
| 123 | command::registerGUIDChangeCallback(); |
| 124 | cache::guid = command::getSystemGUID(); |
| 125 | |
Tom | 485038e | 2016-12-02 13:44:45 +0530 | [diff] [blame] | 126 | // Register all the IPMI provider libraries applicable for net-ipmid |
| 127 | provider::registerCallbackHandlers(NET_IPMID_LIB_PATH); |
| 128 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 129 | // Register the phosphor-net-ipmid session setup commands |
| 130 | command::sessionSetupCommands(); |
| 131 | |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 132 | // Register the phosphor-net-ipmid SOL commands |
| 133 | sol::command::registerCommands(); |
| 134 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 135 | // Start Event Loop |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 136 | return std::get<eventloop::EventLoop&>(singletonPool) |
| 137 | .startEventLoop(events); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 138 | |
| 139 | finish: |
| 140 | sd_bus_unref(bus); |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 141 | sd_event_unref(events); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |