blob: 39ed3231648545c7d2fedaa56b204ac2127b31af [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>
Vernon Mauerye4aa6542023-11-01 14:29:21 -070010#include <nlohmann/json.hpp>
George Liu9cd6d9a2024-07-19 09:28:56 +080011#include <phosphor-logging/lg2.hpp>
Tom9e5232e2016-11-07 12:14:51 +053012
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050013#include <cstring>
Vernon Mauerye4aa6542023-11-01 14:29:21 -070014#include <fstream>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050015
Tom9e5232e2016-11-07 12:14:51 +053016void register_netfn_app_functions() __attribute__((constructor));
17
Willy Tu523e2d12023-09-05 11:36:48 -070018using namespace sdbusplus::server::xyz::openbmc_project::control;
Andrew Geissler12866372017-03-21 22:58:28 -050019
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053020// For accessing Host command manager
21using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>;
22extern cmdManagerPtr& ipmid_get_host_cmd_manager();
Andrew Geissler12866372017-03-21 22:58:28 -050023
Andrew Geissler12866372017-03-21 22:58:28 -050024//-------------------------------------------------------------------
25// Called by Host post response from Get_Message_Flags
26//-------------------------------------------------------------------
Vernon Mauerye4aa6542023-11-01 14:29:21 -070027ipmi::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 Geissler12866372017-03-21 22:58:28 -050036{
Vernon Mauerye4aa6542023-11-01 14:29:21 -070037 // require this to be limited to system interface
38 if (ctx->channel != ipmi::channelSystemIface)
39 {
40 return ipmi::responseInvalidCommand();
41 }
Andrew Geissler12866372017-03-21 22:58:28 -050042
Vernon Mauerye4aa6542023-11-01 14:29:21 -070043 constexpr uint16_t selOemId = 0x5555;
44 constexpr uint8_t selRecordTypeOem = 0xc0;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053045
Vernon Mauerye4aa6542023-11-01 14:29:21 -070046 // 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 }
Tom9e5232e2016-11-07 12:14:51 +053061
Vernon Mauerye4aa6542023-11-01 14:29:21 -070062 constexpr uint32_t timestamp{0};
Tom9e5232e2016-11-07 12:14:51 +053063
64 // per IPMI spec NetFuntion for OEM
Vernon Mauerye4aa6542023-11-01 14:29:21 -070065 constexpr uint8_t netfun = 0x3a;
Tom9e5232e2016-11-07 12:14:51 +053066
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053067 // Read from the Command Manager queue. What gets returned is a
68 // pair of <command, data> that can be directly used here
Vernon Mauerye4aa6542023-11-01 14:29:21 -070069 const auto& [cmd, data0] = ipmid_get_host_cmd_manager()->getNextCommand();
70 constexpr uint8_t dataUnused = 0xff;
Tom9e5232e2016-11-07 12:14:51 +053071
Vernon Mauerye4aa6542023-11-01 14:29:21 -070072 return ipmi::responseSuccess(
73 selOemId, selRecordTypeOem, manufId, timestamp, netfun, cmd,
74 std::to_array<uint8_t>({data0, dataUnused, dataUnused, dataUnused}));
Tom9e5232e2016-11-07 12:14:51 +053075}
76
77//---------------------------------------------------------------------
78// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
XP Chen414d2f72021-09-20 16:19:11 -050079// value of 0x0 to indicate Event Message Buffer is not supported
Tom9e5232e2016-11-07 12:14:51 +053080//-------------------------------------------------------------------
Andrew Geissler461f4642019-04-22 10:34:34 -050081ipmi::RspType<uint8_t> ipmiAppGetMessageFlags()
Tom9e5232e2016-11-07 12:14:51 +053082{
Tom9e5232e2016-11-07 12:14:51 +053083 // 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 Geissler461f4642019-04-22 10:34:34 -050087 // This path is used to communicate messages to the host
88 // from within the phosphor::host::command::Manager
XP Chen414d2f72021-09-20 16:19:11 -050089 constexpr uint8_t setEventMsgBufferNotSupported = 0x0;
90 return ipmi::responseSuccess(setEventMsgBufferNotSupported);
Tom9e5232e2016-11-07 12:14:51 +053091}
92
Yong Li5aa26932019-11-04 13:25:43 +080093ipmi::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, Chunhui30206db2018-12-11 09:00:15 +0800103{
Yong Li5aa26932019-11-04 13:25:43 +0800104 return ipmi::responseSuccess(true, false, false, true, 0, false, false,
105 false);
Jia, Chunhui30206db2018-12-11 09:00:15 +0800106}
107
Yong Liecd7bb92019-10-29 13:24:40 +0800108ipmi::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)
Tom9e5232e2016-11-07 12:14:51 +0530113{
Yong Lia249a082019-10-29 13:37:17 +0800114 ipmi::ChannelInfo chInfo;
115
116 if (ipmi::getChannelInfo(ctx->channel, chInfo) != ipmi::ccSuccess)
117 {
George Liu9cd6d9a2024-07-19 09:28:56 +0800118 lg2::error("Failed to get Channel Info, channel={CHANNEL}", "CHANNEL",
119 ctx->channel);
Yong Lia249a082019-10-29 13:37:17 +0800120 return ipmi::responseUnspecifiedError();
121 }
122
123 if (chInfo.mediumType !=
124 static_cast<uint8_t>(ipmi::EChannelMediumType::systemInterface))
125 {
George Liu9cd6d9a2024-07-19 09:28:56 +0800126 lg2::error("Error - supported only in system interface");
Yong Lia249a082019-10-29 13:37:17 +0800127 return ipmi::responseCommandNotAvailable();
128 }
129
Jia, Chunhui30206db2018-12-11 09:00:15 +0800130 // 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 Liecd7bb92019-10-29 13:24:40 +0800133 if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable ||
134 eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled ||
135 OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved)
Jia, Chunhui30206db2018-12-11 09:00:15 +0800136 {
Yong Liecd7bb92019-10-29 13:24:40 +0800137 return ipmi::responseInvalidFieldRequest();
Jia, Chunhui30206db2018-12-11 09:00:15 +0800138 }
Yong Liecd7bb92019-10-29 13:24:40 +0800139
140 return ipmi::responseSuccess();
Tom9e5232e2016-11-07 12:14:51 +0530141}
142
Patrick Venture0b02be92018-08-31 11:55:55 -0700143namespace
144{
Lei YU12c2db72017-05-15 11:24:04 +0800145// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530146std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700147 __attribute__((init_priority(101)));
Patrick Williams5d82f472022-07-22 19:26:53 -0500148std::unique_ptr<sdbusplus::server::manager_t> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700149 __attribute__((init_priority(101)));
150} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500151
Tom9e5232e2016-11-07 12:14:51 +0530152void register_netfn_app_functions()
153{
Tom9e5232e2016-11-07 12:14:51 +0530154 // <Read Event Message Buffer>
Vernon Mauerye4aa6542023-11-01 14:29:21 -0700155 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
156 ipmi::app::cmdReadEventMessageBuffer,
157 ipmi::Privilege::Admin, ipmiAppReadEventBuffer);
Tom9e5232e2016-11-07 12:14:51 +0530158
159 // <Set BMC Global Enables>
Yong Liecd7bb92019-10-29 13:24:40 +0800160 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
161 ipmi::app::cmdSetBmcGlobalEnables,
162 ipmi::Privilege::Admin, ipmiAppSetBMCGlobalEnable);
Tom9e5232e2016-11-07 12:14:51 +0530163
Jia, Chunhui30206db2018-12-11 09:00:15 +0800164 // <Get BMC Global Enables>
Yong Li5aa26932019-11-04 13:25:43 +0800165 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
166 ipmi::app::cmdGetBmcGlobalEnables,
167 ipmi::Privilege::User, ipmiAppGetBMCGlobalEnable);
Jia, Chunhui30206db2018-12-11 09:00:15 +0800168
Tom9e5232e2016-11-07 12:14:51 +0530169 // <Get Message Flags>
Andrew Geissler461f4642019-04-22 10:34:34 -0500170 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
171 ipmi::app::cmdGetMessageFlags, ipmi::Privilege::Admin,
172 ipmiAppGetMessageFlags);
Tom9e5232e2016-11-07 12:14:51 +0530173
Andrew Geissler12866372017-03-21 22:58:28 -0500174 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530175 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500176
Vernon Mauery20ff3332019-03-01 16:52:25 -0800177 std::unique_ptr<sdbusplus::asio::connection>& sdbusp =
178 ipmid_get_sdbus_plus_handler();
Andrew Geissler12866372017-03-21 22:58:28 -0500179
Vernon Mauery240b1862018-10-08 12:05:16 -0700180 // Add sdbusplus ObjectManager.
Patrick Williams5d82f472022-07-22 19:26:53 -0500181 objManager = std::make_unique<sdbusplus::server::manager_t>(
Vernon Mauery240b1862018-10-08 12:05:16 -0700182 *sdbusp, CONTROL_HOST_OBJ_MGR);
183
184 host = std::make_unique<phosphor::host::command::Host>(*sdbusp,
Patrick Venture0b02be92018-08-31 11:55:55 -0700185 objPath.c_str());
Vernon Mauery240b1862018-10-08 12:05:16 -0700186 sdbusp->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500187
Tom9e5232e2016-11-07 12:14:51 +0530188 return;
189}