blob: c19d9ce21fa8d65e7690ad041f475f8175652ac2 [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/";
9uint16_t g_record_id = 0x0100;
10
11
12#define LSMSSWAP(x,y) ((y)<<8|(x))
13
14
15///////////////////////////////////////////////////////////////////////////////
Patrick Williams24fa5a92015-10-30 14:53:57 -050016// For the First partial add eSEL the SEL Record ID and offset
17// value should be 0x0000. The extended data needs to be in
18// the form of an IPMI SEL Event Record, with Event sensor type
19// of 0xDF and Event Message format of 0x04. The returned
Chris Austen4d98c1e2015-10-13 14:33:50 -050020// Record ID should be used for all partial eSEL adds.
21//
Patrick Williams24fa5a92015-10-30 14:53:57 -050022// This function creates a /tmp/esel# file to store the
Chris Austen4d98c1e2015-10-13 14:33:50 -050023// incoming partial esel. It is the role of some other
Patrick Williams24fa5a92015-10-30 14:53:57 -050024// function to commit the error log in to long term
25// storage. Likely via the ipmi add_sel command.
Chris Austen4d98c1e2015-10-13 14:33:50 -050026///////////////////////////////////////////////////////////////////////////////
Patrick Williams24fa5a92015-10-30 14:53:57 -050027ipmi_ret_t ipmi_ibm_oem_partial_esel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
Chris Austen17160ce2015-10-30 11:44:38 -050028 ipmi_request_t request, ipmi_response_t response,
29 ipmi_data_len_t data_len, ipmi_context_t context)
Chris Austen4d98c1e2015-10-13 14:33:50 -050030{
31 esel_request_t *reqptr = (esel_request_t*) request;
32 FILE *fp;
Chris Austen17160ce2015-10-30 11:44:38 -050033 short recid, offset = 0;
Chris Austen4d98c1e2015-10-13 14:33:50 -050034 uint8_t rlen;
35 ipmi_ret_t rc = IPMI_CC_OK;
36 char string[64];
37 const char *pio;
38
Chris Austen17160ce2015-10-30 11:44:38 -050039 recid = LSMSSWAP(reqptr->selrecordls, reqptr->selrecordms);
Chris Austen4d98c1e2015-10-13 14:33:50 -050040 offset = LSMSSWAP(reqptr->offsetls, reqptr->offsetms);
41
Chris Austen17160ce2015-10-30 11:44:38 -050042 if (!recid && !offset) {
43 // OpenPOWER Host Interface spec says if RecordID and Offset are
44 // 0 then then this is a new request
45 pio = "wb";
46 snprintf(string, sizeof(string), "%s%s%02x%02x", g_esel_path, "esel", (g_record_id&0xFF00>>8), (g_record_id&0xFF));
47 } else {
48 pio = "rb+";
49 snprintf(string, sizeof(string), "%s%s%02x%02x", g_esel_path, "esel", reqptr->selrecordms, reqptr->selrecordls);
50 }
Chris Austen4d98c1e2015-10-13 14:33:50 -050051
52 // Length is the number of request bytes minus the header itself.
53 // The header contains an extra byte to indicate the start of
54 // the data (so didn't need to worry about word/byte boundaries)
55 // hence the -1...
56 rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t));
57
58
Patrick Williams24fa5a92015-10-30 14:53:57 -050059 printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n",
Chris Austen4d98c1e2015-10-13 14:33:50 -050060 string, offset, rlen);
61
62
Chris Austen4d98c1e2015-10-13 14:33:50 -050063 if ((fp = fopen(string, pio)) != NULL) {
64 fseek(fp, offset, SEEK_SET);
65 fwrite(reqptr+1,rlen,1,fp);
66 fclose(fp);
67
Chris Austen4d98c1e2015-10-13 14:33:50 -050068 *data_len = sizeof(g_record_id);
69 memcpy(response, &g_record_id, *data_len);
Chris Austen4d98c1e2015-10-13 14:33:50 -050070 } else {
71 fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, string);
72 rc = IPMI_CC_INVALID;
73 *data_len = 0;
74 }
Patrick Williams24fa5a92015-10-30 14:53:57 -050075
Chris Austen4d98c1e2015-10-13 14:33:50 -050076 return rc;
77}
78
79
80void register_netfn_oem_partial_esel()
81{
82 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL);
83 ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel);
84 return;
85}