Vishwanatha Subbanna | b891a57 | 2017-03-31 11:34:48 +0530 | [diff] [blame] | 1 | #include "config.h" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 2 | |
Patrick Venture | 46470a3 | 2018-09-07 19:26:25 -0700 | [diff] [blame] | 3 | #include "systemintfcmds.hpp" |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 4 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 5 | #include "host-cmd-manager.hpp" |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 6 | #include "host-interface.hpp" |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 7 | |
William A. Kennington III | 194375f | 2018-12-14 02:14:33 -0800 | [diff] [blame] | 8 | #include <ipmid-host/cmd.hpp> |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 9 | #include <ipmid/api.hpp> |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 10 | #include <nlohmann/json.hpp> |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 11 | |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 12 | #include <cstring> |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 13 | #include <fstream> |
Patrick Williams | fbc6c9d | 2023-05-10 07:50:16 -0500 | [diff] [blame] | 14 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 15 | void register_netfn_app_functions() __attribute__((constructor)); |
| 16 | |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 17 | using namespace sdbusplus::server::xyz::openbmc_project::control; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 18 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 19 | // For accessing Host command manager |
| 20 | using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>; |
| 21 | extern cmdManagerPtr& ipmid_get_host_cmd_manager(); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 22 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 23 | //------------------------------------------------------------------- |
| 24 | // Called by Host post response from Get_Message_Flags |
| 25 | //------------------------------------------------------------------- |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 26 | ipmi::RspType<uint16_t, // id |
| 27 | uint8_t, // type |
| 28 | uint24_t, // manuf_id |
| 29 | uint32_t, // timestamp |
| 30 | uint8_t, // netfun |
| 31 | uint8_t, // cmd |
| 32 | std::array<uint8_t, 4> // data |
| 33 | > |
| 34 | ipmiAppReadEventBuffer(ipmi::Context::ptr& ctx) |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 35 | { |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 36 | // require this to be limited to system interface |
| 37 | if (ctx->channel != ipmi::channelSystemIface) |
| 38 | { |
| 39 | return ipmi::responseInvalidCommand(); |
| 40 | } |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 41 | |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 42 | constexpr uint16_t selOemId = 0x5555; |
| 43 | constexpr uint8_t selRecordTypeOem = 0xc0; |
Vishwanatha Subbanna | 83b5c1c | 2017-01-25 18:41:51 +0530 | [diff] [blame] | 44 | |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 45 | // read manufacturer ID from dev_id file |
| 46 | static uint24_t manufId{}; |
| 47 | if (!manufId) |
| 48 | { |
| 49 | const char* filename = "/usr/share/ipmi-providers/dev_id.json"; |
| 50 | std::ifstream devIdFile(filename); |
| 51 | if (devIdFile.is_open()) |
| 52 | { |
| 53 | auto data = nlohmann::json::parse(devIdFile, nullptr, false); |
| 54 | if (!data.is_discarded()) |
| 55 | { |
| 56 | manufId = data.value("manuf_id", 0); |
| 57 | } |
| 58 | } |
| 59 | } |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 60 | |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 61 | constexpr uint32_t timestamp{0}; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 62 | |
| 63 | // per IPMI spec NetFuntion for OEM |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 64 | constexpr uint8_t netfun = 0x3a; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 65 | |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 66 | // Read from the Command Manager queue. What gets returned is a |
| 67 | // pair of <command, data> that can be directly used here |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 68 | const auto& [cmd, data0] = ipmid_get_host_cmd_manager()->getNextCommand(); |
| 69 | constexpr uint8_t dataUnused = 0xff; |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 70 | |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 71 | return ipmi::responseSuccess( |
| 72 | selOemId, selRecordTypeOem, manufId, timestamp, netfun, cmd, |
| 73 | std::to_array<uint8_t>({data0, dataUnused, dataUnused, dataUnused})); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | //--------------------------------------------------------------------- |
| 77 | // Called by Host on seeing a SMS_ATN bit set. Return a hardcoded |
XP Chen | 414d2f7 | 2021-09-20 16:19:11 -0500 | [diff] [blame] | 78 | // value of 0x0 to indicate Event Message Buffer is not supported |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 79 | //------------------------------------------------------------------- |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 80 | ipmi::RspType<uint8_t> ipmiAppGetMessageFlags() |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 81 | { |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 82 | // From IPMI spec V2.0 for Get Message Flags Command : |
| 83 | // bit:[1] from LSB : 1b = Event Message Buffer Full. |
| 84 | // Return as 0 if Event Message Buffer is not supported, |
| 85 | // or when the Event Message buffer is disabled. |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 86 | // This path is used to communicate messages to the host |
| 87 | // from within the phosphor::host::command::Manager |
XP Chen | 414d2f7 | 2021-09-20 16:19:11 -0500 | [diff] [blame] | 88 | constexpr uint8_t setEventMsgBufferNotSupported = 0x0; |
| 89 | return ipmi::responseSuccess(setEventMsgBufferNotSupported); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 90 | } |
| 91 | |
Yong Li | 5aa2693 | 2019-11-04 13:25:43 +0800 | [diff] [blame] | 92 | ipmi::RspType<bool, // Receive Message Queue Interrupt Enabled |
| 93 | bool, // Event Message Buffer Full Interrupt Enabled |
| 94 | bool, // Event Message Buffer Enabled |
| 95 | bool, // System Event Logging Enabled |
| 96 | uint1_t, // Reserved |
| 97 | bool, // OEM 0 enabled |
| 98 | bool, // OEM 1 enabled |
| 99 | bool // OEM 2 enabled |
| 100 | > |
| 101 | ipmiAppGetBMCGlobalEnable() |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 102 | { |
Yong Li | 5aa2693 | 2019-11-04 13:25:43 +0800 | [diff] [blame] | 103 | return ipmi::responseSuccess(true, false, false, true, 0, false, false, |
| 104 | false); |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 105 | } |
| 106 | |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 107 | ipmi::RspType<> ipmiAppSetBMCGlobalEnable( |
| 108 | ipmi::Context::ptr ctx, bool receiveMessageQueueInterruptEnabled, |
| 109 | bool eventMessageBufferFullInterruptEnabled, bool eventMessageBufferEnabled, |
| 110 | bool systemEventLogEnable, uint1_t reserved, bool OEM0Enabled, |
| 111 | bool OEM1Enabled, bool OEM2Enabled) |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 112 | { |
Yong Li | a249a08 | 2019-10-29 13:37:17 +0800 | [diff] [blame] | 113 | ipmi::ChannelInfo chInfo; |
| 114 | |
| 115 | if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess) |
| 116 | { |
| 117 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 118 | "Failed to get Channel Info", |
| 119 | phosphor::logging::entry("CHANNEL=%d", ctx->channel)); |
| 120 | return ipmi::responseUnspecifiedError(); |
| 121 | } |
| 122 | |
| 123 | if (chInfo.mediumType != |
| 124 | static_cast<uint8_t>(ipmi::EChannelMediumType::systemInterface)) |
| 125 | { |
| 126 | phosphor::logging::log<phosphor::logging::level::ERR>( |
| 127 | "Error - supported only in system interface"); |
| 128 | return ipmi::responseCommandNotAvailable(); |
| 129 | } |
| 130 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 131 | // Recv Message Queue and SEL are enabled by default. |
| 132 | // Event Message buffer are disabled by default (not supported). |
| 133 | // Any request that try to change the mask will be rejected |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 134 | if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable || |
| 135 | eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled || |
| 136 | OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved) |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 137 | { |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 138 | return ipmi::responseInvalidFieldRequest(); |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 139 | } |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 140 | |
| 141 | return ipmi::responseSuccess(); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 142 | } |
| 143 | |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 144 | namespace |
| 145 | { |
Lei YU | 12c2db7 | 2017-05-15 11:24:04 +0800 | [diff] [blame] | 146 | // Static storage to keep the object alive during process life |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 147 | std::unique_ptr<phosphor::host::command::Host> host |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 148 | __attribute__((init_priority(101))); |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 149 | std::unique_ptr<sdbusplus::server::manager_t> objManager |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 150 | __attribute__((init_priority(101))); |
| 151 | } // namespace |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 152 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 153 | void register_netfn_app_functions() |
| 154 | { |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 155 | // <Read Event Message Buffer> |
Vernon Mauery | e4aa654 | 2023-11-01 14:29:21 -0700 | [diff] [blame] | 156 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 157 | ipmi::app::cmdReadEventMessageBuffer, |
| 158 | ipmi::Privilege::Admin, ipmiAppReadEventBuffer); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 159 | |
| 160 | // <Set BMC Global Enables> |
Yong Li | ecd7bb9 | 2019-10-29 13:24:40 +0800 | [diff] [blame] | 161 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 162 | ipmi::app::cmdSetBmcGlobalEnables, |
| 163 | ipmi::Privilege::Admin, ipmiAppSetBMCGlobalEnable); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 164 | |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 165 | // <Get BMC Global Enables> |
Yong Li | 5aa2693 | 2019-11-04 13:25:43 +0800 | [diff] [blame] | 166 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 167 | ipmi::app::cmdGetBmcGlobalEnables, |
| 168 | ipmi::Privilege::User, ipmiAppGetBMCGlobalEnable); |
Jia, Chunhui | 30206db | 2018-12-11 09:00:15 +0800 | [diff] [blame] | 169 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 170 | // <Get Message Flags> |
Andrew Geissler | 461f464 | 2019-04-22 10:34:34 -0500 | [diff] [blame] | 171 | ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp, |
| 172 | ipmi::app::cmdGetMessageFlags, ipmi::Privilege::Admin, |
| 173 | ipmiAppGetMessageFlags); |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 174 | |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 175 | // Create new xyz.openbmc_project.host object on the bus |
Vishwanatha Subbanna | 3eb117a | 2017-07-12 16:13:49 +0530 | [diff] [blame] | 176 | auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0'; |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 177 | |
Vernon Mauery | 20ff333 | 2019-03-01 16:52:25 -0800 | [diff] [blame] | 178 | std::unique_ptr<sdbusplus::asio::connection>& sdbusp = |
| 179 | ipmid_get_sdbus_plus_handler(); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 180 | |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 181 | // Add sdbusplus ObjectManager. |
Patrick Williams | 5d82f47 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 182 | objManager = std::make_unique<sdbusplus::server::manager_t>( |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 183 | *sdbusp, CONTROL_HOST_OBJ_MGR); |
| 184 | |
| 185 | host = std::make_unique<phosphor::host::command::Host>(*sdbusp, |
Patrick Venture | 0b02be9 | 2018-08-31 11:55:55 -0700 | [diff] [blame] | 186 | objPath.c_str()); |
Vernon Mauery | 240b186 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 187 | sdbusp->request_name(CONTROL_HOST_BUSNAME); |
Andrew Geissler | 1286637 | 2017-03-21 22:58:28 -0500 | [diff] [blame] | 188 | |
Tom | 9e5232e | 2016-11-07 12:14:51 +0530 | [diff] [blame] | 189 | return; |
| 190 | } |