blob: dd1d5aa96c4948a90517f8c0afc4eee003f66f50 [file] [log] [blame]
vishwabmcba0bd5f2015-09-30 16:50:23 +05301#include "apphandler.h"
Patrick Williams37af7332016-09-02 21:21:42 -05002#include "host-ipmid/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;
Chris Austen176c9652016-04-30 16:32:17 -0500131 uint16_t commits;
Chris Austen7303bdc2016-04-17 11:50:54 -0500132
133 if (*p != 'v')
134 return -1;
135 p++;
136
137 s = strdup(p);
138 token = strtok(s,".-");
139
140 rev->major = (int8_t) atoi(token);
141
142 token = strtok(NULL, ".-");
143 rev->minor = (int8_t) atoi(token);
144
145 // Capture the number of commits on top of the minor tag.
146 // I'm using BE format like the ipmi spec asked for
147 token = strtok(NULL,".-");
Chris Austen7303bdc2016-04-17 11:50:54 -0500148
Chris Austen176c9652016-04-30 16:32:17 -0500149 if (token) {
150 commits = (int16_t) atoi(token);
151 rev->d[0] = (commits>>8) | (commits<<8);
Chris Austen7303bdc2016-04-17 11:50:54 -0500152
Chris Austen176c9652016-04-30 16:32:17 -0500153 // commit number we skip
154 token = strtok(NULL,".-");
Chris Austen7303bdc2016-04-17 11:50:54 -0500155
Chris Austen176c9652016-04-30 16:32:17 -0500156 } else {
157 rev->d[0] = 0;
158 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500159
160 // Any value of the optional parameter forces it to 1
Chris Austen176c9652016-04-30 16:32:17 -0500161 if (token)
162 token = strtok(NULL,".-");
163
164 rev->d[1] = (token != NULL) ? 1 : 0;
Chris Austen7303bdc2016-04-17 11:50:54 -0500165
166 free(s);
167 return 0;
168}
169
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500170ipmi_ret_t ipmi_app_get_device_id(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
171 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500172 ipmi_data_len_t data_len, ipmi_context_t context)
173{
174 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen7303bdc2016-04-17 11:50:54 -0500175 const char *objname = "/org/openbmc/inventory/system/chassis/motherboard/bmc";
176 const char *iface = "org.openbmc.InventoryItem";
177 char *ver = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500178 char *busname = NULL;
Chris Austen7303bdc2016-04-17 11:50:54 -0500179 int r;
180 rev_t rev = {0};
Nan Liee0cb902016-07-11 15:38:03 +0800181 ipmi_device_id_t dev_id{};
Chris Austen6caf28b2015-10-13 12:40:40 -0500182
183 // Data length
Chris Austen7303bdc2016-04-17 11:50:54 -0500184 *data_len = sizeof(dev_id);
185
Nan Liee0cb902016-07-11 15:38:03 +0800186 // From IPMI spec, controller that have different application commands, or different
187 // definitions of OEM fields, are expected to have different Device ID values.
188 // Set to 0 now.
189
190 // Device Revision is set to 0 now.
191 // Bit7 identifies if device provide Device SDRs, obmc don't have SDR,we use ipmi to
192 // simulate SDR, hence the value:
193 dev_id.revision = 0x80;
194
195 // Firmware revision is already implemented, so get it from appropriate position.
Sergey Solomineb9b8142016-08-23 09:07:28 -0500196 r = mapper_get_service(bus, objname, &busname);
197 if (r < 0) {
198 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
199 goto finish;
200 }
Chris Austen7303bdc2016-04-17 11:50:54 -0500201 r = sd_bus_get_property_string(bus,busname,objname,iface,"version", NULL, &ver);
202 if ( r < 0 ) {
203 fprintf(stderr, "Failed to obtain version property: %s\n", strerror(-r));
204 } else {
205 r = convert_version(ver, &rev);
206 if( r >= 0 ) {
Nan Liee0cb902016-07-11 15:38:03 +0800207 // bit7 identifies if the device is available, 0=normal operation,
208 // 1=device firmware, SDR update or self-initialization in progress.
209 // our SDR is normal working condition, so mask:
210 dev_id.fw[0] = 0x7F & rev.major;
Adriana Kobylak0e912642016-06-22 16:54:39 -0500211
212 rev.minor = (rev.minor > 99 ? 99 : rev.minor);
Nan Liee0cb902016-07-11 15:38:03 +0800213 dev_id.fw[1] = rev.minor % 10 + (rev.minor / 10) * 16;
214 memcpy(&dev_id.aux, rev.d, 4);
Chris Austen7303bdc2016-04-17 11:50:54 -0500215 }
216 }
Chris Austen6caf28b2015-10-13 12:40:40 -0500217
Nan Liee0cb902016-07-11 15:38:03 +0800218 // IPMI Spec verison 2.0
219 dev_id.ipmi_ver = 2;
220
221 // Additional device Support.
222 // List the 'logical device' commands and functions that the controller supports
223 // that are in addition to the mandatory IPM and Application commands.
224 // [7] Chassis Device (device functions as chassis device per ICMB spec.)
225 // [6] Bridge (device responds to Bridge NetFn commands)
226 // [5] IPMB Event Generator
227 // [4] IPMB Event Receiver
228 // [3] FRU Inventory Device
229 // [2] SEL Device
230 // [1] SDR Repository Device
231 // [0] Sensor Device
232 // We support FRU/SEL/Sensor now:
233 dev_id.addn_dev_support = 0x8D;
234
235 // This value is the IANA number assigned to "IBM Platform Firmware
236 // Division", which is also used by our service processor. We may want
237 // a different number or at least a different version?
238 dev_id.manuf_id[0] = 0x41;
239 dev_id.manuf_id[1] = 0xA7;
240 dev_id.manuf_id[2] = 0x00;
241
242 // Witherspoon's product ID is hardcoded to 4F42(ASCII 'OB').
243 // TODO: openbmc/openbmc#495
244 dev_id.prod_id[0] = 0x4F;
245 dev_id.prod_id[1] = 0x42;
246
Chris Austen6caf28b2015-10-13 12:40:40 -0500247 // Pack the actual response
Chris Austen7303bdc2016-04-17 11:50:54 -0500248 memcpy(response, &dev_id, *data_len);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500249finish:
250 free(busname);
Chris Austen6caf28b2015-10-13 12:40:40 -0500251 return rc;
252}
253
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500254ipmi_ret_t ipmi_app_get_device_guid(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
255 ipmi_request_t request, ipmi_response_t response,
256 ipmi_data_len_t data_len, ipmi_context_t context)
257{
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500258 const char *objname = "/org/openbmc/control/chassis0";
Adriana Kobylak31bccae2015-11-05 13:31:06 -0600259 const char *iface = "org.freedesktop.DBus.Properties";
260 const char *chassis_iface = "org.openbmc.control.Chassis";
vishwa1eaea4f2016-02-26 11:57:40 -0600261 sd_bus_message *reply = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500262 sd_bus_error error = SD_BUS_ERROR_NULL;
263 int r = 0;
264 char *uuid = NULL;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500265 char *busname = NULL;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500266
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500267 // UUID is in RFC4122 format. Ex: 61a39523-78f2-11e5-9862-e6402cfc3223
268 // Per IPMI Spec 2.0 need to convert to 16 hex bytes and reverse the byte order
269 // Ex: 0x2332fc2c40e66298e511f2782395a361
270
271 const int resp_size = 16; // Response is 16 hex bytes per IPMI Spec
272 uint8_t resp_uuid[resp_size]; // Array to hold the formatted response
273 int resp_loc = resp_size-1; // Point resp end of array to save in reverse order
274 int i = 0;
275 char *tokptr = NULL;
vishwa1eaea4f2016-02-26 11:57:40 -0600276 char *id_octet = NULL;
277
278 // Status code.
279 ipmi_ret_t rc = IPMI_CC_OK;
280 *data_len = 0;
281
282 printf("IPMI GET DEVICE GUID\n");
283
284 // Call Get properties method with the interface and property name
Sergey Solomineb9b8142016-08-23 09:07:28 -0500285 r = mapper_get_service(bus, objname, &busname);
286 if (r < 0) {
287 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
288 goto finish;
289 }
vishwa1eaea4f2016-02-26 11:57:40 -0600290 r = sd_bus_call_method(bus,busname,objname,iface,
291 "Get",&error, &reply, "ss",
292 chassis_iface, "uuid");
293 if (r < 0)
294 {
295 fprintf(stderr, "Failed to call Get Method: %s\n", strerror(-r));
296 rc = IPMI_CC_UNSPECIFIED_ERROR;
297 goto finish;
298 }
299
300 r = sd_bus_message_read(reply, "v", "s", &uuid);
301 if (r < 0 || uuid == NULL)
302 {
303 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
304 rc = IPMI_CC_RESPONSE_ERROR;
305 goto finish;
306 }
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500307
308 // Traverse the UUID
vishwa1eaea4f2016-02-26 11:57:40 -0600309 id_octet = strtok_r(uuid, "-", &tokptr); // Get the UUID octects separated by dash
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500310
311 if (id_octet == NULL)
vishwa1eaea4f2016-02-26 11:57:40 -0600312 {
313 // Error
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500314 fprintf(stderr, "Unexpected UUID format: %s", uuid);
vishwa1eaea4f2016-02-26 11:57:40 -0600315 rc = IPMI_CC_RESPONSE_ERROR;
316 goto finish;
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500317 }
318
319 while (id_octet != NULL)
320 {
321 // Calculate the octet string size since it varies
322 // Divide it by 2 for the array size since 1 byte is built from 2 chars
323 int tmp_size = strlen(id_octet)/2;
324
325 for(i = 0; i < tmp_size; i++)
326 {
Joel Stanley38310cd2015-11-25 17:32:08 +1030327 char tmp_array[3] = {0}; // Holder of the 2 chars that will become a byte
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500328 strncpy(tmp_array, id_octet, 2); // 2 chars at a time
329
330 int resp_byte = strtoul(tmp_array, NULL, 16); // Convert to hex byte
331 memcpy((void*)&resp_uuid[resp_loc], &resp_byte, 1); // Copy end to first
332 resp_loc--;
333 id_octet+=2; // Finished with the 2 chars, advance
334 }
335 id_octet=strtok_r(NULL, "-", &tokptr); // Get next octet
336 }
337
338 // Data length
339 *data_len = resp_size;
340
341 // Pack the actual response
342 memcpy(response, &resp_uuid, *data_len);
343
vishwa1eaea4f2016-02-26 11:57:40 -0600344finish:
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500345 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600346 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500347 free(busname);
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500348
349 return rc;
350}
Chris Austen6caf28b2015-10-13 12:40:40 -0500351
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500352ipmi_ret_t ipmi_app_get_bt_capabilities(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
353 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530354 ipmi_data_len_t data_len, ipmi_context_t context)
355{
356 printf("Handling Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
357
358 // Status code.
359 ipmi_ret_t rc = IPMI_CC_OK;
360
Chris Austen6caf28b2015-10-13 12:40:40 -0500361 uint8_t str[] = {0x01, MAX_IPMI_BUFFER, MAX_IPMI_BUFFER, 0x0A, 0x01};
vishwabmcba0bd5f2015-09-30 16:50:23 +0530362
363 // Data length
364 *data_len = sizeof(str);
365
366 // Pack the actual response
367 memcpy(response, &str, *data_len);
368
369 return rc;
370}
371
Chris Austen6caf28b2015-10-13 12:40:40 -0500372
373struct set_wd_data_t {
374 uint8_t t_use;
375 uint8_t t_action;
376 uint8_t preset;
377 uint8_t flags;
378 uint8_t ls;
379 uint8_t ms;
380} __attribute__ ((packed));
381
382
383
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500384ipmi_ret_t ipmi_app_set_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
385 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500386 ipmi_data_len_t data_len, ipmi_context_t context)
387{
Chris Austen454acfe2015-10-29 23:03:34 -0500388 const char *objname = "/org/openbmc/watchdog/host0";
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500389 const char *iface = "org.openbmc.Watchdog";
vishwa1eaea4f2016-02-26 11:57:40 -0600390 sd_bus_message *reply = NULL;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500391 sd_bus_error error = SD_BUS_ERROR_NULL;
392 int r = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500393
394 set_wd_data_t *reqptr = (set_wd_data_t*) request;
395 uint16_t timer = 0;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500396 uint32_t timer_ms = 0;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500397 char *busname = NULL;
Chris Austen6caf28b2015-10-13 12:40:40 -0500398 *data_len = 0;
399
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500400 // Get number of 100ms intervals
Chris Austen6caf28b2015-10-13 12:40:40 -0500401 timer = (((uint16_t)reqptr->ms) << 8) + reqptr->ls;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500402 // Get timer value in ms
403 timer_ms = timer * 100;
Chris Austen6caf28b2015-10-13 12:40:40 -0500404
405 printf("WATCHDOG SET Timer:[0x%X] 100ms intervals\n",timer);
406
Sergey Solomineb9b8142016-08-23 09:07:28 -0500407 // Get bus name
408 r = mapper_get_service(bus, objname, &busname);
409 if (r < 0) {
410 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
411 goto finish;
412 }
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500413 // Set watchdog timer
vishwa1eaea4f2016-02-26 11:57:40 -0600414 r = sd_bus_call_method(bus, busname, objname, iface,
415 "set", &error, &reply, "i", timer_ms);
416 if(r < 0)
Adriana Kobylak0896be32015-10-22 13:27:23 -0500417 {
vishwa1eaea4f2016-02-26 11:57:40 -0600418 fprintf(stderr, "Failed to call the SET method: %s\n", strerror(-r));
419 goto finish;
Adriana Kobylak0896be32015-10-22 13:27:23 -0500420 }
421
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500422 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600423 reply = sd_bus_message_unref(reply);
Chris Austen6caf28b2015-10-13 12:40:40 -0500424
vishwa1eaea4f2016-02-26 11:57:40 -0600425 // Stop the current watchdog if any
426 r = sd_bus_call_method(bus, busname, objname, iface,
427 "stop", &error, &reply, NULL);
428 if(r < 0)
429 {
430 fprintf(stderr, "Failed to call the STOP method: %s\n", strerror(-r));
431 goto finish;
432 }
433
434 if (reqptr->t_use & 0x40)
435 {
436 sd_bus_error_free(&error);
437 reply = sd_bus_message_unref(reply);
438
439 // Start the watchdog if requested
440 r = sd_bus_call_method(bus, busname, objname, iface,
441 "start", &error, &reply, NULL);
442 if(r < 0)
443 {
444 fprintf(stderr, "Failed to call the START method: %s\n", strerror(-r));
445 }
446 }
447
448finish:
449 sd_bus_error_free(&error);
450 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500451 free(busname);
vishwa1eaea4f2016-02-26 11:57:40 -0600452
453 return (r < 0) ? -1 : IPMI_CC_OK;
Chris Austen6caf28b2015-10-13 12:40:40 -0500454}
455
456
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500457ipmi_ret_t ipmi_app_reset_watchdog(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
458 ipmi_request_t request, ipmi_response_t response,
Chris Austen6caf28b2015-10-13 12:40:40 -0500459 ipmi_data_len_t data_len, ipmi_context_t context)
460{
Chris Austen454acfe2015-10-29 23:03:34 -0500461 const char *objname = "/org/openbmc/watchdog/host0";
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500462 const char *iface = "org.openbmc.Watchdog";
vishwa1eaea4f2016-02-26 11:57:40 -0600463 sd_bus_message *reply = NULL;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500464 sd_bus_error error = SD_BUS_ERROR_NULL;
465 int r = 0;
Sergey Solomineb9b8142016-08-23 09:07:28 -0500466 char *busname = NULL;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500467
Chris Austen6caf28b2015-10-13 12:40:40 -0500468 // Status code.
469 ipmi_ret_t rc = IPMI_CC_OK;
470 *data_len = 0;
471
472 printf("WATCHDOG RESET\n");
Sergey Solomineb9b8142016-08-23 09:07:28 -0500473 // Get bus name
474 r = mapper_get_service(bus, objname, &busname);
475 if (r < 0) {
476 fprintf(stderr, "Failed to get bus name, return value: %s.\n", strerror(-r));
477 goto finish;
478 }
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500479 // Refresh watchdog
vishwa1eaea4f2016-02-26 11:57:40 -0600480 r = sd_bus_call_method(bus, busname, objname, iface,
481 "poke", &error, &reply, NULL);
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500482 if (r < 0) {
vishwa1eaea4f2016-02-26 11:57:40 -0600483 fprintf(stderr, "Failed to add reset watchdog: %s\n", strerror(-r));
484 rc = -1;
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500485 }
486
Sergey Solomineb9b8142016-08-23 09:07:28 -0500487finish:
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500488 sd_bus_error_free(&error);
vishwa1eaea4f2016-02-26 11:57:40 -0600489 reply = sd_bus_message_unref(reply);
Sergey Solomineb9b8142016-08-23 09:07:28 -0500490 free(busname);
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500491
Chris Austen6caf28b2015-10-13 12:40:40 -0500492 return rc;
493}
494
Chris Austenc2cd29d2016-02-05 20:02:29 -0600495// ATTENTION: This ipmi function is very hardcoded on purpose
496// OpenBMC does not fully support IPMI. This command is useful
497// to have around because it enables testing of interfaces with
498// the IPMI tool.
499#define GET_CHANNEL_INFO_CHANNEL_OFFSET 0
500// IPMI Table 6-2
501#define IPMI_CHANNEL_TYPE_IPMB 1
502// IPMI Table 6-3
503#define IPMI_CHANNEL_MEDIUM_TYPE_OTHER 6
504
505ipmi_ret_t ipmi_app_channel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
506 ipmi_request_t request, ipmi_response_t response,
507 ipmi_data_len_t data_len, ipmi_context_t context)
508{
509 ipmi_ret_t rc = IPMI_CC_OK;
510 uint8_t resp[] = {
511 1,
512 IPMI_CHANNEL_MEDIUM_TYPE_OTHER,
513 IPMI_CHANNEL_TYPE_IPMB,
514 1,0x41,0xA7,0x00,0,0};
515 uint8_t *p = (uint8_t*) request;
516
517 printf("IPMI APP GET CHANNEL INFO\n");
518
tomjose7ec0add2016-06-27 07:59:28 -0500519 // The supported channels numbers are 1 and 8.
520 // Channel Number E is used as way to identify the current channel
521 // that the command is being is received from.
tomjose13fb4412016-03-08 14:02:34 -0600522 if (*p == 0xe || *p == 1 || *p == 8) {
Chris Austenc2cd29d2016-02-05 20:02:29 -0600523
524 *data_len = sizeof(resp);
525 memcpy(response, resp, *data_len);
526
527 } else {
528 rc = IPMI_CC_PARM_OUT_OF_RANGE;
529 *data_len = 0;
530 }
531
532 return rc;
533}
534
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500535ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
536 ipmi_request_t request, ipmi_response_t response,
537 ipmi_data_len_t data_len, ipmi_context_t context)
538{
539 ipmi_ret_t rc = IPMI_CC_OK;
540 *data_len = 0;
Chris Austen6caf28b2015-10-13 12:40:40 -0500541
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500542 // Event and message logging enabled by default so return for now
543 printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
544
545 return rc;
546}
Chris Austen6caf28b2015-10-13 12:40:40 -0500547
548
549
Adriana Kobylak3a552e12015-10-19 16:11:00 -0500550ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
551 ipmi_request_t request, ipmi_response_t response,
vishwabmcba0bd5f2015-09-30 16:50:23 +0530552 ipmi_data_len_t data_len, ipmi_context_t context)
553{
554 printf("Handling WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
555
556 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +0800557 ipmi_ret_t rc = IPMI_CC_INVALID;
vishwabmcba0bd5f2015-09-30 16:50:23 +0530558
559 *data_len = strlen("THIS IS WILDCARD");
560
561 // Now pack actual response
562 memcpy(response, "THIS IS WILDCARD", *data_len);
563
564 return rc;
565}
566
Chris Austen6caf28b2015-10-13 12:40:40 -0500567void register_netfn_app_functions()
vishwabmcba0bd5f2015-09-30 16:50:23 +0530568{
569 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CAP_BIT);
Chris Austen6caf28b2015-10-13 12:40:40 -0500570 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CAP_BIT, NULL, ipmi_app_get_bt_capabilities);
571
572 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_WILDCARD);
573 ipmi_register_callback(NETFUN_APP, IPMI_CMD_WILDCARD, NULL, ipmi_app_wildcard_handler);
574
575 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_RESET_WD);
576 ipmi_register_callback(NETFUN_APP, IPMI_CMD_RESET_WD, NULL, ipmi_app_reset_watchdog);
577
578 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_WD);
579 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_WD, NULL, ipmi_app_set_watchdog);
580
581 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_ID);
582 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_ID, NULL, ipmi_app_get_device_id);
583
Adriana Kobylakd100ee52015-10-20 17:02:37 -0500584 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID);
585 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_DEVICE_GUID, NULL, ipmi_app_get_device_guid);
586
Chris Austen6caf28b2015-10-13 12:40:40 -0500587 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI);
588 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state);
589
590 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
591 ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event);
Adriana Kobylakdfc8d772015-10-20 09:34:48 -0500592
593 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
594 IPMI_CMD_SET_BMC_GLOBAL_ENABLES);
595 ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
596 ipmi_app_set_bmc_global_enables);
597
vishwa36993272015-11-20 12:43:49 -0600598 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS);
599 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags);
600
Chris Austenc2cd29d2016-02-05 20:02:29 -0600601
602 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO);
603 ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info);
604
605
606
vishwabmcba0bd5f2015-09-30 16:50:23 +0530607 return;
608}
609
Chris Austen6caf28b2015-10-13 12:40:40 -0500610