blob: 132f5c66705a34ef0ad5cdec571c0e7e9e919685 [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
137 // Start watchdog
138 r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"start");
139 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
149 sd_bus_error_free(&error);
150 sd_bus_message_unref(m);
Chris Austen6caf28b2015-10-13 12:40:40 -0500151
152 return rc;
153}
154
155
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500156ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
157 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500158 ipmi_data_len_t data_len, ipmi_context_t context)
159{
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500160 const char *busname = "org.openbmc.watchdog.Host";
161 const char *objname = "/org/openbmc/watchdog/HostWatchdog_0";
162 const char *iface = "org.openbmc.Watchdog";
163 sd_bus_message *reply = NULL, *m = NULL;
164 sd_bus_error error = SD_BUS_ERROR_NULL;
165 int r = 0;
166
Chris Austen6caf28b2015-10-13 12:40:40 -0500167 // Status code.
168 ipmi_ret_t rc = IPMI_CC_OK;
169 *data_len = 0;
170
171 printf("WATCHDOG RESET\n");
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500172
173 // Refresh watchdog
174 r = sd_bus_message_new_method_call(bus,&m,busname,objname,iface,"poke");
175 if (r < 0) {
176 fprintf(stderr, "Failed to add the method object: %s\n", strerror(-r));
177 return -1;
178 }
179 r = sd_bus_call(bus, m, 0, &error, &reply);
180 if (r < 0) {
181 fprintf(stderr, "Failed to call the method: %s\n", strerror(-r));
182 return -1;
183 }
184
185 sd_bus_error_free(&error);
186 sd_bus_message_unref(m);
187
Chris Austen6caf28b2015-10-13 12:40:40 -0500188 return rc;
189}
190
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500191ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
192 ipmi_request_t request, ipmi_response_t response,
193 ipmi_data_len_t data_len, ipmi_context_t context)
194{
195 ipmi_ret_t rc = IPMI_CC_OK;
196 *data_len = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500197
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500198 // Event and message logging enabled by default so return for now
199 printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
200
201 return rc;
202}
Chris Austen6caf28b2015-10-13 12:40:40 -0500203
204
205
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500206ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
207 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530208 ipmi_data_len_t data_len, ipmi_context_t context)
209{
210 printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
211
212 // Status code.
213 ipmi_ret_t rc = IPMI_CC_OK;
214
215 *data_len = strlen("THIS IS WILDCARD");
216
217 // Now pack actual response
218 memcpy(response, "THIS IS WILDCARD", *data_len);
219
220 return rc;
221}
222
Chris Austen6caf28b2015-10-13 12:40:40 -0500223void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530224{
225 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT);
Chris Austen6caf28b2015-10-13 12:40:40 -0500226 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities);
227
228 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD);
229 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler);
230
231 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD);
232 ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog);
233
234 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD);
235 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog);
236
237 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID);
238 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id);
239
240 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI);
241 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state);
242
243 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
244 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event);
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500245
246 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
247 IPMI_CMD_SET_BMC_GLOBAL_ENABLES);
248 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
249 ipmi_app_set_bmc_global_enables);
250
vishwabmcba0bd5f2015-09-30 16:50:23 +0530251 return;
252}
253
Chris Austen6caf28b2015-10-13 12:40:40 -0500254