blob: bfc821e2268a870cc32c13a67de75a59f3bfb059 [file] [log] [blame]
vishwabmcba0bd5f2015-09-30 16:50:23 +05301#include "apphandler.h"
2#include "ipmid-api.h"
Patrick Williams53a360e2016-08-12 22:01:02 -05003#include "ipmid.hpp"
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>
Sergey Solomineb9b8142016-08-23 09:07:28 -05008#include <mapper.h>
Nan Liee0cb902016-07-11 15:38:03 +08009#include <array>
Adriana Kobylak3a552e12015-10-19 16:11:00 -050010
11extern sd_bus *bus;
vishwabmcba0bd5f2015-09-30 16:50:23 +053012
Chris Austen6caf28b2015-10-13 12:40:40 -050013void register_netfn_app_functions() __attribute__((constructor));
vishwabmcba0bd5f2015-09-30 16:50:23 +053014
Nan Liee0cb902016-07-11 15:38:03 +080015// Offset in get device id command.
16typedef struct
17{
18 uint8_t id;
19 uint8_t revision;
20 uint8_t fw[2];
21 uint8_t ipmi_ver;
22 uint8_t addn_dev_support;
23 uint8_t manuf_id[3];
24 uint8_t prod_id[2];
25 uint8_t aux[4];
26}__attribute__((packed)) ipmi_device_id_t;
Chris Austen7303bdc2016-04-17 11:50:54 -050027
vishwa36993272015-11-20 12:43:49 -060028//---------------------------------------------------------------------
Patrick Williams53a360e2016-08-12 22:01:02 -050029// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
vishwa36993272015-11-20 12:43:49 -060030// value of 0x2 indicating we need Host read some data.
31//-------------------------------------------------------------------
32ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
33 ipmi_request_t request, ipmi_response_t response,
34 ipmi_data_len_t data_len, ipmi_context_t context)
35{
36 // Generic return from IPMI commands.
37 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen6caf28b2015-10-13 12:40:40 -050038
vishwa36993272015-11-20 12:43:49 -060039 printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n");
40
41 // From IPMI spec V2.0 for Get Message Flags Command :
Patrick Williams53a360e2016-08-12 22:01:02 -050042 // bit:[1] from LSB : 1b = Event Message Buffer Full.
43 // Return as 0 if Event Message Buffer is not supported,
vishwa36993272015-11-20 12:43:49 -060044 // or when the Event Message buffer is disabled.
45 // TODO. For now. assume its not disabled and send "0x2" anyway:
46
47 uint8_t set_event_msg_buffer_full = 0x2;
48 *data_len = sizeof(set_event_msg_buffer_full);
49
50 // Pack the actual response
51 memcpy(response, &set_event_msg_buffer_full, *data_len);
52
53 return rc;
54}
55
56//-------------------------------------------------------------------
57// Called by Host post response from Get_Message_Flags
58//-------------------------------------------------------------------
Adriana Kobylak3a552e12015-10-19 16:11:00 -050059ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
60 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -050061 ipmi_data_len_t data_len, ipmi_context_t context)
62{
63 ipmi_ret_t rc = IPMI_CC_OK;
vishwa36993272015-11-20 12:43:49 -060064 printf("IPMI APP READ EVENT command received\n");
Chris Austen6caf28b2015-10-13 12:40:40 -050065
vishwa36993272015-11-20 12:43:49 -060066 // TODO : For now, this is catering only to the Soft Power Off via OEM SEL
67 // mechanism. If we need to make this generically used for some
68 // other conditions, then we can take advantage of context pointer.
69
70 struct oem_sel_timestamped soft_off = {0};
71 *data_len = sizeof(struct oem_sel_timestamped);
72
73 // either id[0] -or- id[1] can be filled in. We will use id[0]
74 soft_off.id[0] = SEL_OEM_ID_0;
75 soft_off.id[1] = SEL_OEM_ID_0;
76 soft_off.type = SEL_RECORD_TYPE_OEM;
77
78 // Following 3 bytes are from IANA Manufactre_Id field. See below
79 soft_off.manuf_id[0]= 0x41;
80 soft_off.manuf_id[1]= 0xA7;
81 soft_off.manuf_id[2]= 0x00;
82
83 // per IPMI spec NetFuntion for OEM
84 soft_off.netfun = 0x3A;
85
86 // Mechanism to kick start soft shutdown.
87 soft_off.cmd = CMD_POWER;
88 soft_off.data[0] = SOFT_OFF;
89
90 // All '0xFF' since unused.
91 memset(&soft_off.data[1], 0xFF, 3);
92
93 // Pack the actual response
94 memcpy(response, &soft_off, *data_len);
Chris Austen6caf28b2015-10-13 12:40:40 -050095 return rc;
Chris Austen6caf28b2015-10-13 12:40:40 -050096}
97
Adriana Kobylak3a552e12015-10-19 16:11:00 -050098ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
99 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500100 ipmi_data_len_t data_len, ipmi_context_t context)
101{
102 ipmi_ret_t rc = IPMI_CC_OK;
103 *data_len = 0;
104
105 printf("IPMI SET ACPI STATE Ignoring for now\n");
106 return rc;
107}
108
Chris Austen7303bdc2016-04-17 11:50:54 -0500109
110typedef struct
111{
112 char major;
113 char minor;
Chris Austen176c9652016-04-30 16:32:17 -0500114 uint16_t d[2];
Chris Austen7303bdc2016-04-17 11:50:54 -0500115} rev_t;
116
117
118/* Currently only supports the vx.x-x-[-x] format Will return -1 if not in */
119/* the format this routine knows how to parse */
120/* version = v0.6-19-gf363f61-dirty */
121/* ^ ^ ^^ ^ */
122/* | | |----------|-- additional details */
123/* | |---------------- Minor */
124/* |------------------ Major */
125/* Additional details : If the option group exists it will force Auxiliary */
126/* Firmware Revision Information 4th byte to 1 indicating the build was */
127/* derived with additional edits */
128int convert_version(const char *p, rev_t *rev)
129{
130 char *s, *token;
131 char hexbyte[5];
132 int l;
Chris Austen176c9652016-04-30 16:32:17 -0500133 uint16_t commits;
Chris Austen7303bdc2016-04-17 11:50:54 -0500134
135 if (*p != 'v')
136 return -1;
137 p++;
138
139 s = strdup(p);
140 token = strtok(s,".-");
141
142 rev->major = (int8_t) atoi(token);
143
144 token = strtok(NULL, ".-");
145 rev->minor = (int8_t) atoi(token);
146
147 // Capture the number of commits on top of the minor tag.
148 // I'm using BE format like the ipmi spec asked for
149 token = strtok(NULL,".-");
Chris Austen7303bdc2016-04-17 11:50:54 -0500150
Chris Austen176c9652016-04-30 16:32:17 -0500151 if (token) {
152 commits = (int16_t) atoi(token);
153 rev->d[0] = (commits>>8) | (commits<<8);
Chris Austen7303bdc2016-04-17 11:50:54 -0500154
Chris Austen176c9652016-04-30 16:32:17 -0500155 // commit number we skip
156 token = strtok(NULL,".-");
Chris Austen7303bdc2016-04-17 11:50:54 -0500157
Chris Austen176c9652016-04-30 16:32:17 -0500158 } else {
159 rev->d[0] = 0;
160 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500161
162 // Any value of the optional parameter forces it to 1
Chris Austen176c9652016-04-30 16:32:17 -0500163 if (token)
164 token = strtok(NULL,".-");
165
166 rev->d[1] = (token != NULL) ? 1 : 0;
Chris Austen7303bdc2016-04-17 11:50:54 -0500167
168 free(s);
169 return 0;
170}
171
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500172ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
173 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500174 ipmi_data_len_t data_len, ipmi_context_t context)
175{
176 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen7303bdc2016-04-17 11:50:54 -0500177 const char *objname = "/org/openbmc/inventory/system/chassis/motherboard/bmc";
178 const char *iface = "org.openbmc.InventoryItem";
179 char *ver = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500180 char *busname = NULL;
Chris Austen7303bdc2016-04-17 11:50:54 -0500181 int r;
182 rev_t rev = {0};
Nan Liee0cb902016-07-11 15:38:03 +0800183 ipmi_device_id_t dev_id{};
Chris Austen6caf28b2015-10-13 12:40:40 -0500184
185 // Data length
Chris Austen7303bdc2016-04-17 11:50:54 -0500186 *data_len = sizeof(dev_id);
187
Nan Liee0cb902016-07-11 15:38:03 +0800188 // From IPMI spec, controller that have different application commands, or different
189 // definitions of OEM fields, are expected to have different Device ID values.
190 // Set to 0 now.
191
192 // Device Revision is set to 0 now.
193 // Bit7 identifies if device provide Device SDRs, obmc don't have SDR,we use ipmi to
194 // simulate SDR, hence the value:
195 dev_id.revision = 0x80;
196
197 // Firmware revision is already implemented, so get it from appropriate position.
Sergey Solomineb9b8142016-08-23 09:07:28 -0500198 r = mapper_get_service(bus, objname, &busname);
199 if (r < 0) {
200 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
201 goto finish;
202 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500203 r = sd_bus_get_property_string(bus,busname,objname,iface,"version", NULL, &ver);
204 if ( r < 0 ) {
205 fprintf(stderr, "Failed to obtain version property: %s\n", strerror(-r));
206 } else {
207 r = convert_version(ver, &rev);
208 if( r >= 0 ) {
Nan Liee0cb902016-07-11 15:38:03 +0800209 // bit7 identifies if the device is available, 0=normal operation,
210 // 1=device firmware, SDR update or self-initialization in progress.
211 // our SDR is normal working condition, so mask:
212 dev_id.fw[0] = 0x7F & rev.major;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500213
214 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
Nan Liee0cb902016-07-11 15:38:03 +0800215 dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
216 memcpy(&dev_id.aux, rev.d, 4);
Chris Austen7303bdc2016-04-17 11:50:54 -0500217 }
218 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500219
Nan Liee0cb902016-07-11 15:38:03 +0800220 // IPMI Spec verison 2.0
221 dev_id.ipmi_ver = 2;
222
223 // Additional device Support.
224 // List the 'logical device' commands and functions that the controller supports
225 // that are in addition to the mandatory IPM and Application commands.
226 // [7] Chassis Device (device functions as chassis device per ICMB spec.)
227 // [6] Bridge (device responds to Bridge NetFn commands)
228 // [5] IPMB Event Generator
229 // [4] IPMB Event Receiver
230 // [3] FRU Inventory Device
231 // [2] SEL Device
232 // [1] SDR Repository Device
233 // [0] Sensor Device
234 // We support FRU/SEL/Sensor now:
235 dev_id.addn_dev_support = 0x8D;
236
237 // This value is the IANA number assigned to "IBM Platform Firmware
238 // Division", which is also used by our service processor. We may want
239 // a different number or at least a different version?
240 dev_id.manuf_id[0] = 0x41;
241 dev_id.manuf_id[1] = 0xA7;
242 dev_id.manuf_id[2] = 0x00;
243
244 // Witherspoon's product ID is hardcoded to 4F42(ASCII 'OB').
245 // TODO: openbmc/openbmc#495
246 dev_id.prod_id[0] = 0x4F;
247 dev_id.prod_id[1] = 0x42;
248
Chris Austen6caf28b2015-10-13 12:40:40 -0500249 // Pack the actual response
Chris Austen7303bdc2016-04-17 11:50:54 -0500250 memcpy(response, &dev_id, *data_len);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500251finish:
252 free(busname);
Chris Austen6caf28b2015-10-13 12:40:40 -0500253 return rc;
254}
255
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500256ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
257 ipmi_request_t request, ipmi_response_t response,
258 ipmi_data_len_t data_len, ipmi_context_t context)
259{
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500260 const char *objname = "/org/openbmc/control/chassis0";
Adriana Kobylak31bccae2015-11-05 13:31:06 -0600261 const char *iface = "org.freedesktop.DBus.Properties";
262 const char *chassis_iface = "org.openbmc.control.Chassis";
vishwa1eaea4f2016-02-26 11:57:40 -0600263 sd_bus_message *reply = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500264 sd_bus_error error = SD_BUS_ERROR_NULL;
265 int r = 0;
266 char *uuid = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500267 char *busname = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500268
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500269 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
270 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order
271 // Ex: 0x2332fc2c40e66298e511f2782395a361
272
273 const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec
274 uint8_t resp_uuid[resp_size]; // Array to hold the formatted response
275 int resp_loc = resp_size-1; // Point resp end of array to save in reverse order
276 int i = 0;
277 char *tokptr = NULL;
vishwa1eaea4f2016-02-26 11:57:40 -0600278 char *id_octet = NULL;
279
280 // Status code.
281 ipmi_ret_t rc = IPMI_CC_OK;
282 *data_len = 0;
283
284 printf("IPMI GET DEVICE GUID\n");
285
286 // Call Get properties method with the interface and property name
Sergey Solomineb9b8142016-08-23 09:07:28 -0500287 r = mapper_get_service(bus, objname, &busname);
288 if (r < 0) {
289 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
290 goto finish;
291 }
vishwa1eaea4f2016-02-26 11:57:40 -0600292 r = sd_bus_call_method(bus,busname,objname,iface,
293 "Get",&error, &reply, "ss",
294 chassis_iface, "uuid");
295 if (r < 0)
296 {
297 fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r));
298 rc = IPMI_CC_UNSPECIFIED_ERROR;
299 goto finish;
300 }
301
302 r = sd_bus_message_read(reply, "v", "s", &uuid);
303 if (r < 0 || uuid == NULL)
304 {
305 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
306 rc = IPMI_CC_RESPONSE_ERROR;
307 goto finish;
308 }
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500309
310 // Traverse the UUID
vishwa1eaea4f2016-02-26 11:57:40 -0600311 id_octet = strtok_r(uuid, "-", &tokptr); // Get the UUID octects separated by dash
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500312
313 if (id_octet == NULL)
vishwa1eaea4f2016-02-26 11:57:40 -0600314 {
315 // Error
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500316 fprintf(stderr, "Unexpected UUID format: %s", uuid);
vishwa1eaea4f2016-02-26 11:57:40 -0600317 rc = IPMI_CC_RESPONSE_ERROR;
318 goto finish;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500319 }
320
321 while (id_octet != NULL)
322 {
323 // Calculate the octet string size since it varies
324 // Divide it by 2 for the array size since 1 byte is built from 2 chars
325 int tmp_size = strlen(id_octet)/2;
326
327 for(i = 0; i < tmp_size; i++)
328 {
Joel Stanley38310cd2015-11-25 17:32:08 +1030329 char tmp_array[3] = {0}; // Holder of the 2 chars that will become a byte
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500330 strncpy(tmp_array, id_octet, 2); // 2 chars at a time
331
332 int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte
333 memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first
334 resp_loc--;
335 id_octet+=2; // Finished with the 2 chars, advance
336 }
337 id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet
338 }
339
340 // Data length
341 *data_len = resp_size;
342
343 // Pack the actual response
344 memcpy(response, &resp_uuid, *data_len);
345
vishwa1eaea4f2016-02-26 11:57:40 -0600346finish:
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500347 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600348 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500349 free(busname);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500350
351 return rc;
352}
Chris Austen6caf28b2015-10-13 12:40:40 -0500353
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500354ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
355 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530356 ipmi_data_len_t data_len, ipmi_context_t context)
357{
358 printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
359
360 // Status code.
361 ipmi_ret_t rc = IPMI_CC_OK;
362
Chris Austen6caf28b2015-10-13 12:40:40 -0500363 uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01};
vishwabmcba0bd5f2015-09-30 16:50:23 +0530364
365 // Data length
366 *data_len = sizeof(str);
367
368 // Pack the actual response
369 memcpy(response, &str, *data_len);
370
371 return rc;
372}
373
Chris Austen6caf28b2015-10-13 12:40:40 -0500374
375struct set_wd_data_t {
376 uint8_t t_use;
377 uint8_t t_action;
378 uint8_t preset;
379 uint8_t flags;
380 uint8_t ls;
381 uint8_t ms;
382} __attribute__ ((packed));
383
384
385
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500386ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
387 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500388 ipmi_data_len_t data_len, ipmi_context_t context)
389{
Chris Austen454acfe2015-10-29 23:03:34 -0500390 const char *objname = "/org/openbmc/watchdog/host0";
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500391 const char *iface = "org.openbmc.Watchdog";
vishwa1eaea4f2016-02-26 11:57:40 -0600392 sd_bus_message *reply = NULL;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500393 sd_bus_error error = SD_BUS_ERROR_NULL;
394 int r = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500395
396 set_wd_data_t *reqptr = (set_wd_data_t*) request;
397 uint16_t timer = 0;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500398 uint32_t timer_ms = 0;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500399 char *busname = NULL;
Chris Austen6caf28b2015-10-13 12:40:40 -0500400 *data_len = 0;
401
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500402 // Get number of 100ms intervals
Chris Austen6caf28b2015-10-13 12:40:40 -0500403 timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500404 // Get timer value in ms
405 timer_ms = timer * 100;
Chris Austen6caf28b2015-10-13 12:40:40 -0500406
407 printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer);
408
Sergey Solomineb9b8142016-08-23 09:07:28 -0500409 // Get bus name
410 r = mapper_get_service(bus, objname, &busname);
411 if (r < 0) {
412 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
413 goto finish;
414 }
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500415 // Set watchdog timer
vishwa1eaea4f2016-02-26 11:57:40 -0600416 r = sd_bus_call_method(bus, busname, objname, iface,
417 "set", &error, &reply, "i", timer_ms);
418 if(r < 0)
Adriana Kobylak0896be32015-10-22 13:27:23 -0500419 {
vishwa1eaea4f2016-02-26 11:57:40 -0600420 fprintf(stderr, "Failed to call the SET method: %s\n", strerror(-r));
421 goto finish;
Adriana Kobylak0896be32015-10-22 13:27:23 -0500422 }
423
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500424 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600425 reply = sd_bus_message_unref(reply);
Chris Austen6caf28b2015-10-13 12:40:40 -0500426
vishwa1eaea4f2016-02-26 11:57:40 -0600427 // Stop the current watchdog if any
428 r = sd_bus_call_method(bus, busname, objname, iface,
429 "stop", &error, &reply, NULL);
430 if(r < 0)
431 {
432 fprintf(stderr, "Failed to call the STOP method: %s\n", strerror(-r));
433 goto finish;
434 }
435
436 if (reqptr->t_use & 0x40)
437 {
438 sd_bus_error_free(&error);
439 reply = sd_bus_message_unref(reply);
440
441 // Start the watchdog if requested
442 r = sd_bus_call_method(bus, busname, objname, iface,
443 "start", &error, &reply, NULL);
444 if(r < 0)
445 {
446 fprintf(stderr, "Failed to call the START method: %s\n", strerror(-r));
447 }
448 }
449
450finish:
451 sd_bus_error_free(&error);
452 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500453 free(busname);
vishwa1eaea4f2016-02-26 11:57:40 -0600454
455 return (r < 0) ? -1 : IPMI_CC_OK;
Chris Austen6caf28b2015-10-13 12:40:40 -0500456}
457
458
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500459ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
460 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500461 ipmi_data_len_t data_len, ipmi_context_t context)
462{
Chris Austen454acfe2015-10-29 23:03:34 -0500463 const char *objname = "/org/openbmc/watchdog/host0";
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500464 const char *iface = "org.openbmc.Watchdog";
vishwa1eaea4f2016-02-26 11:57:40 -0600465 sd_bus_message *reply = NULL;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500466 sd_bus_error error = SD_BUS_ERROR_NULL;
467 int r = 0;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500468 char *busname = NULL;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500469
Chris Austen6caf28b2015-10-13 12:40:40 -0500470 // Status code.
471 ipmi_ret_t rc = IPMI_CC_OK;
472 *data_len = 0;
473
474 printf("WATCHDOG RESET\n");
Sergey Solomineb9b8142016-08-23 09:07:28 -0500475 // Get bus name
476 r = mapper_get_service(bus, objname, &busname);
477 if (r < 0) {
478 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
479 goto finish;
480 }
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500481 // Refresh watchdog
vishwa1eaea4f2016-02-26 11:57:40 -0600482 r = sd_bus_call_method(bus, busname, objname, iface,
483 "poke", &error, &reply, NULL);
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500484 if (r < 0) {
vishwa1eaea4f2016-02-26 11:57:40 -0600485 fprintf(stderr, "Failed to add reset watchdog: %s\n", strerror(-r));
486 rc = -1;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500487 }
488
Sergey Solomineb9b8142016-08-23 09:07:28 -0500489finish:
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500490 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600491 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500492 free(busname);
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500493
Chris Austen6caf28b2015-10-13 12:40:40 -0500494 return rc;
495}
496
Chris Austenc2cd29d2016-02-05 20:02:29 -0600497// ATTENTION: This ipmi function is very hardcoded on purpose
498// OpenBMC does not fully support IPMI. This command is useful
499// to have around because it enables testing of interfaces with
500// the IPMI tool.
501#define GET_CHANNEL_INFO_CHANNEL_OFFSET 0
502// IPMI Table 6-2
503#define IPMI_CHANNEL_TYPE_IPMB 1
504// IPMI Table 6-3
505#define IPMI_CHANNEL_MEDIUM_TYPE_OTHER 6
506
507ipmi_ret_t ipmi_app_channel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
508 ipmi_request_t request, ipmi_response_t response,
509 ipmi_data_len_t data_len, ipmi_context_t context)
510{
511 ipmi_ret_t rc = IPMI_CC_OK;
512 uint8_t resp[] = {
513 1,
514 IPMI_CHANNEL_MEDIUM_TYPE_OTHER,
515 IPMI_CHANNEL_TYPE_IPMB,
516 1,0x41,0xA7,0x00,0,0};
517 uint8_t *p = (uint8_t*) request;
518
519 printf("IPMI APP GET CHANNEL INFO\n");
520
tomjose7ec0add2016-06-27 07:59:28 -0500521 // The supported channels numbers are 1 and 8.
522 // Channel Number E is used as way to identify the current channel
523 // that the command is being is received from.
tomjose13fb4412016-03-08 14:02:34 -0600524 if (*p == 0xe || *p == 1 || *p == 8) {
Chris Austenc2cd29d2016-02-05 20:02:29 -0600525
526 *data_len = sizeof(resp);
527 memcpy(response, resp, *data_len);
528
529 } else {
530 rc = IPMI_CC_PARM_OUT_OF_RANGE;
531 *data_len = 0;
532 }
533
534 return rc;
535}
536
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500537ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
538 ipmi_request_t request, ipmi_response_t response,
539 ipmi_data_len_t data_len, ipmi_context_t context)
540{
541 ipmi_ret_t rc = IPMI_CC_OK;
542 *data_len = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500543
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500544 // Event and message logging enabled by default so return for now
545 printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
546
547 return rc;
548}
Chris Austen6caf28b2015-10-13 12:40:40 -0500549
550
551
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500552ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
553 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530554 ipmi_data_len_t data_len, ipmi_context_t context)
555{
556 printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
557
558 // Status code.
559 ipmi_ret_t rc = IPMI_CC_OK;
560
561 *data_len = strlen("THIS IS WILDCARD");
562
563 // Now pack actual response
564 memcpy(response, "THIS IS WILDCARD", *data_len);
565
566 return rc;
567}
568
Chris Austen6caf28b2015-10-13 12:40:40 -0500569void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530570{
571 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT);
Chris Austen6caf28b2015-10-13 12:40:40 -0500572 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities);
573
574 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD);
575 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler);
576
577 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD);
578 ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog);
579
580 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD);
581 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog);
582
583 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID);
584 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id);
585
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500586 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID);
587 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid);
588
Chris Austen6caf28b2015-10-13 12:40:40 -0500589 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI);
590 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state);
591
592 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
593 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event);
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500594
595 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
596 IPMI_CMD_SET_BMC_GLOBAL_ENABLES);
597 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
598 ipmi_app_set_bmc_global_enables);
599
vishwa36993272015-11-20 12:43:49 -0600600 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS);
601 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags);
602
Chris Austenc2cd29d2016-02-05 20:02:29 -0600603
604 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO);
605 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info);
606
607
608
vishwabmcba0bd5f2015-09-30 16:50:23 +0530609 return;
610}
611
Chris Austen6caf28b2015-10-13 12:40:40 -0500612