blob: fb5dde508eebad7a09301171bbb91a70d6b1f377 [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>
Tom9e5232e2016-11-07 12:14:51 +053011
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050012#include <cstring>
Vernon Mauerye4aa6542023-11-01 14:29:21 -070013#include <fstream>
Patrick Williamsfbc6c9d2023-05-10 07:50:16 -050014
Tom9e5232e2016-11-07 12:14:51 +053015void register_netfn_app_functions() __attribute__((constructor));
16
Willy Tu523e2d12023-09-05 11:36:48 -070017using namespace sdbusplus::server::xyz::openbmc_project::control;
Andrew Geissler12866372017-03-21 22:58:28 -050018
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053019// For accessing Host command manager
20using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>;
21extern cmdManagerPtr& ipmid_get_host_cmd_manager();
Andrew Geissler12866372017-03-21 22:58:28 -050022
Andrew Geissler12866372017-03-21 22:58:28 -050023//-------------------------------------------------------------------
24// Called by Host post response from Get_Message_Flags
25//-------------------------------------------------------------------
Vernon Mauerye4aa6542023-11-01 14:29:21 -070026ipmi::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 Geissler12866372017-03-21 22:58:28 -050035{
Vernon Mauerye4aa6542023-11-01 14:29:21 -070036 // require this to be limited to system interface
37 if (ctx->channel != ipmi::channelSystemIface)
38 {
39 return ipmi::responseInvalidCommand();
40 }
Andrew Geissler12866372017-03-21 22:58:28 -050041
Vernon Mauerye4aa6542023-11-01 14:29:21 -070042 constexpr uint16_t selOemId = 0x5555;
43 constexpr uint8_t selRecordTypeOem = 0xc0;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053044
Vernon Mauerye4aa6542023-11-01 14:29:21 -070045 // 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 }
Tom9e5232e2016-11-07 12:14:51 +053060
Vernon Mauerye4aa6542023-11-01 14:29:21 -070061 constexpr uint32_t timestamp{0};
Tom9e5232e2016-11-07 12:14:51 +053062
63 // per IPMI spec NetFuntion for OEM
Vernon Mauerye4aa6542023-11-01 14:29:21 -070064 constexpr uint8_t netfun = 0x3a;
Tom9e5232e2016-11-07 12:14:51 +053065
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053066 // Read from the Command Manager queue. What gets returned is a
67 // pair of <command, data> that can be directly used here
Vernon Mauerye4aa6542023-11-01 14:29:21 -070068 const auto& [cmd, data0] = ipmid_get_host_cmd_manager()->getNextCommand();
69 constexpr uint8_t dataUnused = 0xff;
Tom9e5232e2016-11-07 12:14:51 +053070
Vernon Mauerye4aa6542023-11-01 14:29:21 -070071 return ipmi::responseSuccess(
72 selOemId, selRecordTypeOem, manufId, timestamp, netfun, cmd,
73 std::to_array<uint8_t>({data0, dataUnused, dataUnused, dataUnused}));
Tom9e5232e2016-11-07 12:14:51 +053074}
75
76//---------------------------------------------------------------------
77// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
XP Chen414d2f72021-09-20 16:19:11 -050078// value of 0x0 to indicate Event Message Buffer is not supported
Tom9e5232e2016-11-07 12:14:51 +053079//-------------------------------------------------------------------
Andrew Geissler461f4642019-04-22 10:34:34 -050080ipmi::RspType<uint8_t> ipmiAppGetMessageFlags()
Tom9e5232e2016-11-07 12:14:51 +053081{
Tom9e5232e2016-11-07 12:14:51 +053082 // 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 Geissler461f4642019-04-22 10:34:34 -050086 // This path is used to communicate messages to the host
87 // from within the phosphor::host::command::Manager
XP Chen414d2f72021-09-20 16:19:11 -050088 constexpr uint8_t setEventMsgBufferNotSupported = 0x0;
89 return ipmi::responseSuccess(setEventMsgBufferNotSupported);
Tom9e5232e2016-11-07 12:14:51 +053090}
91
Yong Li5aa26932019-11-04 13:25:43 +080092ipmi::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, Chunhui30206db2018-12-11 09:00:15 +0800102{
Yong Li5aa26932019-11-04 13:25:43 +0800103 return ipmi::responseSuccess(true, false, false, true, 0, false, false,
104 false);
Jia, Chunhui30206db2018-12-11 09:00:15 +0800105}
106
Yong Liecd7bb92019-10-29 13:24:40 +0800107ipmi::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)
Tom9e5232e2016-11-07 12:14:51 +0530112{
Yong Lia249a082019-10-29 13:37:17 +0800113 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, Chunhui30206db2018-12-11 09:00:15 +0800131 // 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 Liecd7bb92019-10-29 13:24:40 +0800134 if (!receiveMessageQueueInterruptEnabled || !systemEventLogEnable ||
135 eventMessageBufferFullInterruptEnabled || eventMessageBufferEnabled ||
136 OEM0Enabled || OEM1Enabled || OEM2Enabled || reserved)
Jia, Chunhui30206db2018-12-11 09:00:15 +0800137 {
Yong Liecd7bb92019-10-29 13:24:40 +0800138 return ipmi::responseInvalidFieldRequest();
Jia, Chunhui30206db2018-12-11 09:00:15 +0800139 }
Yong Liecd7bb92019-10-29 13:24:40 +0800140
141 return ipmi::responseSuccess();
Tom9e5232e2016-11-07 12:14:51 +0530142}
143
Patrick Venture0b02be92018-08-31 11:55:55 -0700144namespace
145{
Lei YU12c2db72017-05-15 11:24:04 +0800146// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530147std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700148 __attribute__((init_priority(101)));
Patrick Williams5d82f472022-07-22 19:26:53 -0500149std::unique_ptr<sdbusplus::server::manager_t> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700150 __attribute__((init_priority(101)));
151} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500152
Tom9e5232e2016-11-07 12:14:51 +0530153void register_netfn_app_functions()
154{
Tom9e5232e2016-11-07 12:14:51 +0530155 // <Read Event Message Buffer>
Vernon Mauerye4aa6542023-11-01 14:29:21 -0700156 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
157 ipmi::app::cmdReadEventMessageBuffer,
158 ipmi::Privilege::Admin, ipmiAppReadEventBuffer);
Tom9e5232e2016-11-07 12:14:51 +0530159
160 // <Set BMC Global Enables>
Yong Liecd7bb92019-10-29 13:24:40 +0800161 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
162 ipmi::app::cmdSetBmcGlobalEnables,
163 ipmi::Privilege::Admin, ipmiAppSetBMCGlobalEnable);
Tom9e5232e2016-11-07 12:14:51 +0530164
Jia, Chunhui30206db2018-12-11 09:00:15 +0800165 // <Get BMC Global Enables>
Yong Li5aa26932019-11-04 13:25:43 +0800166 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
167 ipmi::app::cmdGetBmcGlobalEnables,
168 ipmi::Privilege::User, ipmiAppGetBMCGlobalEnable);
Jia, Chunhui30206db2018-12-11 09:00:15 +0800169
Tom9e5232e2016-11-07 12:14:51 +0530170 // <Get Message Flags>
Andrew Geissler461f4642019-04-22 10:34:34 -0500171 ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnApp,
172 ipmi::app::cmdGetMessageFlags, ipmi::Privilege::Admin,
173 ipmiAppGetMessageFlags);
Tom9e5232e2016-11-07 12:14:51 +0530174
Andrew Geissler12866372017-03-21 22:58:28 -0500175 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530176 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500177
Vernon Mauery20ff3332019-03-01 16:52:25 -0800178 std::unique_ptr<sdbusplus::asio::connection>& sdbusp =
179 ipmid_get_sdbus_plus_handler();
Andrew Geissler12866372017-03-21 22:58:28 -0500180
Vernon Mauery240b1862018-10-08 12:05:16 -0700181 // Add sdbusplus ObjectManager.
Patrick Williams5d82f472022-07-22 19:26:53 -0500182 objManager = std::make_unique<sdbusplus::server::manager_t>(
Vernon Mauery240b1862018-10-08 12:05:16 -0700183 *sdbusp, CONTROL_HOST_OBJ_MGR);
184
185 host = std::make_unique<phosphor::host::command::Host>(*sdbusp,
Patrick Venture0b02be92018-08-31 11:55:55 -0700186 objPath.c_str());
Vernon Mauery240b1862018-10-08 12:05:16 -0700187 sdbusp->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500188
Tom9e5232e2016-11-07 12:14:51 +0530189 return;
190}