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 | |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame^] | 46 | std::shared_ptr<sdbusplus::bus::bus> sdbusp; |
| 47 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 48 | /* |
| 49 | * @brief Required by apphandler IPMI Provider Library |
| 50 | */ |
| 51 | sd_bus* ipmid_get_sd_bus_connection() |
| 52 | { |
| 53 | return bus; |
| 54 | } |
| 55 | |
| 56 | /* |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame^] | 57 | * @brief mechanism to get at sdbusplus object |
| 58 | */ |
| 59 | std::shared_ptr<sdbusplus::bus::bus> getSdBus() |
| 60 | { |
| 61 | return sdbusp; |
| 62 | } |
| 63 | |
| 64 | /* |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 65 | * @brief Required by apphandler IPMI Provider Library |
| 66 | */ |
Ratan Gupta | 04edb9b | 2018-03-20 23:06:06 +0530 | [diff] [blame] | 67 | sd_event* ipmid_get_sd_event_connection() |
| 68 | { |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 69 | return events; |
Ratan Gupta | 04edb9b | 2018-03-20 23:06:06 +0530 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* |
| 73 | * @brief Required by apphandler IPMI Provider Library |
| 74 | */ |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 75 | unsigned short reserveSel(void) |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 76 | { |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 77 | // IPMI spec, Reservation ID, the value simply increases against each |
| 78 | // execution of the Reserve SEL command. |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 79 | if (++selReservationID == 0) |
| 80 | { |
Jason M. Bills | b00f8f7 | 2018-09-10 15:14:10 -0700 | [diff] [blame] | 81 | selReservationID = 1; |
| 82 | } |
| 83 | selReservationValid = true; |
| 84 | return selReservationID; |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * @brief Required by apphandler IPMI Provider Library |
| 89 | */ |
| 90 | bool checkSELReservation(unsigned short id) |
| 91 | { |
| 92 | return (selReservationValid && selReservationID == id); |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * @brief Required by apphandler IPMI Provider Library |
| 97 | */ |
| 98 | void cancelSELReservation(void) |
| 99 | { |
| 100 | selReservationValid = false; |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 101 | } |
| 102 | |
ssekar | d6f3f7d | 2018-08-16 17:30:28 +0530 | [diff] [blame] | 103 | EInterfaceIndex getInterfaceIndex(void) |
| 104 | { |
| 105 | return interfaceLAN1; |
| 106 | } |
| 107 | |
Vernon Mauery | cc7b1cb | 2018-10-24 13:13:46 -0700 | [diff] [blame] | 108 | int main() |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 109 | { |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 110 | /* |
| 111 | * Required by apphandler IPMI Provider Library for logging. |
| 112 | */ |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 113 | ipmidbus = fopen("/dev/null", "w"); |
Tom | 069f01e | 2016-12-02 14:11:37 +0530 | [diff] [blame] | 114 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 115 | // Connect to system bus |
Vernon Mauery | 96a1a39 | 2018-11-08 16:54:23 -0800 | [diff] [blame] | 116 | auto rc = sd_bus_default_system(&bus); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 117 | if (rc < 0) |
| 118 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 119 | std::cerr << "Failed to connect to system bus:" << strerror(-rc) |
| 120 | << "\n"; |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 121 | goto finish; |
| 122 | } |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame^] | 123 | sdbusp = std::make_shared<sdbusplus::bus::bus>(bus); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 124 | |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 125 | /* Get an sd event handler */ |
| 126 | rc = sd_event_default(&events); |
| 127 | if (rc < 0) |
| 128 | { |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 129 | std::cerr << "Failure to create sd_event" << strerror(-rc) << "\n"; |
Vernon Mauery | d0062ed | 2018-10-25 09:36:06 -0700 | [diff] [blame^] | 130 | return EXIT_FAILURE; |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 131 | } |
| 132 | |
Tom Joseph | 83029cb | 2017-09-01 16:37:31 +0530 | [diff] [blame] | 133 | // Register callback to update cache for a GUID change and cache the GUID |
| 134 | command::registerGUIDChangeCallback(); |
| 135 | cache::guid = command::getSystemGUID(); |
| 136 | |
Tom | 485038e | 2016-12-02 13:44:45 +0530 | [diff] [blame] | 137 | // Register all the IPMI provider libraries applicable for net-ipmid |
| 138 | provider::registerCallbackHandlers(NET_IPMID_LIB_PATH); |
| 139 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 140 | // Register the phosphor-net-ipmid session setup commands |
| 141 | command::sessionSetupCommands(); |
| 142 | |
Tom Joseph | 89481cf | 2017-04-03 02:11:34 +0530 | [diff] [blame] | 143 | // Register the phosphor-net-ipmid SOL commands |
| 144 | sol::command::registerCommands(); |
| 145 | |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 146 | // Start Event Loop |
Vernon Mauery | 9e801a2 | 2018-10-12 13:20:49 -0700 | [diff] [blame] | 147 | return std::get<eventloop::EventLoop&>(singletonPool) |
| 148 | .startEventLoop(events); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 149 | |
| 150 | finish: |
Ratan Gupta | 166c71a | 2018-03-23 23:05:17 +0530 | [diff] [blame] | 151 | sd_event_unref(events); |
Tom Joseph | c35524e | 2016-08-29 08:17:59 -0500 | [diff] [blame] | 152 | |
| 153 | return 0; |
| 154 | } |