blob: 45cec197b7d665fa7c3a3c84c5703f75773387ce [file] [log] [blame]
vishwabmcba0bd5f2015-09-30 16:50:23 +05301#include "apphandler.h"
2#include "ipmid-api.h"
Chris Austen6caf28b2015-10-13 12:40:40 -05003#include "ipmid.H"
vishwabmcba0bd5f2015-09-30 16:50:23 +05304#include <stdio.h>
5#include <string.h>
Chris Austen6caf28b2015-10-13 12:40:40 -05006#include <stdint.h>
Adriana Kobylak3a552e12015-10-19 16:11:00 -05007#include <systemd/sd-bus.h>
8
9extern sd_bus *bus;
vishwabmcba0bd5f2015-09-30 16:50:23 +053010
Chris Austen6caf28b2015-10-13 12:40:40 -050011void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053012
Chris Austen6caf28b2015-10-13 12:40:40 -050013
Adriana Kobylak3a552e12015-10-19 16:11:00 -050014ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
15 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -050016 ipmi_data_len_t data_len, ipmi_context_t context)
17{
18 ipmi_ret_t rc = IPMI_CC_OK;
19 *data_len = 0;
20
21 printf("IPMI APP READ EVENT Ignoring for now\n");
22 return rc;
23
24}
25
26
Adriana Kobylak3a552e12015-10-19 16:11:00 -050027ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
28 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -050029 ipmi_data_len_t data_len, ipmi_context_t context)
30{
31 ipmi_ret_t rc = IPMI_CC_OK;
32 *data_len = 0;
33
34 printf("IPMI SET ACPI STATE Ignoring for now\n");
35 return rc;
36}
37
Adriana Kobylak3a552e12015-10-19 16:11:00 -050038ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
39 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -050040 ipmi_data_len_t data_len, ipmi_context_t context)
41{
42 ipmi_ret_t rc = IPMI_CC_OK;
43
Adriana Kobylak3a552e12015-10-19 16:11:00 -050044 // TODO GET REAL VALUES HERE.... I made these ones up because
Chris Austen6caf28b2015-10-13 12:40:40 -050045 // we are in bringup mode. Version Major and Minor can be what we
Adriana Kobylak3a552e12015-10-19 16:11:00 -050046 // want like v1.03 but the IANA really should be something that
47 // we own. I would suggest getting the IANA from Hostboot as
48 // long as IBM owns it then no problem. If some other company
49 // gave us the IANA to use then use the one we have from the
Chris Austen6caf28b2015-10-13 12:40:40 -050050 // FSP ipmi code.
51 uint8_t str[] = {0x00, 0, 1, 1,2, 0xD, 0x41, 0xA7, 0x00, 0x43, 0x40};
52
53 // Data length
54 *data_len = sizeof(str);
55
56 // Pack the actual response
57 memcpy(response, &str, *data_len);
58 return rc;
59}
60
61
Adriana Kobylak3a552e12015-10-19 16:11:00 -050062ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
63 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +053064 ipmi_data_len_t data_len, ipmi_context_t context)
65{
66 printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
67
68 // Status code.
69 ipmi_ret_t rc = IPMI_CC_OK;
70
Chris Austen6caf28b2015-10-13 12:40:40 -050071 uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01};
vishwabmcba0bd5f2015-09-30 16:50:23 +053072
73 // Data length
74 *data_len = sizeof(str);
75
76 // Pack the actual response
77 memcpy(response, &str, *data_len);
78
79 return rc;
80}
81
Chris Austen6caf28b2015-10-13 12:40:40 -050082
83struct set_wd_data_t {
84 uint8_t t_use;
85 uint8_t t_action;
86 uint8_t preset;
87 uint8_t flags;
88 uint8_t ls;
89 uint8_t ms;
90} __attribute__ ((packed));
91
92
93
Adriana Kobylak3a552e12015-10-19 16:11:00 -050094ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
95 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -050096 ipmi_data_len_t data_len, ipmi_context_t context)
97{
Adriana Kobylak3a552e12015-10-19 16:11:00 -050098 const char *busname = "org.openbmc.watchdog.Host";
99 const char *objname = "/org/openbmc/watchdog/HostWatchdog_0";
100 const char *iface = "org.openbmc.Watchdog";
101 sd_bus_message *reply = NULL, *m = NULL;
102 sd_bus_error error = SD_BUS_ERROR_NULL;
103 int r = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500104
105 set_wd_data_t *reqptr = (set_wd_data_t*) request;
106 uint16_t timer = 0;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500107 uint32_t timer_ms = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500108 // Status code.
109 ipmi_ret_t rc = IPMI_CC_OK;
110
111 *data_len = 0;
112
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500113 // Get number of 100ms intervals
Chris Austen6caf28b2015-10-13 12:40:40 -0500114 timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500115 // Get timer value in ms
116 timer_ms = timer * 100;
Chris Austen6caf28b2015-10-13 12:40:40 -0500117
118 printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer);
119
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500120 // Set watchdog timer
121 r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"set");
122 if (r < 0) {
123 fprintf(stderr, "Failed to add the set method object: %s\n", strerror(-r));
124 return -1;
125 }
126 r = sd_bus_message_append(m, "i", timer_ms);
127 if (r < 0) {
128 fprintf(stderr, "Failed to add timer value: %s\n", strerror(-r));
129 return -1;
130 }
131 r = sd_bus_call(bus, m, 0, &error, &reply);
132 if (r < 0) {
133 fprintf(stderr, "Failed to call the set method: %s\n", strerror(-r));
134 return -1;
135 }
136
Adriana Kobylak0896be32015-10-22 13:27:23 -0500137 // Stop the current watchdog if any
138 r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"stop");
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500139 if (r < 0) {
140 fprintf(stderr, "Failed to add the start method object: %s\n", strerror(-r));
141 return -1;
142 }
143 r = sd_bus_call(bus, m, 0, &error, &reply);
144 if (r < 0) {
145 fprintf(stderr, "Failed to call the start method: %s\n", strerror(-r));
146 return -1;
147 }
148
Adriana Kobylak0896be32015-10-22 13:27:23 -0500149 // Start the watchdog if requested
150 if (reqptr->t_use & 0x40)
151 {
152 r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"start");
153 if (r < 0) {
154 fprintf(stderr, "Failed to add the start method object: %s\n", strerror(-r));
155 return -1;
156 }
157 r = sd_bus_call(bus, m, 0, &error, &reply);
158 if (r < 0) {
159 fprintf(stderr, "Failed to call the start method: %s\n", strerror(-r));
160 return -1;
161 }
162 }
163
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500164 sd_bus_error_free(&error);
165 sd_bus_message_unref(m);
Chris Austen6caf28b2015-10-13 12:40:40 -0500166
167 return rc;
168}
169
170
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500171ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
172 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500173 ipmi_data_len_t data_len, ipmi_context_t context)
174{
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500175 const char *busname = "org.openbmc.watchdog.Host";
176 const char *objname = "/org/openbmc/watchdog/HostWatchdog_0";
177 const char *iface = "org.openbmc.Watchdog";
178 sd_bus_message *reply = NULL, *m = NULL;
179 sd_bus_error error = SD_BUS_ERROR_NULL;
180 int r = 0;
181
Chris Austen6caf28b2015-10-13 12:40:40 -0500182 // Status code.
183 ipmi_ret_t rc = IPMI_CC_OK;
184 *data_len = 0;
185
186 printf("WATCHDOG RESET\n");
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500187
188 // Refresh watchdog
189 r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"poke");
190 if (r < 0) {
191 fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r));
192 return -1;
193 }
194 r = sd_bus_call(bus, m, 0, &error, &reply);
195 if (r < 0) {
196 fprintf(stderr, "Failed to call the method: %s\n", strerror(-r));
197 return -1;
198 }
199
200 sd_bus_error_free(&error);
201 sd_bus_message_unref(m);
202
Chris Austen6caf28b2015-10-13 12:40:40 -0500203 return rc;
204}
205
206
207
208
209
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500210ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
211 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530212 ipmi_data_len_t data_len, ipmi_context_t context)
213{
214 printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
215
216 // Status code.
217 ipmi_ret_t rc = IPMI_CC_OK;
218
219 *data_len = strlen("THIS IS WILDCARD");
220
221 // Now pack actual response
222 memcpy(response, "THIS IS WILDCARD", *data_len);
223
224 return rc;
225}
226
Chris Austen6caf28b2015-10-13 12:40:40 -0500227void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530228{
229 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT);
Chris Austen6caf28b2015-10-13 12:40:40 -0500230 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities);
231
232 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD);
233 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler);
234
235 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD);
236 ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog);
237
238 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD);
239 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog);
240
241 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID);
242 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id);
243
244 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI);
245 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state);
246
247 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
248 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event);
vishwabmcba0bd5f2015-09-30 16:50:23 +0530249 return;
250}
251
Chris Austen6caf28b2015-10-13 12:40:40 -0500252