blob: 1ab23222f8225b7ffdb9dbed10440645698d6dd8 [file] [log] [blame]
Vishwanatha Subbannab891a572017-03-31 11:34:48 +05301#include "config.h"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
Patrick Venture46470a32018-09-07 19:26:25 -07003#include "systemintfcmds.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07004
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +05305#include "host-cmd-manager.hpp"
Andrew Geissler12866372017-03-21 22:58:28 -05006#include "host-interface.hpp"
Tom9e5232e2016-11-07 12:14:51 +05307
William A. Kennington III194375f2018-12-14 02:14:33 -08008#include <ipmid-host/cmd.hpp>
Vernon Mauery240b1862018-10-08 12:05:16 -07009#include <ipmid/api.hpp>
Tom9e5232e2016-11-07 12:14:51 +053010
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050011#include <cstring>
12
Tom9e5232e2016-11-07 12:14:51 +053013void register_netfn_app_functions() __attribute__((constructor));
14
Andrew Geissler12866372017-03-21 22:58:28 -050015using namespace sdbusplus::xyz::openbmc_project::Control::server;
16
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053017// For accessing Host command manager
18using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>;
19extern cmdManagerPtr& ipmid_get_host_cmd_manager();
Andrew Geissler12866372017-03-21 22:58:28 -050020
Andrew Geissler12866372017-03-21 22:58:28 -050021//-------------------------------------------------------------------
22// Called by Host post response from Get_Message_Flags
23//-------------------------------------------------------------------
Willy Tu11d68892022-01-20 10:37:34 -080024ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
25 ipmi_response_t response,
26 ipmi_data_len_t data_len, ipmi_context_t)
Andrew Geissler12866372017-03-21 22:58:28 -050027{
28 ipmi_ret_t rc = IPMI_CC_OK;
29
Willy Tu11d68892022-01-20 10:37:34 -080030 struct oem_sel_timestamped oem_sel = {};
Andrew Geissler12866372017-03-21 22:58:28 -050031 *data_len = sizeof(struct oem_sel_timestamped);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053032
Tom9e5232e2016-11-07 12:14:51 +053033 // either id[0] -or- id[1] can be filled in. We will use id[0]
Patrick Venture0b02be92018-08-31 11:55:55 -070034 oem_sel.id[0] = SEL_OEM_ID_0;
35 oem_sel.id[1] = SEL_OEM_ID_0;
36 oem_sel.type = SEL_RECORD_TYPE_OEM;
Tom9e5232e2016-11-07 12:14:51 +053037
38 // Following 3 bytes are from IANA Manufactre_Id field. See below
Patrick Venture0b02be92018-08-31 11:55:55 -070039 oem_sel.manuf_id[0] = 0x41;
40 oem_sel.manuf_id[1] = 0xA7;
41 oem_sel.manuf_id[2] = 0x00;
Tom9e5232e2016-11-07 12:14:51 +053042
43 // per IPMI spec NetFuntion for OEM
Patrick Venture0b02be92018-08-31 11:55:55 -070044 oem_sel.netfun = 0x3A;
Tom9e5232e2016-11-07 12:14:51 +053045
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053046 // Read from the Command Manager queue. What gets returned is a
47 // pair of <command, data> that can be directly used here
Patrick Venture0b02be92018-08-31 11:55:55 -070048 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand();
49 oem_sel.cmd = hostCmd.first;
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053050 oem_sel.data[0] = hostCmd.second;
Tom9e5232e2016-11-07 12:14:51 +053051
52 // All '0xFF' since unused.
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070053 std::memset(&oem_sel.data[1], 0xFF, 3);
Tom9e5232e2016-11-07 12:14:51 +053054
55 // Pack the actual response
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070056 std::memcpy(response, &oem_sel, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053057 return rc;
58}
59
60//---------------------------------------------------------------------
61// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
XP Chen414d2f72021-09-20 16:19:11 -050062// value of 0x0 to indicate Event Message Buffer is not supported
Tom9e5232e2016-11-07 12:14:51 +053063//-------------------------------------------------------------------
Andrew Geissler461f4642019-04-22 10:34:34 -050064ipmi::RspType<uint8_t> ipmiAppGetMessageFlags()
Tom9e5232e2016-11-07 12:14:51 +053065{
Tom9e5232e2016-11-07 12:14:51 +053066 // From IPMI spec V2.0 for Get Message Flags Command :
67 // bit:[1] from LSB : 1b = Event Message Buffer Full.
68 // Return as 0 if Event Message Buffer is not supported,
69 // or when the Event Message buffer is disabled.
Andrew Geissler461f4642019-04-22 10:34:34 -050070 // This path is used to communicate messages to the host
71 // from within the phosphor::host::command::Manager
XP Chen414d2f72021-09-20 16:19:11 -050072 constexpr uint8_t setEventMsgBufferNotSupported = 0x0;
73 return ipmi::responseSuccess(setEventMsgBufferNotSupported);
Tom9e5232e2016-11-07 12:14:51 +053074}
75
Yong Li5aa26932019-11-04 13:25:43 +080076ipmi::RspType<bool, // Receive Message Queue Interrupt Enabled
77 bool, // Event Message Buffer Full Interrupt Enabled
78 bool, // Event Message Buffer Enabled
79 bool, // System Event Logging Enabled
80 uint1_t, // Reserved
81 bool, // OEM 0 enabled
82 bool, // OEM 1 enabled
83 bool // OEM 2 enabled
84 >
85 ipmiAppGetBMCGlobalEnable()
Jia, Chunhui30206db2018-12-11 09:00:15 +080086{
Yong Li5aa26932019-11-04 13:25:43 +080087 return ipmi::responseSuccess(true, false, false, true, 0, false, false,
88 false);
Jia, Chunhui30206db2018-12-11 09:00:15 +080089}
90
Yong Liecd7bb92019-10-29 13:24:40 +080091ipmi::RspType<> ipmiAppSetBMCGlobalEnable(
92 ipmi::Context::ptr ctx, bool receiveMessageQueueInterruptEnabled,
93 bool eventMessageBufferFullInterruptEnabled, bool eventMessageBufferEnabled,
94 bool systemEventLogEnable, uint1_t reserved, bool OEM0Enabled,
95 bool OEM1Enabled, bool OEM2Enabled)
Tom9e5232e2016-11-07 12:14:51 +053096{
Yong Lia249a082019-10-29 13:37:17 +080097 ipmi::ChannelInfo chInfo;
98
99 if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess)
100 {
101 phosphor::logging::log<phosphor::logging::level::ERR>(
102 "Failed to get Channel Info",
103 phosphor::logging::entry("CHANNEL=%d", ctx->channel));
104 return ipmi::responseUnspecifiedError();
105 }
106
107 if (chInfo.mediumType !=
108 static_cast<uint8_t>(ipmi::EChannelMediumType::systemInterface))
109 {
110 phosphor::logging::log<phosphor::logging::level::ERR>(
111 "Error - supported only in system interface");
112 return ipmi::responseCommandNotAvailable();
113 }
114
Jia, Chunhui30206db2018-12-11 09:00:15 +0800115 // Recv Message Queue and SEL are enabled by default.
116 // Event Message buffer are disabled by default (not supported).
117 // Any request that try to change the mask will be rejected
Yong Liecd7bb92019-10-29 13:24:40 +0800118 if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable ||
119 eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled ||
120 OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved)
Jia, Chunhui30206db2018-12-11 09:00:15 +0800121 {
Yong Liecd7bb92019-10-29 13:24:40 +0800122 return ipmi::responseInvalidFieldRequest();
Jia, Chunhui30206db2018-12-11 09:00:15 +0800123 }
Yong Liecd7bb92019-10-29 13:24:40 +0800124
125 return ipmi::responseSuccess();
Tom9e5232e2016-11-07 12:14:51 +0530126}
127
Patrick Venture0b02be92018-08-31 11:55:55 -0700128namespace
129{
Lei YU12c2db72017-05-15 11:24:04 +0800130// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530131std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700132 __attribute__((init_priority(101)));
Patrick Williams5d82f472022-07-22 19:26:53 -0500133std::unique_ptr<sdbusplus::server::manager_t> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700134 __attribute__((init_priority(101)));
135} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500136
Tom9e5232e2016-11-07 12:14:51 +0530137void register_netfn_app_functions()
138{
Tom9e5232e2016-11-07 12:14:51 +0530139 // <Read Event Message Buffer>
Patrick Venture0b02be92018-08-31 11:55:55 -0700140 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL,
141 ipmi_app_read_event, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530142
143 // <Set BMC Global Enables>
Yong Liecd7bb92019-10-29 13:24:40 +0800144 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
145 ipmi::app::cmdSetBmcGlobalEnables,
146 ipmi::Privilege::Admin, ipmiAppSetBMCGlobalEnable);
Tom9e5232e2016-11-07 12:14:51 +0530147
Jia, Chunhui30206db2018-12-11 09:00:15 +0800148 // <Get BMC Global Enables>
Yong Li5aa26932019-11-04 13:25:43 +0800149 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
150 ipmi::app::cmdGetBmcGlobalEnables,
151 ipmi::Privilege::User, ipmiAppGetBMCGlobalEnable);
Jia, Chunhui30206db2018-12-11 09:00:15 +0800152
Tom9e5232e2016-11-07 12:14:51 +0530153 // <Get Message Flags>
Andrew Geissler461f4642019-04-22 10:34:34 -0500154 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
155 ipmi::app::cmdGetMessageFlags, ipmi::Privilege::Admin,
156 ipmiAppGetMessageFlags);
Tom9e5232e2016-11-07 12:14:51 +0530157
Andrew Geissler12866372017-03-21 22:58:28 -0500158 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530159 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500160
Vernon Mauery20ff3332019-03-01 16:52:25 -0800161 std::unique_ptr<sdbusplus::asio::connection>& sdbusp =
162 ipmid_get_sdbus_plus_handler();
Andrew Geissler12866372017-03-21 22:58:28 -0500163
Vernon Mauery240b1862018-10-08 12:05:16 -0700164 // Add sdbusplus ObjectManager.
Patrick Williams5d82f472022-07-22 19:26:53 -0500165 objManager = std::make_unique<sdbusplus::server::manager_t>(
Vernon Mauery240b1862018-10-08 12:05:16 -0700166 *sdbusp, CONTROL_HOST_OBJ_MGR);
167
168 host = std::make_unique<phosphor::host::command::Host>(*sdbusp,
Patrick Venture0b02be92018-08-31 11:55:55 -0700169 objPath.c_str());
Vernon Mauery240b1862018-10-08 12:05:16 -0700170 sdbusp->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500171
Tom9e5232e2016-11-07 12:14:51 +0530172 return;
173}