blob: 00e6c51caac278a30fa8da5c23af980d00e33d94 [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>
11#include <ipmid/registration.hpp>
Tom9e5232e2016-11-07 12:14:51 +053012
13void 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
Jia, Chunhui30206db2018-12-11 09:00:15 +080021// global enables
22// bit0 - Message Receive Queue enable
23// bit1 - Enable Event Message Buffer Full Interrupt
24// bit2 - Enable Event Message Buffer
25// bit3 - Enable System Event Logging
26// bit4 - reserved
27// bit5-7 - OEM 0~2 enables
28static constexpr uint8_t selEnable = 0x08;
29static constexpr uint8_t recvMsgQueueEnable = 0x01;
30static constexpr uint8_t globalEnablesDefault = selEnable | recvMsgQueueEnable;
31
Andrew Geissler12866372017-03-21 22:58:28 -050032//-------------------------------------------------------------------
33// Called by Host post response from Get_Message_Flags
34//-------------------------------------------------------------------
35ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070036 ipmi_request_t request, ipmi_response_t response,
37 ipmi_data_len_t data_len, ipmi_context_t context)
Andrew Geissler12866372017-03-21 22:58:28 -050038{
39 ipmi_ret_t rc = IPMI_CC_OK;
40
Andrew Geissler12866372017-03-21 22:58:28 -050041 struct oem_sel_timestamped oem_sel = {0};
42 *data_len = sizeof(struct oem_sel_timestamped);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053043
Tom9e5232e2016-11-07 12:14:51 +053044 // either id[0] -or- id[1] can be filled in. We will use id[0]
Patrick Venture0b02be92018-08-31 11:55:55 -070045 oem_sel.id[0] = SEL_OEM_ID_0;
46 oem_sel.id[1] = SEL_OEM_ID_0;
47 oem_sel.type = SEL_RECORD_TYPE_OEM;
Tom9e5232e2016-11-07 12:14:51 +053048
49 // Following 3 bytes are from IANA Manufactre_Id field. See below
Patrick Venture0b02be92018-08-31 11:55:55 -070050 oem_sel.manuf_id[0] = 0x41;
51 oem_sel.manuf_id[1] = 0xA7;
52 oem_sel.manuf_id[2] = 0x00;
Tom9e5232e2016-11-07 12:14:51 +053053
54 // per IPMI spec NetFuntion for OEM
Patrick Venture0b02be92018-08-31 11:55:55 -070055 oem_sel.netfun = 0x3A;
Tom9e5232e2016-11-07 12:14:51 +053056
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053057 // Read from the Command Manager queue. What gets returned is a
58 // pair of <command, data> that can be directly used here
Patrick Venture0b02be92018-08-31 11:55:55 -070059 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand();
60 oem_sel.cmd = hostCmd.first;
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053061 oem_sel.data[0] = hostCmd.second;
Tom9e5232e2016-11-07 12:14:51 +053062
63 // All '0xFF' since unused.
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070064 std::memset(&oem_sel.data[1], 0xFF, 3);
Tom9e5232e2016-11-07 12:14:51 +053065
66 // Pack the actual response
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070067 std::memcpy(response, &oem_sel, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053068 return rc;
69}
70
71//---------------------------------------------------------------------
72// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
73// value of 0x2 indicating we need Host read some data.
74//-------------------------------------------------------------------
75ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070076 ipmi_request_t request,
77 ipmi_response_t response,
78 ipmi_data_len_t data_len,
79 ipmi_context_t context)
Tom9e5232e2016-11-07 12:14:51 +053080{
81 // Generic return from IPMI commands.
82 ipmi_ret_t rc = IPMI_CC_OK;
83
Tom9e5232e2016-11-07 12:14:51 +053084 // From IPMI spec V2.0 for Get Message Flags Command :
85 // bit:[1] from LSB : 1b = Event Message Buffer Full.
86 // Return as 0 if Event Message Buffer is not supported,
87 // or when the Event Message buffer is disabled.
Jia, Chunhui30206db2018-12-11 09:00:15 +080088 // For now, it is not supported.
Tom9e5232e2016-11-07 12:14:51 +053089
Jia, Chunhui30206db2018-12-11 09:00:15 +080090 uint8_t set_event_msg_buffer_full = 0x0;
Tom9e5232e2016-11-07 12:14:51 +053091 *data_len = sizeof(set_event_msg_buffer_full);
92
93 // Pack the actual response
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070094 std::memcpy(response, &set_event_msg_buffer_full, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053095
96 return rc;
97}
98
Jia, Chunhui30206db2018-12-11 09:00:15 +080099ipmi_ret_t ipmi_app_get_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
100 ipmi_request_t request,
101 ipmi_response_t response,
102 ipmi_data_len_t data_len,
103 ipmi_context_t context)
104{
105 ipmi_ret_t rc = IPMI_CC_OK;
106 if (0 != *data_len)
107 {
108 *data_len = 0;
109 return IPMI_CC_REQ_DATA_LEN_INVALID;
110 }
111 *data_len = sizeof(globalEnablesDefault);
112 *reinterpret_cast<uint8_t*>(response) = globalEnablesDefault;
113 return rc;
114}
115
Tom9e5232e2016-11-07 12:14:51 +0530116ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -0700117 ipmi_request_t request,
118 ipmi_response_t response,
119 ipmi_data_len_t data_len,
120 ipmi_context_t context)
Tom9e5232e2016-11-07 12:14:51 +0530121{
122 ipmi_ret_t rc = IPMI_CC_OK;
Jia, Chunhui30206db2018-12-11 09:00:15 +0800123
124 uint8_t reqMask = *reinterpret_cast<uint8_t*>(request);
125 if (sizeof(reqMask) != *data_len)
126 {
127 *data_len = 0;
128 return IPMI_CC_REQ_DATA_LEN_INVALID;
129 }
130
Tom9e5232e2016-11-07 12:14:51 +0530131 *data_len = 0;
Jia, Chunhui30206db2018-12-11 09:00:15 +0800132 // Recv Message Queue and SEL are enabled by default.
133 // Event Message buffer are disabled by default (not supported).
134 // Any request that try to change the mask will be rejected
135 if (reqMask != (selEnable | recvMsgQueueEnable))
136 {
137 return IPMI_CC_INVALID_FIELD_REQUEST;
138 }
Tom9e5232e2016-11-07 12:14:51 +0530139 return rc;
140}
141
Patrick Venture0b02be92018-08-31 11:55:55 -0700142namespace
143{
Lei YU12c2db72017-05-15 11:24:04 +0800144// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530145std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700146 __attribute__((init_priority(101)));
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530147std::unique_ptr<sdbusplus::server::manager::manager> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700148 __attribute__((init_priority(101)));
Vernon Mauery240b1862018-10-08 12:05:16 -0700149std::unique_ptr<sdbusplus::asio::connection> sdbusp
150 __attribute__((init_priority(101)));
Patrick Venture0b02be92018-08-31 11:55:55 -0700151} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500152
Vernon Maueryfe6c6552019-02-27 10:05:14 -0800153// this is used by openpower-host-ipmi-oem
154std::unique_ptr<sdbusplus::asio::connection>& ipmid_get_sdbus_plus_handler()
155{
156 return sdbusp;
157}
158
Andrew Geissler12866372017-03-21 22:58:28 -0500159#include <unistd.h>
Tom9e5232e2016-11-07 12:14:51 +0530160void register_netfn_app_functions()
161{
162
163 // <Read Event Message Buffer>
Patrick Venture0b02be92018-08-31 11:55:55 -0700164 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL,
165 ipmi_app_read_event, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530166
167 // <Set BMC Global Enables>
Tom9e5232e2016-11-07 12:14:51 +0530168 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
Tom05732372016-09-06 17:21:23 +0530169 ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530170
Jia, Chunhui30206db2018-12-11 09:00:15 +0800171 // <Get BMC Global Enables>
172 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_BMC_GLOBAL_ENABLES, NULL,
173 ipmi_app_get_bmc_global_enables, SYSTEM_INTERFACE);
174
Tom9e5232e2016-11-07 12:14:51 +0530175 // <Get Message Flags>
Patrick Venture0b02be92018-08-31 11:55:55 -0700176 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL,
177 ipmi_app_get_msg_flags, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530178
Andrew Geissler12866372017-03-21 22:58:28 -0500179 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530180 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500181
Vernon Mauery240b1862018-10-08 12:05:16 -0700182 // Create a new sdbus connection so it can have a well-known name
183 sd_bus* bus = nullptr;
184 sd_bus_open_system(&bus);
185 if (!bus)
186 {
187 return;
188 }
189 auto io = getIoService();
190 sdbusp = std::make_unique<sdbusplus::asio::connection>(*io, bus);
Andrew Geissler12866372017-03-21 22:58:28 -0500191
Vernon Mauery240b1862018-10-08 12:05:16 -0700192 // Add sdbusplus ObjectManager.
193 objManager = std::make_unique<sdbusplus::server::manager::manager>(
194 *sdbusp, CONTROL_HOST_OBJ_MGR);
195
196 host = std::make_unique<phosphor::host::command::Host>(*sdbusp,
Patrick Venture0b02be92018-08-31 11:55:55 -0700197 objPath.c_str());
Vernon Mauery240b1862018-10-08 12:05:16 -0700198 sdbusp->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500199
Tom9e5232e2016-11-07 12:14:51 +0530200 return;
201}