blob: d363233cbc3bd133caddf28054b8a6af0f296c9c [file] [log] [blame]
Tom9e5232e2016-11-07 12:14:51 +05301#include "systemintfcmds.h"
2#include "host-ipmid/ipmid-api.h"
Vishwanatha Subbanna6e8979d2017-07-13 16:48:20 +05303#include "host-ipmid/ipmid-host-cmd.hpp"
Vishwanatha Subbannab891a572017-03-31 11:34:48 +05304#include "config.h"
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
8#include <stdio.h>
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05309#include <mapper.h>
Tom9e5232e2016-11-07 12:14:51 +053010
11void register_netfn_app_functions() __attribute__((constructor));
12
Andrew Geissler12866372017-03-21 22:58:28 -050013using namespace sdbusplus::xyz::openbmc_project::Control::server;
14
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053015// For accessing Host command manager
16using cmdManagerPtr = std::unique_ptr<phosphor::host::command::Manager>;
17extern cmdManagerPtr& ipmid_get_host_cmd_manager();
Andrew Geissler12866372017-03-21 22:58:28 -050018
Andrew Geissler12866372017-03-21 22:58:28 -050019//-------------------------------------------------------------------
20// Called by Host post response from Get_Message_Flags
21//-------------------------------------------------------------------
22ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
23 ipmi_request_t request, ipmi_response_t response,
24 ipmi_data_len_t data_len, ipmi_context_t context)
25{
26 ipmi_ret_t rc = IPMI_CC_OK;
27
Andrew Geissler12866372017-03-21 22:58:28 -050028 struct oem_sel_timestamped oem_sel = {0};
29 *data_len = sizeof(struct oem_sel_timestamped);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053030
Tom9e5232e2016-11-07 12:14:51 +053031 // either id[0] -or- id[1] can be filled in. We will use id[0]
Andrew Geissler12866372017-03-21 22:58:28 -050032 oem_sel.id[0] = SEL_OEM_ID_0;
33 oem_sel.id[1] = SEL_OEM_ID_0;
34 oem_sel.type = SEL_RECORD_TYPE_OEM;
Tom9e5232e2016-11-07 12:14:51 +053035
36 // Following 3 bytes are from IANA Manufactre_Id field. See below
Andrew Geissler12866372017-03-21 22:58:28 -050037 oem_sel.manuf_id[0]= 0x41;
38 oem_sel.manuf_id[1]= 0xA7;
39 oem_sel.manuf_id[2]= 0x00;
Tom9e5232e2016-11-07 12:14:51 +053040
41 // per IPMI spec NetFuntion for OEM
Andrew Geissler12866372017-03-21 22:58:28 -050042 oem_sel.netfun = 0x3A;
Tom9e5232e2016-11-07 12:14:51 +053043
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +053044 // Read from the Command Manager queue. What gets returned is a
45 // pair of <command, data> that can be directly used here
46 auto hostCmd = ipmid_get_host_cmd_manager()->getNextCommand();
47 oem_sel.cmd = hostCmd.first;
48 oem_sel.data[0] = hostCmd.second;
Tom9e5232e2016-11-07 12:14:51 +053049
50 // All '0xFF' since unused.
Andrew Geissler12866372017-03-21 22:58:28 -050051 memset(&oem_sel.data[1], 0xFF, 3);
Tom9e5232e2016-11-07 12:14:51 +053052
53 // Pack the actual response
Andrew Geissler12866372017-03-21 22:58:28 -050054 memcpy(response, &oem_sel, *data_len);
Tom9e5232e2016-11-07 12:14:51 +053055 return rc;
56}
57
58//---------------------------------------------------------------------
59// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
60// value of 0x2 indicating we need Host read some data.
61//-------------------------------------------------------------------
62ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
63 ipmi_request_t request, ipmi_response_t response,
64 ipmi_data_len_t data_len, ipmi_context_t context)
65{
66 // Generic return from IPMI commands.
67 ipmi_ret_t rc = IPMI_CC_OK;
68
Tom9e5232e2016-11-07 12:14:51 +053069 // From IPMI spec V2.0 for Get Message Flags Command :
70 // bit:[1] from LSB : 1b = Event Message Buffer Full.
71 // Return as 0 if Event Message Buffer is not supported,
72 // or when the Event Message buffer is disabled.
73 // TODO. For now. assume its not disabled and send "0x2" anyway:
74
75 uint8_t set_event_msg_buffer_full = 0x2;
76 *data_len = sizeof(set_event_msg_buffer_full);
77
78 // Pack the actual response
79 memcpy(response, &set_event_msg_buffer_full, *data_len);
80
81 return rc;
82}
83
84ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
85 ipmi_request_t request, ipmi_response_t response,
86 ipmi_data_len_t data_len, ipmi_context_t context)
87{
88 ipmi_ret_t rc = IPMI_CC_OK;
89 *data_len = 0;
90
91 // Event and message logging enabled by default so return for now
Aditya Saripalli5fb14602017-11-09 14:46:27 +053092#ifdef __IPMI_DEBUG__
Tom9e5232e2016-11-07 12:14:51 +053093 printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
Aditya Saripalli5fb14602017-11-09 14:46:27 +053094#endif
Tom9e5232e2016-11-07 12:14:51 +053095
96 return rc;
97}
98
Lei YU12c2db72017-05-15 11:24:04 +080099namespace {
100// Static storage to keep the object alive during process life
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530101std::unique_ptr<phosphor::host::command::Host> host
102 __attribute__((init_priority(101)));
103std::unique_ptr<sdbusplus::server::manager::manager> objManager
104 __attribute__((init_priority(101)));
Lei YU12c2db72017-05-15 11:24:04 +0800105}
Andrew Geissler12866372017-03-21 22:58:28 -0500106
107#include <unistd.h>
Tom9e5232e2016-11-07 12:14:51 +0530108void register_netfn_app_functions()
109{
110
111 // <Read Event Message Buffer>
Tom05732372016-09-06 17:21:23 +0530112 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event,
113 SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530114
115 // <Set BMC Global Enables>
Tom9e5232e2016-11-07 12:14:51 +0530116 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
Tom05732372016-09-06 17:21:23 +0530117 ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530118
119 // <Get Message Flags>
Tom05732372016-09-06 17:21:23 +0530120 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags,
121 SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530122
Andrew Geissler12866372017-03-21 22:58:28 -0500123 // Create new xyz.openbmc_project.host object on the bus
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530124 auto objPath = std::string{CONTROL_HOST_OBJ_MGR} + '/' + HOST_NAME + '0';
Andrew Geissler12866372017-03-21 22:58:28 -0500125
126 // Add sdbusplus ObjectManager.
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530127 auto& sdbusPlusHandler = ipmid_get_sdbus_plus_handler();
128 objManager = std::make_unique<sdbusplus::server::manager::manager>(
129 *sdbusPlusHandler,
130 CONTROL_HOST_OBJ_MGR);
Andrew Geissler12866372017-03-21 22:58:28 -0500131
Vishwanatha Subbanna3eb117a2017-07-12 16:13:49 +0530132 host = std::make_unique<phosphor::host::command::Host>(
133 *sdbusPlusHandler, objPath.c_str());
134 sdbusPlusHandler->request_name(CONTROL_HOST_BUSNAME);
Andrew Geissler12866372017-03-21 22:58:28 -0500135
Tom9e5232e2016-11-07 12:14:51 +0530136 return;
137}