Skip to content

Commit

Permalink
Merge pull request #8 from causten/rollingesels
Browse files Browse the repository at this point in the history
Rollingesels
  • Loading branch information
nkskjames committed Feb 29, 2016
2 parents b7df30e + ba54afb commit caa755e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 205 deletions.
11 changes: 2 additions & 9 deletions Makefile
@@ -1,26 +1,19 @@
CXX ?= $(CROSS_COMPILE)g++

TESTER = testit
TESTER_OBJ = testit.o oemhandler.o

LIB_OEM_OBJ = oemhandler.o
LIB_OEM = liboemhandler.so

LDFLAGS += -rdynamic -ldl
CXXFLAGS += -fPIC -Wall


all: $(TESTER) $(LIB_OEM)
all: $(LIB_OEM)

%.o: %.C
$(CXX) -c $< $(CXXFLAGS) -o $@


$(LIB_OEM): $(LIB_OEM_OBJ)
$(CXX) $^ -shared $(LDFLAGS) -o $@

$(TESTER): $(TESTER_OBJ)
$(CXX) $^ $(LDFLAGS) $(LIB_FLAG) -o $@ -ldl

clean:
$(RM) $(LIB_OEM_OBJ) $(LIB_OEM) $(TESTER_OBJ) $(TESTER)
$(RM) $(LIB_OEM_OBJ) $(LIB_OEM)
103 changes: 48 additions & 55 deletions oemhandler.C
Expand Up @@ -5,7 +5,7 @@

void register_netfn_oem_partial_esel() __attribute__((constructor));

const char *g_esel_path = "/tmp/";
const char *g_esel_path = "/tmp/esel";
uint16_t g_record_id = 0x0001;


Expand All @@ -16,7 +16,7 @@ uint16_t g_record_id = 0x0001;
// of 0xDF and Event Message format of 0x04. The returned
// Record ID should be used for all partial eSEL adds.
//
// This function creates a /tmp/esel# file to store the
// This function creates a /tmp/esel file to store the
// incoming partial esel. It is the role of some other
// function to commit the error log in to long term
// storage. Likely via the ipmi add_sel command.
Expand All @@ -25,62 +25,55 @@ ipmi_ret_t ipmi_ibm_oem_partial_esel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
ipmi_request_t request, ipmi_response_t response,
ipmi_data_len_t data_len, ipmi_context_t context)
{
esel_request_t *reqptr = (esel_request_t*) request;
FILE *fp;
// TODO: Issue 5: This is not endian-safe.
short *recid = (short*) &reqptr->selrecordls;
short *offset = (short*) &reqptr->offsetls;
uint8_t rlen;
ipmi_ret_t rc = IPMI_CC_OK;
char string[64];
const char *pio;


if (!*recid && !*offset) {
// OpenPOWER Host Interface spec says if RecordID and Offset are
// 0 then then this is a new request
pio = "wb";
snprintf(string, sizeof(string), "%s%s%04x", g_esel_path, "esel", g_record_id);
} else {
pio = "rb+";
snprintf(string, sizeof(string), "%s%s%02x%02x", g_esel_path, "esel", reqptr->selrecordms, reqptr->selrecordls);
}

rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t));


printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n",
string, *offset, rlen);


if ((fp = fopen(string, pio)) != NULL) {
fseek(fp, *offset, SEEK_SET);
fwrite(reqptr+1,rlen,1,fp);
fclose(fp);

*data_len = sizeof(g_record_id);
memcpy(response, &g_record_id, *data_len);
} else {
fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, string);
rc = IPMI_CC_INVALID;
*data_len = 0;
}

// The first bit prepresents that this is the last partial packet
// coming down. If that is the case advance the record id so we
// don't overlap logs. This allows anyone to establish a log
// directory system.
if (reqptr->progress & 1 ) {
g_record_id++;
}

return rc;
esel_request_t *reqptr = (esel_request_t*) request;
FILE *fp;
// TODO: Issue 5: This is not endian-safe.
short *recid = (short*) &reqptr->selrecordls;
short *offset = (short*) &reqptr->offsetls;
uint8_t rlen;
ipmi_ret_t rc = IPMI_CC_OK;
const char *pio;

// OpenPOWER Host Interface spec says if RecordID and Offset are
// 0 then then this is a new request
if (!*recid && !*offset)
pio = "wb";
else
pio = "rb+";

rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t));

printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n",
g_esel_path, *offset, rlen);

if ((fp = fopen(g_esel_path, pio)) != NULL) {
fseek(fp, *offset, SEEK_SET);
fwrite(reqptr+1,rlen,1,fp);
fclose(fp);

*data_len = sizeof(g_record_id);
memcpy(response, &g_record_id, *data_len);
} else {
fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, g_esel_path);
rc = IPMI_CC_INVALID;
*data_len = 0;
}

// The first bit prepresents that this is the last partial packet
// coming down. If that is the case advance the record id so we
// don't overlap logs. This allows anyone to establish a log
// directory system.
if (reqptr->progress & 1 ) {
g_record_id++;
}

return rc;
}


void register_netfn_oem_partial_esel()
{
printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL);
ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel);
return;
printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL);
ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel);
return;
}
141 changes: 0 additions & 141 deletions testit.C

This file was deleted.

0 comments on commit caa755e

Please sign in to comment.