blob: 61afac1fb1aa56c09d5bbc5b2f1422758c3e9e60 [file] [log] [blame]
Chris Austen4d98c1e2015-10-13 14:33:50 -05001#include "oemhandler.h"
2#include <host-ipmid/ipmid-api.h>
3#include <stdio.h>
4#include <string.h>
5
6void register_netfn_oem_partial_esel() __attribute__((constructor));
7
8const char *g_esel_path = "/tmp/";
Chris Austen29a8e0f2015-10-30 11:44:38 -05009uint16_t g_record_id = 0x0001;
Chris Austen4d98c1e2015-10-13 14:33:50 -050010
11
12///////////////////////////////////////////////////////////////////////////////
Patrick Williams24fa5a92015-10-30 14:53:57 -050013// For the First partial add eSEL the SEL Record ID and offset
14// value should be 0x0000. The extended data needs to be in
15// the form of an IPMI SEL Event Record, with Event sensor type
16// of 0xDF and Event Message format of 0x04. The returned
Chris Austen4d98c1e2015-10-13 14:33:50 -050017// Record ID should be used for all partial eSEL adds.
18//
Patrick Williams24fa5a92015-10-30 14:53:57 -050019// This function creates a /tmp/esel# file to store the
Chris Austen4d98c1e2015-10-13 14:33:50 -050020// incoming partial esel. It is the role of some other
Patrick Williams24fa5a92015-10-30 14:53:57 -050021// function to commit the error log in to long term
22// storage. Likely via the ipmi add_sel command.
Chris Austen4d98c1e2015-10-13 14:33:50 -050023///////////////////////////////////////////////////////////////////////////////
Patrick Williams24fa5a92015-10-30 14:53:57 -050024ipmi_ret_t ipmi_ibm_oem_partial_esel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Chris Austen17160ce2015-10-30 11:44:38 -050025 ipmi_request_t request, ipmi_response_t response,
26 ipmi_data_len_t data_len, ipmi_context_t context)
Chris Austen4d98c1e2015-10-13 14:33:50 -050027{
28 esel_request_t *reqptr = (esel_request_t*) request;
29 FILE *fp;
Chris Austen29a8e0f2015-10-30 11:44:38 -050030 // TODO: Issue 5: This is not endian-safe.
31 short *recid = (short*) &reqptr->selrecordls;
32 short *offset = (short*) &reqptr->offsetls;
Chris Austen4d98c1e2015-10-13 14:33:50 -050033 uint8_t rlen;
34 ipmi_ret_t rc = IPMI_CC_OK;
35 char string[64];
36 const char *pio;
37
Chris Austen4d98c1e2015-10-13 14:33:50 -050038
Chris Austen29a8e0f2015-10-30 11:44:38 -050039 if (!*recid && !*offset) {
Chris Austen17160ce2015-10-30 11:44:38 -050040 // OpenPOWER Host Interface spec says if RecordID and Offset are
41 // 0 then then this is a new request
42 pio = "wb";
Chris Austen29a8e0f2015-10-30 11:44:38 -050043 snprintf(string, sizeof(string), "%s%s%04x", g_esel_path, "esel", g_record_id);
Chris Austen17160ce2015-10-30 11:44:38 -050044 } else {
45 pio = "rb+";
46 snprintf(string, sizeof(string), "%s%s%02x%02x", g_esel_path, "esel", reqptr->selrecordms, reqptr->selrecordls);
47 }
Chris Austen4d98c1e2015-10-13 14:33:50 -050048
49 // Length is the number of request bytes minus the header itself.
50 // The header contains an extra byte to indicate the start of
51 // the data (so didn't need to worry about word/byte boundaries)
52 // hence the -1...
53 rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t));
54
55
Patrick Williams24fa5a92015-10-30 14:53:57 -050056 printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n",
Chris Austen29a8e0f2015-10-30 11:44:38 -050057 string, *offset, rlen);
Chris Austen4d98c1e2015-10-13 14:33:50 -050058
59
Chris Austen4d98c1e2015-10-13 14:33:50 -050060 if ((fp = fopen(string, pio)) != NULL) {
Chris Austen29a8e0f2015-10-30 11:44:38 -050061 fseek(fp, *offset, SEEK_SET);
Chris Austen4d98c1e2015-10-13 14:33:50 -050062 fwrite(reqptr+1,rlen,1,fp);
63 fclose(fp);
64
Chris Austen4d98c1e2015-10-13 14:33:50 -050065 *data_len = sizeof(g_record_id);
66 memcpy(response, &g_record_id, *data_len);
Chris Austen4d98c1e2015-10-13 14:33:50 -050067 } else {
68 fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, string);
69 rc = IPMI_CC_INVALID;
70 *data_len = 0;
71 }
Patrick Williams24fa5a92015-10-30 14:53:57 -050072
Chris Austen4d98c1e2015-10-13 14:33:50 -050073 return rc;
74}
75
76
77void register_netfn_oem_partial_esel()
78{
79 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL);
80 ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel);
81 return;
82}