blob: c39a7aff8c35c9fc6e9dba05fcd9ff4eb5300ed6 [file] [log] [blame]
Vishwanatha Subbannab891a572017-03-31 11:34:48 +05301#include "config.h"
Patrick Venture0b02be92018-08-31 11:55:55 -07002
3#include "systemintfcmds.h"
4
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"
Patrick Venture0b02be92018-08-31 11:55:55 -07007#include "host-ipmid/ipmid-host-cmd.hpp"
Tom9e5232e2016-11-07 12:14:51 +05308
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05309#include <mapper.h>
Patrick Venture0b02be92018-08-31 11:55:55 -070010#include <stdio.h>
11
12#include "host-ipmid/ipmid-api.h"
Tom9e5232e2016-11-07 12:14:51 +053013
14void register_netfn_app_functions() __attribute__((constructor));
15
Andrew Geissler12866372017-03-21 22:58:28 -050016using namespace sdbusplus::xyz::openbmc_project::Control::server;
17
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053018// For accessing Host command manager
19using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>;
20extern cmdManagerPtr& ipmid_get_host_cmd_manager();
Andrew Geissler12866372017-03-21 22:58:28 -050021
Andrew Geissler12866372017-03-21 22:58:28 -050022//-------------------------------------------------------------------
23// Called by Host post response from Get_Message_Flags
24//-------------------------------------------------------------------
25ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070026 ipmi_request_t request, ipmi_response_t response,
27 ipmi_data_len_t data_len, ipmi_context_t context)
Andrew Geissler12866372017-03-21 22:58:28 -050028{
29 ipmi_ret_t rc = IPMI_CC_OK;
30
Andrew Geissler12866372017-03-21 22:58:28 -050031 struct oem_sel_timestamped oem_sel = {0};
32 *data_len = sizeof(struct oem_sel_timestamped);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053033
Tom9e5232e2016-11-07 12:14:51 +053034 // either id[0] -or- id[1] can be filled in. We will use id[0]
Patrick Venture0b02be92018-08-31 11:55:55 -070035 oem_sel.id[0] = SEL_OEM_ID_0;
36 oem_sel.id[1] = SEL_OEM_ID_0;
37 oem_sel.type = SEL_RECORD_TYPE_OEM;
Tom9e5232e2016-11-07 12:14:51 +053038
39 // Following 3 bytes are from IANA Manufactre_Id field. See below
Patrick Venture0b02be92018-08-31 11:55:55 -070040 oem_sel.manuf_id[0] = 0x41;
41 oem_sel.manuf_id[1] = 0xA7;
42 oem_sel.manuf_id[2] = 0x00;
Tom9e5232e2016-11-07 12:14:51 +053043
44 // per IPMI spec NetFuntion for OEM
Patrick Venture0b02be92018-08-31 11:55:55 -070045 oem_sel.netfun = 0x3A;
Tom9e5232e2016-11-07 12:14:51 +053046
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053047 // Read from the Command Manager queue. What gets returned is a
48 // pair of <command, data> that can be directly used here
Patrick Venture0b02be92018-08-31 11:55:55 -070049 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand();
50 oem_sel.cmd = hostCmd.first;
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053051 oem_sel.data[0] = hostCmd.second;
Tom9e5232e2016-11-07 12:14:51 +053052
53 // All '0xFF' since unused.
Andrew Geissler12866372017-03-21 22:58:28 -050054 memset(&oem_sel.data[1], 0xFF, 3);
Tom9e5232e2016-11-07 12:14:51 +053055
56 // Pack the actual response
Andrew Geissler12866372017-03-21 22:58:28 -050057 memcpy(response, &oem_sel, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053058 return rc;
59}
60
61//---------------------------------------------------------------------
62// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
63// value of 0x2 indicating we need Host read some data.
64//-------------------------------------------------------------------
65ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070066 ipmi_request_t request,
67 ipmi_response_t response,
68 ipmi_data_len_t data_len,
69 ipmi_context_t context)
Tom9e5232e2016-11-07 12:14:51 +053070{
71 // Generic return from IPMI commands.
72 ipmi_ret_t rc = IPMI_CC_OK;
73
Tom9e5232e2016-11-07 12:14:51 +053074 // From IPMI spec V2.0 for Get Message Flags Command :
75 // bit:[1] from LSB : 1b = Event Message Buffer Full.
76 // Return as 0 if Event Message Buffer is not supported,
77 // or when the Event Message buffer is disabled.
78 // TODO. For now. assume its not disabled and send "0x2" anyway:
79
80 uint8_t set_event_msg_buffer_full = 0x2;
81 *data_len = sizeof(set_event_msg_buffer_full);
82
83 // Pack the actual response
84 memcpy(response, &set_event_msg_buffer_full, *data_len);
85
86 return rc;
87}
88
89ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Patrick Venture0b02be92018-08-31 11:55:55 -070090 ipmi_request_t request,
91 ipmi_response_t response,
92 ipmi_data_len_t data_len,
93 ipmi_context_t context)
Tom9e5232e2016-11-07 12:14:51 +053094{
95 ipmi_ret_t rc = IPMI_CC_OK;
96 *data_len = 0;
97
98 // Event and message logging enabled by default so return for now
Aditya Saripalli5fb14602017-11-09 14:46:27 +053099#ifdef __IPMI_DEBUG__
Tom9e5232e2016-11-07 12:14:51 +0530100 printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
Aditya Saripalli5fb14602017-11-09 14:46:27 +0530101#endif
Tom9e5232e2016-11-07 12:14:51 +0530102
103 return rc;
104}
105
Patrick Venture0b02be92018-08-31 11:55:55 -0700106namespace
107{
Lei YU12c2db72017-05-15 11:24:04 +0800108// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530109std::unique_ptr<phosphor::host::command::Host> host
Patrick Venture0b02be92018-08-31 11:55:55 -0700110 __attribute__((init_priority(101)));
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530111std::unique_ptr<sdbusplus::server::manager::manager> objManager
Patrick Venture0b02be92018-08-31 11:55:55 -0700112 __attribute__((init_priority(101)));
113} // namespace
Andrew Geissler12866372017-03-21 22:58:28 -0500114
115#include <unistd.h>
Tom9e5232e2016-11-07 12:14:51 +0530116void register_netfn_app_functions()
117{
118
119 // <Read Event Message Buffer>
Patrick Venture0b02be92018-08-31 11:55:55 -0700120 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL,
121 ipmi_app_read_event, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530122
123 // <Set BMC Global Enables>
Tom9e5232e2016-11-07 12:14:51 +0530124 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
Tom05732372016-09-06 17:21:23 +0530125 ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530126
127 // <Get Message Flags>
Patrick Venture0b02be92018-08-31 11:55:55 -0700128 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL,
129 ipmi_app_get_msg_flags, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530130
Andrew Geissler12866372017-03-21 22:58:28 -0500131 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530132 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500133
134 // Add sdbusplus ObjectManager.
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530135 auto& sdbusPlusHandler = ipmid_get_sdbus_plus_handler();
136 objManager = std::make_unique<sdbusplus::server::manager::manager>(
Patrick Venture0b02be92018-08-31 11:55:55 -0700137 *sdbusPlusHandler, CONTROL_HOST_OBJ_MGR);
Andrew Geissler12866372017-03-21 22:58:28 -0500138
Patrick Venture0b02be92018-08-31 11:55:55 -0700139 host = std::make_unique<phosphor::host::command::Host>(*sdbusPlusHandler,
140 objPath.c_str());
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530141 sdbusPlusHandler->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500142
Tom9e5232e2016-11-07 12:14:51 +0530143 return;
144}