blob: 62d95241e703861049fe1959de2880e50dce3b2c [file] [log] [blame]
Tom9e5232e2016-11-07 12:14:51 +05301#include "systemintfcmds.h"
2#include "host-ipmid/ipmid-api.h"
Vishwanatha Subbannab891a572017-03-31 11:34:48 +05303#include "config.h"
Tom9e5232e2016-11-07 12:14:51 +05304
5#include <stdio.h>
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +05306#include <mapper.h>
Tom9e5232e2016-11-07 12:14:51 +05307
8void register_netfn_app_functions() __attribute__((constructor));
9
10//-------------------------------------------------------------------
11// Called by Host post response from Get_Message_Flags
12//-------------------------------------------------------------------
13ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
14 ipmi_request_t request, ipmi_response_t response,
15 ipmi_data_len_t data_len, ipmi_context_t context)
16{
17 ipmi_ret_t rc = IPMI_CC_OK;
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053018
Tom9e5232e2016-11-07 12:14:51 +053019 printf("IPMI APP READ EVENT command received\n");
20
21 // TODO : For now, this is catering only to the Soft Power Off via OEM SEL
22 // mechanism. If we need to make this generically used for some
23 // other conditions, then we can take advantage of context pointer.
24
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053025 constexpr auto iface = "org.freedesktop.DBus.Properties";
26 constexpr auto soft_off_iface = "xyz.openbmc_project.Ipmi.Internal."
27 "SoftPowerOff";
28
29 constexpr auto property = "ResponseReceived";
30 constexpr auto value = "xyz.openbmc_project.Ipmi.Internal."
31 "SoftPowerOff.HostResponse.SoftOffReceived";
32 char *busname = nullptr;
33
Tom9e5232e2016-11-07 12:14:51 +053034 struct oem_sel_timestamped soft_off = {0};
35 *data_len = sizeof(struct oem_sel_timestamped);
36
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053037 // Get the system bus where most system services are provided.
38 auto bus = ipmid_get_sd_bus_connection();
39
40 // Nudge the SoftPowerOff application that it needs to stop the
41 // initial watchdog timer. If we have some errors talking to Soft Off
42 // object, get going and do our regular job
Vishwanatha Subbannab891a572017-03-31 11:34:48 +053043 mapper_get_service(bus, SOFTOFF_OBJPATH, &busname);
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053044 if (busname)
45 {
46 // No error object or reply expected.
Vishwanatha Subbannab891a572017-03-31 11:34:48 +053047 auto r = sd_bus_call_method(bus, busname, SOFTOFF_OBJPATH, iface,
Vishwanatha Subbanna83b5c1c2017-01-25 18:41:51 +053048 "Set", nullptr, nullptr, "ssv",
49 soft_off_iface, property, "s", value);
50 if (r < 0)
51 {
52 fprintf(stderr, "Failed to set property in SoftPowerOff object: %s\n",
53 strerror(-r));
54 }
55 free (busname);
56 }
57 else
58 {
59 printf("Soft Power Off object is not available. Ignoring watchdog refresh");
60 }
61
Tom9e5232e2016-11-07 12:14:51 +053062 // either id[0] -or- id[1] can be filled in. We will use id[0]
63 soft_off.id[0] = SEL_OEM_ID_0;
64 soft_off.id[1] = SEL_OEM_ID_0;
65 soft_off.type = SEL_RECORD_TYPE_OEM;
66
67 // Following 3 bytes are from IANA Manufactre_Id field. See below
68 soft_off.manuf_id[0]= 0x41;
69 soft_off.manuf_id[1]= 0xA7;
70 soft_off.manuf_id[2]= 0x00;
71
72 // per IPMI spec NetFuntion for OEM
73 soft_off.netfun = 0x3A;
74
75 // Mechanism to kick start soft shutdown.
76 soft_off.cmd = CMD_POWER;
77 soft_off.data[0] = SOFT_OFF;
78
79 // All '0xFF' since unused.
80 memset(&soft_off.data[1], 0xFF, 3);
81
82 // Pack the actual response
83 memcpy(response, &soft_off, *data_len);
84 return rc;
85}
86
87//---------------------------------------------------------------------
88// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
89// value of 0x2 indicating we need Host read some data.
90//-------------------------------------------------------------------
91ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
92 ipmi_request_t request, ipmi_response_t response,
93 ipmi_data_len_t data_len, ipmi_context_t context)
94{
95 // Generic return from IPMI commands.
96 ipmi_ret_t rc = IPMI_CC_OK;
97
98 printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n");
99
100 // From IPMI spec V2.0 for Get Message Flags Command :
101 // bit:[1] from LSB : 1b = Event Message Buffer Full.
102 // Return as 0 if Event Message Buffer is not supported,
103 // or when the Event Message buffer is disabled.
104 // TODO. For now. assume its not disabled and send "0x2" anyway:
105
106 uint8_t set_event_msg_buffer_full = 0x2;
107 *data_len = sizeof(set_event_msg_buffer_full);
108
109 // Pack the actual response
110 memcpy(response, &set_event_msg_buffer_full, *data_len);
111
112 return rc;
113}
114
115ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
116 ipmi_request_t request, ipmi_response_t response,
117 ipmi_data_len_t data_len, ipmi_context_t context)
118{
119 ipmi_ret_t rc = IPMI_CC_OK;
120 *data_len = 0;
121
122 // Event and message logging enabled by default so return for now
123 printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
124
125 return rc;
126}
127
128void register_netfn_app_functions()
129{
130
131 // <Read Event Message Buffer>
132 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
Tom05732372016-09-06 17:21:23 +0530133 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event,
134 SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530135
136 // <Set BMC Global Enables>
137 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
138 IPMI_CMD_SET_BMC_GLOBAL_ENABLES);
139 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
Tom05732372016-09-06 17:21:23 +0530140 ipmi_app_set_bmc_global_enables, SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530141
142 // <Get Message Flags>
143 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS);
Tom05732372016-09-06 17:21:23 +0530144 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags,
145 SYSTEM_INTERFACE);
Tom9e5232e2016-11-07 12:14:51 +0530146
147 return;
148}