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