blob: 23e80a2244461c403a5e1ed60be2cf99cf129bb8 [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
Patrick Ventureb51bf9c2018-09-10 15:53:14 -07008#include <cstring>
William A. Kennington III194375f2018-12-14 02:14:33 -08009#include <ipmid-host/cmd.hpp>
Vernon Mauery240b1862018-10-08 12:05:16 -070010#include <ipmid/api.hpp>
Tom9e5232e2016-11-07 12:14:51 +053011
12void register_netfn_app_functions() __attribute__((constructor));
13
Andrew Geissler12866372017-03-21 22:58:28 -050014using namespace sdbusplus::xyz::openbmc_project::Control::server;
15
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053016// For accessing Host command manager
17using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>;
18extern cmdManagerPtr& ipmid_get_host_cmd_manager();
Andrew Geissler12866372017-03-21 22:58:28 -050019
Andrew Geissler12866372017-03-21 22:58:28 -050020//-------------------------------------------------------------------
21// Called by Host post response from Get_Message_Flags
22//-------------------------------------------------------------------
Willy Tu11d68892022-01-20 10:37:34 -080023ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t, ipmi_cmd_t, ipmi_request_t,
24 ipmi_response_t response,
25 ipmi_data_len_t data_len, ipmi_context_t)
Andrew Geissler12866372017-03-21 22:58:28 -050026{
27 ipmi_ret_t rc = IPMI_CC_OK;
28
Willy Tu11d68892022-01-20 10:37:34 -080029 struct oem_sel_timestamped oem_sel = {};
Andrew Geissler12866372017-03-21 22:58:28 -050030 *data_len = sizeof(struct oem_sel_timestamped);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053031
Tom9e5232e2016-11-07 12:14:51 +053032 // either id[0] -or- id[1] can be filled in. We will use id[0]
Patrick Venture0b02be92018-08-31 11:55:55 -070033 oem_sel.id[0] = SEL_OEM_ID_0;
34 oem_sel.id[1] = SEL_OEM_ID_0;
35 oem_sel.type = SEL_RECORD_TYPE_OEM;
Tom9e5232e2016-11-07 12:14:51 +053036
37 // Following 3 bytes are from IANA Manufactre_Id field. See below
Patrick Venture0b02be92018-08-31 11:55:55 -070038 oem_sel.manuf_id[0] = 0x41;
39 oem_sel.manuf_id[1] = 0xA7;
40 oem_sel.manuf_id[2] = 0x00;
Tom9e5232e2016-11-07 12:14:51 +053041
42 // per IPMI spec NetFuntion for OEM
Patrick Venture0b02be92018-08-31 11:55:55 -070043 oem_sel.netfun = 0x3A;
Tom9e5232e2016-11-07 12:14:51 +053044
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053045 // Read from the Command Manager queue. What gets returned is a
46 // pair of <command, data> that can be directly used here
Patrick Venture0b02be92018-08-31 11:55:55 -070047 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand();
48 oem_sel.cmd = hostCmd.first;
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053049 oem_sel.data[0] = hostCmd.second;
Tom9e5232e2016-11-07 12:14:51 +053050
51 // All '0xFF' since unused.
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070052 std::memset(&oem_sel.data[1], 0xFF, 3);
Tom9e5232e2016-11-07 12:14:51 +053053
54 // Pack the actual response
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070055 std::memcpy(response, &oem_sel, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053056 return rc;
57}
58
59//---------------------------------------------------------------------
60// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
XP Chen414d2f72021-09-20 16:19:11 -050061// value of 0x0 to indicate Event Message Buffer is not supported
Tom9e5232e2016-11-07 12:14:51 +053062//-------------------------------------------------------------------
Andrew Geissler461f4642019-04-22 10:34:34 -050063ipmi::RspType<uint8_t> ipmiAppGetMessageFlags()
Tom9e5232e2016-11-07 12:14:51 +053064{
Tom9e5232e2016-11-07 12:14:51 +053065 // From IPMI spec V2.0 for Get Message Flags Command :
66 // bit:[1] from LSB : 1b = Event Message Buffer Full.
67 // Return as 0 if Event Message Buffer is not supported,
68 // or when the Event Message buffer is disabled.
Andrew Geissler461f4642019-04-22 10:34:34 -050069 // This path is used to communicate messages to the host
70 // from within the phosphor::host::command::Manager
XP Chen414d2f72021-09-20 16:19:11 -050071 constexpr uint8_t setEventMsgBufferNotSupported = 0x0;
72 return ipmi::responseSuccess(setEventMsgBufferNotSupported);
Tom9e5232e2016-11-07 12:14:51 +053073}
74
Yong Li5aa26932019-11-04 13:25:43 +080075ipmi::RspType<bool, // Receive Message Queue Interrupt Enabled
76 bool, // Event Message Buffer Full Interrupt Enabled
77 bool, // Event Message Buffer Enabled
78 bool, // System Event Logging Enabled
79 uint1_t, // Reserved
80 bool, // OEM 0 enabled
81 bool, // OEM 1 enabled
82 bool // OEM 2 enabled
83 >
84 ipmiAppGetBMCGlobalEnable()
Jia, Chunhui30206db2018-12-11 09:00:15 +080085{
Yong Li5aa26932019-11-04 13:25:43 +080086 return ipmi::responseSuccess(true, false, false, true, 0, false, false,
87 false);
Jia, Chunhui30206db2018-12-11 09:00:15 +080088}
89
Yong Liecd7bb92019-10-29 13:24:40 +080090ipmi::RspType<> ipmiAppSetBMCGlobalEnable(
91 ipmi::Context::ptr ctx, bool receiveMessageQueueInterruptEnabled,
92 bool eventMessageBufferFullInterruptEnabled, bool eventMessageBufferEnabled,
93 bool systemEventLogEnable, uint1_t reserved, bool OEM0Enabled,
94 bool OEM1Enabled, bool OEM2Enabled)
Tom9e5232e2016-11-07 12:14:51 +053095{
Yong Lia249a082019-10-29 13:37:17 +080096 ipmi::ChannelInfo chInfo;
97
98 if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess)
99 {
100 phosphor::logging::log<phosphor::logging::level::ERR>(
101 "Failed to get Channel Info",
102 phosphor::logging::entry("CHANNEL=%d", ctx->channel));
103 return ipmi::responseUnspecifiedError();
104 }
105
106 if (chInfo.mediumType !=
107 static_cast<uint8_t>(ipmi::EChannelMediumType::systemInterface))
108 {
109 phosphor::logging::log<phosphor::logging::level::ERR>(
110 "Error - supported only in system interface");
111 return ipmi::responseCommandNotAvailable();
112 }
113
Jia, Chunhui30206db2018-12-11 09:00:15 +0800114 // Recv Message Queue and SEL are enabled by default.
115 // Event Message buffer are disabled by default (not supported).
116 // Any request that try to change the mask will be rejected
Yong Liecd7bb92019-10-29 13:24:40 +0800117 if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable ||
118 eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled ||
119 OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved)
Jia, Chunhui30206db2018-12-11 09:00:15 +0800120 {
Yong Liecd7bb92019-10-29 13:24:40 +0800121 return ipmi::responseInvalidFieldRequest();
Jia, Chunhui30206db2018-12-11 09:00:15 +0800122 }
Yong Liecd7bb92019-10-29 13:24:40 +0800123
124 return ipmi::responseSuccess();
Tom9e5232e2016-11-07 12:14:51 +0530125}
126
Patrick Venture0b02be92018-08-31 11:55:55 -0700127namespace
128{
Lei YU12c2db72017-05-15 11:24:04 +0800129// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530130std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700131 __attribute__((init_priority(101)));
Patrick Williams5d82f472022-07-22 19:26:53 -0500132std::unique_ptr<sdbusplus::server::manager_t> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700133 __attribute__((init_priority(101)));
134} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500135
Tom9e5232e2016-11-07 12:14:51 +0530136void register_netfn_app_functions()
137{
138
139 // <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}