blob: d298abd6b322a87e28383a61dba9d26929a144b3 [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
Jia, Chunhui30206db2018-12-11 09:00:15 +080020// global enables
21// bit0 - Message Receive Queue enable
22// bit1 - Enable Event Message Buffer Full Interrupt
23// bit2 - Enable Event Message Buffer
24// bit3 - Enable System Event Logging
25// bit4 - reserved
26// bit5-7 - OEM 0~2 enables
27static constexpr uint8_t selEnable = 0x08;
28static constexpr uint8_t recvMsgQueueEnable = 0x01;
29static constexpr uint8_t globalEnablesDefault = selEnable | recvMsgQueueEnable;
30
Andrew Geissler12866372017-03-21 22:58:28 -050031//-------------------------------------------------------------------
32// Called by Host post response from Get_Message_Flags
33//-------------------------------------------------------------------
34ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070035 ipmi_request_t request, ipmi_response_t response,
36 ipmi_data_len_t data_len, ipmi_context_t context)
Andrew Geissler12866372017-03-21 22:58:28 -050037{
38 ipmi_ret_t rc = IPMI_CC_OK;
39
Andrew Geissler12866372017-03-21 22:58:28 -050040 struct oem_sel_timestamped oem_sel = {0};
41 *data_len = sizeof(struct oem_sel_timestamped);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053042
Tom9e5232e2016-11-07 12:14:51 +053043 // either id[0] -or- id[1] can be filled in. We will use id[0]
Patrick Venture0b02be92018-08-31 11:55:55 -070044 oem_sel.id[0] = SEL_OEM_ID_0;
45 oem_sel.id[1] = SEL_OEM_ID_0;
46 oem_sel.type = SEL_RECORD_TYPE_OEM;
Tom9e5232e2016-11-07 12:14:51 +053047
48 // Following 3 bytes are from IANA Manufactre_Id field. See below
Patrick Venture0b02be92018-08-31 11:55:55 -070049 oem_sel.manuf_id[0] = 0x41;
50 oem_sel.manuf_id[1] = 0xA7;
51 oem_sel.manuf_id[2] = 0x00;
Tom9e5232e2016-11-07 12:14:51 +053052
53 // per IPMI spec NetFuntion for OEM
Patrick Venture0b02be92018-08-31 11:55:55 -070054 oem_sel.netfun = 0x3A;
Tom9e5232e2016-11-07 12:14:51 +053055
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053056 // Read from the Command Manager queue. What gets returned is a
57 // pair of <command, data> that can be directly used here
Patrick Venture0b02be92018-08-31 11:55:55 -070058 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand();
59 oem_sel.cmd = hostCmd.first;
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053060 oem_sel.data[0] = hostCmd.second;
Tom9e5232e2016-11-07 12:14:51 +053061
62 // All '0xFF' since unused.
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070063 std::memset(&oem_sel.data[1], 0xFF, 3);
Tom9e5232e2016-11-07 12:14:51 +053064
65 // Pack the actual response
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070066 std::memcpy(response, &oem_sel, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053067 return rc;
68}
69
70//---------------------------------------------------------------------
71// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
72// value of 0x2 indicating we need Host read some data.
73//-------------------------------------------------------------------
74ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070075 ipmi_request_t request,
76 ipmi_response_t response,
77 ipmi_data_len_t data_len,
78 ipmi_context_t context)
Tom9e5232e2016-11-07 12:14:51 +053079{
80 // Generic return from IPMI commands.
81 ipmi_ret_t rc = IPMI_CC_OK;
82
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.
Jia, Chunhui30206db2018-12-11 09:00:15 +080087 // For now, it is not supported.
Tom9e5232e2016-11-07 12:14:51 +053088
Jia, Chunhui30206db2018-12-11 09:00:15 +080089 uint8_t set_event_msg_buffer_full = 0x0;
Tom9e5232e2016-11-07 12:14:51 +053090 *data_len = sizeof(set_event_msg_buffer_full);
91
92 // Pack the actual response
Patrick Ventureb51bf9c2018-09-10 15:53:14 -070093 std::memcpy(response, &set_event_msg_buffer_full, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053094
95 return rc;
96}
97
Jia, Chunhui30206db2018-12-11 09:00:15 +080098ipmi_ret_t ipmi_app_get_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
99 ipmi_request_t request,
100 ipmi_response_t response,
101 ipmi_data_len_t data_len,
102 ipmi_context_t context)
103{
104 ipmi_ret_t rc = IPMI_CC_OK;
105 if (0 != *data_len)
106 {
107 *data_len = 0;
108 return IPMI_CC_REQ_DATA_LEN_INVALID;
109 }
110 *data_len = sizeof(globalEnablesDefault);
111 *reinterpret_cast<uint8_t*>(response) = globalEnablesDefault;
112 return rc;
113}
114
Tom9e5232e2016-11-07 12:14:51 +0530115ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -0700116 ipmi_request_t request,
117 ipmi_response_t response,
118 ipmi_data_len_t data_len,
119 ipmi_context_t context)
Tom9e5232e2016-11-07 12:14:51 +0530120{
121 ipmi_ret_t rc = IPMI_CC_OK;
Jia, Chunhui30206db2018-12-11 09:00:15 +0800122
123 uint8_t reqMask = *reinterpret_cast<uint8_t*>(request);
124 if (sizeof(reqMask) != *data_len)
125 {
126 *data_len = 0;
127 return IPMI_CC_REQ_DATA_LEN_INVALID;
128 }
129
Tom9e5232e2016-11-07 12:14:51 +0530130 *data_len = 0;
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
134 if (reqMask != (selEnable | recvMsgQueueEnable))
135 {
136 return IPMI_CC_INVALID_FIELD_REQUEST;
137 }
Tom9e5232e2016-11-07 12:14:51 +0530138 return rc;
139}
140
Patrick Venture0b02be92018-08-31 11:55:55 -0700141namespace
142{
Lei YU12c2db72017-05-15 11:24:04 +0800143// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530144std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700145 __attribute__((init_priority(101)));
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530146std::unique_ptr<sdbusplus::server::manager::manager> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700147 __attribute__((init_priority(101)));
148} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500149
Tom9e5232e2016-11-07 12:14:51 +0530150void register_netfn_app_functions()
151{
152
153 // <Read Event Message Buffer>
Patrick Venture0b02be92018-08-31 11:55:55 -0700154 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL,
155 ipmi_app_read_event, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530156
157 // <Set BMC Global Enables>
Tom9e5232e2016-11-07 12:14:51 +0530158 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
Tom05732372016-09-06 17:21:23 +0530159 ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530160
Jia, Chunhui30206db2018-12-11 09:00:15 +0800161 // <Get BMC Global Enables>
162 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_BMC_GLOBAL_ENABLES, NULL,
163 ipmi_app_get_bmc_global_enables, SYSTEM_INTERFACE);
164
Tom9e5232e2016-11-07 12:14:51 +0530165 // <Get Message Flags>
Patrick Venture0b02be92018-08-31 11:55:55 -0700166 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL,
167 ipmi_app_get_msg_flags, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530168
Andrew Geissler12866372017-03-21 22:58:28 -0500169 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530170 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500171
Vernon Mauery20ff3332019-03-01 16:52:25 -0800172 std::unique_ptr<sdbusplus::asio::connection>& sdbusp =
173 ipmid_get_sdbus_plus_handler();
Andrew Geissler12866372017-03-21 22:58:28 -0500174
Vernon Mauery240b1862018-10-08 12:05:16 -0700175 // Add sdbusplus ObjectManager.
176 objManager = std::make_unique<sdbusplus::server::manager::manager>(
177 *sdbusp, CONTROL_HOST_OBJ_MGR);
178
179 host = std::make_unique<phosphor::host::command::Host>(*sdbusp,
Patrick Venture0b02be92018-08-31 11:55:55 -0700180 objPath.c_str());
Vernon Mauery240b1862018-10-08 12:05:16 -0700181 sdbusp->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500182
Tom9e5232e2016-11-07 12:14:51 +0530183 return;
184}