blob: f577d67e61d24657f9950873a895a70702dddf3f [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
Chris Austenfcafccf2016-02-19 23:15:57 -06008const char *g_esel_path = "/tmp/esel";
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//
Chris Austenba54afb2016-02-19 23:18:42 -060019// 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{
Chris Austenba54afb2016-02-19 23:18:42 -060028 esel_request_t *reqptr = (esel_request_t*) request;
29 FILE *fp;
30 // TODO: Issue 5: This is not endian-safe.
31 short *recid = (short*) &reqptr->selrecordls;
32 short *offset = (short*) &reqptr->offsetls;
33 uint8_t rlen;
34 ipmi_ret_t rc = IPMI_CC_OK;
35 const char *pio;
Chris Austen4d98c1e2015-10-13 14:33:50 -050036
Chris Austenba54afb2016-02-19 23:18:42 -060037 // OpenPOWER Host Interface spec says if RecordID and Offset are
38 // 0 then then this is a new request
39 if (!*recid && !*offset)
40 pio = "wb";
41 else
42 pio = "rb+";
Chris Austen4d98c1e2015-10-13 14:33:50 -050043
Chris Austenba54afb2016-02-19 23:18:42 -060044 rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t));
Chris Austen4d98c1e2015-10-13 14:33:50 -050045
Chris Austenba54afb2016-02-19 23:18:42 -060046 printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n",
47 g_esel_path, *offset, rlen);
Chris Austen4d98c1e2015-10-13 14:33:50 -050048
Chris Austenba54afb2016-02-19 23:18:42 -060049 if ((fp = fopen(g_esel_path, pio)) != NULL) {
50 fseek(fp, *offset, SEEK_SET);
51 fwrite(reqptr+1,rlen,1,fp);
52 fclose(fp);
Chris Austen4d98c1e2015-10-13 14:33:50 -050053
Chris Austenba54afb2016-02-19 23:18:42 -060054 *data_len = sizeof(g_record_id);
55 memcpy(response, &g_record_id, *data_len);
56 } else {
57 fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, g_esel_path);
58 rc = IPMI_CC_INVALID;
59 *data_len = 0;
60 }
Chris Austen4d98c1e2015-10-13 14:33:50 -050061
Chris Austenba54afb2016-02-19 23:18:42 -060062 // The first bit prepresents that this is the last partial packet
63 // coming down. If that is the case advance the record id so we
64 // don't overlap logs. This allows anyone to establish a log
65 // directory system.
66 if (reqptr->progress & 1 ) {
67 g_record_id++;
68 }
Chris Austen4d98c1e2015-10-13 14:33:50 -050069
Chris Austenba54afb2016-02-19 23:18:42 -060070 return rc;
Chris Austen4d98c1e2015-10-13 14:33:50 -050071}
72
73
74void register_netfn_oem_partial_esel()
75{
Chris Austenba54afb2016-02-19 23:18:42 -060076 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL);
77 ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel);
78 return;
Chris Austen4d98c1e2015-10-13 14:33:50 -050079}