Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 1 | #include "oemhandler.h" |
| 2 | #include <host-ipmid/ipmid-api.h> |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | void register_netfn_oem_partial_esel() __attribute__((constructor)); |
| 7 | |
| 8 | const char *g_esel_path = "/tmp/"; |
| 9 | uint16_t g_record_id = 0x0100; |
| 10 | |
| 11 | |
| 12 | #define LSMSSWAP(x,y) ((y)<<8|(x)) |
| 13 | |
| 14 | |
| 15 | /////////////////////////////////////////////////////////////////////////////// |
| 16 | // 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 |
| 20 | // Record ID should be used for all partial eSEL adds. |
| 21 | // |
| 22 | // This function creates a /tmp/esel# file to store the |
| 23 | // incoming partial esel. It is the role of some other |
| 24 | // function to commit the error log in to long term |
| 25 | // storage. Likely via the ipmi add_sel command. |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
| 27 | ipmi_ret_t ipmi_ibm_oem_partial_esel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 28 | ipmi_request_t request, ipmi_response_t response, |
| 29 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 30 | { |
| 31 | esel_request_t *reqptr = (esel_request_t*) request; |
| 32 | FILE *fp; |
| 33 | short offset = 0; |
| 34 | uint8_t rlen; |
| 35 | ipmi_ret_t rc = IPMI_CC_OK; |
| 36 | char string[64]; |
| 37 | const char *pio; |
| 38 | |
| 39 | |
| 40 | offset = LSMSSWAP(reqptr->offsetls, reqptr->offsetms); |
| 41 | |
| 42 | snprintf(string, sizeof(string), "%s%s%02x%02x", g_esel_path, "esel", reqptr->selrecordms, reqptr->selrecordls); |
| 43 | |
| 44 | |
| 45 | // Length is the number of request bytes minus the header itself. |
| 46 | // The header contains an extra byte to indicate the start of |
| 47 | // the data (so didn't need to worry about word/byte boundaries) |
| 48 | // hence the -1... |
| 49 | rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t)); |
| 50 | |
| 51 | |
| 52 | printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n", |
| 53 | string, offset, rlen); |
| 54 | |
| 55 | |
| 56 | // Rules state for a Partial eSel that the first write of a |
| 57 | // new esel will be the sensor data record. We will use that |
| 58 | // to indicate this is a new record rather then an ofset in |
| 59 | // my next commit TODO |
| 60 | if (offset == 0) { |
| 61 | pio = "wb"; |
| 62 | } else { |
| 63 | pio = "rb+"; |
| 64 | } |
| 65 | |
| 66 | if ((fp = fopen(string, pio)) != NULL) { |
| 67 | fseek(fp, offset, SEEK_SET); |
| 68 | fwrite(reqptr+1,rlen,1,fp); |
| 69 | fclose(fp); |
| 70 | |
| 71 | |
| 72 | *data_len = sizeof(g_record_id); |
| 73 | memcpy(response, &g_record_id, *data_len); |
| 74 | |
| 75 | |
| 76 | } else { |
| 77 | fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, string); |
| 78 | rc = IPMI_CC_INVALID; |
| 79 | *data_len = 0; |
| 80 | } |
| 81 | |
| 82 | return rc; |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void register_netfn_oem_partial_esel() |
| 87 | { |
| 88 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL); |
| 89 | ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel); |
| 90 | return; |
| 91 | } |