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 | |
Chris Austen | fcafccf | 2016-02-19 23:15:57 -0600 | [diff] [blame^] | 8 | const char *g_esel_path = "/tmp/esel"; |
Chris Austen | 29a8e0f | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 9 | uint16_t g_record_id = 0x0001; |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 10 | |
| 11 | |
| 12 | /////////////////////////////////////////////////////////////////////////////// |
Patrick Williams | 24fa5a9 | 2015-10-30 14:53:57 -0500 | [diff] [blame] | 13 | // 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 Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 17 | // Record ID should be used for all partial eSEL adds. |
| 18 | // |
Patrick Williams | 24fa5a9 | 2015-10-30 14:53:57 -0500 | [diff] [blame] | 19 | // This function creates a /tmp/esel# file to store the |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 20 | // incoming partial esel. It is the role of some other |
Patrick Williams | 24fa5a9 | 2015-10-30 14:53:57 -0500 | [diff] [blame] | 21 | // function to commit the error log in to long term |
| 22 | // storage. Likely via the ipmi add_sel command. |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 23 | /////////////////////////////////////////////////////////////////////////////// |
Patrick Williams | 24fa5a9 | 2015-10-30 14:53:57 -0500 | [diff] [blame] | 24 | ipmi_ret_t ipmi_ibm_oem_partial_esel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
Chris Austen | 17160ce | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 25 | ipmi_request_t request, ipmi_response_t response, |
| 26 | ipmi_data_len_t data_len, ipmi_context_t context) |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 27 | { |
| 28 | esel_request_t *reqptr = (esel_request_t*) request; |
| 29 | FILE *fp; |
Chris Austen | 29a8e0f | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 30 | // TODO: Issue 5: This is not endian-safe. |
| 31 | short *recid = (short*) &reqptr->selrecordls; |
| 32 | short *offset = (short*) &reqptr->offsetls; |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 33 | uint8_t rlen; |
| 34 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 35 | const char *pio; |
| 36 | |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 37 | |
Chris Austen | 29a8e0f | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 38 | if (!*recid && !*offset) { |
Chris Austen | 17160ce | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 39 | // OpenPOWER Host Interface spec says if RecordID and Offset are |
| 40 | // 0 then then this is a new request |
| 41 | pio = "wb"; |
Chris Austen | 17160ce | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 42 | } else { |
| 43 | pio = "rb+"; |
Chris Austen | 17160ce | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 44 | } |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 45 | |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 46 | rlen = (*data_len) - (uint8_t) (sizeof(esel_request_t)); |
| 47 | |
| 48 | |
Patrick Williams | 24fa5a9 | 2015-10-30 14:53:57 -0500 | [diff] [blame] | 49 | printf("IPMI PARTIAL ESEL for %s Offset = %d Length = %d\n", |
Chris Austen | fcafccf | 2016-02-19 23:15:57 -0600 | [diff] [blame^] | 50 | g_esel_path, *offset, rlen); |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 51 | |
| 52 | |
Chris Austen | fcafccf | 2016-02-19 23:15:57 -0600 | [diff] [blame^] | 53 | if ((fp = fopen(g_esel_path, pio)) != NULL) { |
Chris Austen | 29a8e0f | 2015-10-30 11:44:38 -0500 | [diff] [blame] | 54 | fseek(fp, *offset, SEEK_SET); |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 55 | fwrite(reqptr+1,rlen,1,fp); |
| 56 | fclose(fp); |
| 57 | |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 58 | *data_len = sizeof(g_record_id); |
| 59 | memcpy(response, &g_record_id, *data_len); |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 60 | } else { |
Chris Austen | fcafccf | 2016-02-19 23:15:57 -0600 | [diff] [blame^] | 61 | fprintf(stderr, "Error trying to perform %s for esel%s\n",pio, g_esel_path); |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 62 | rc = IPMI_CC_INVALID; |
| 63 | *data_len = 0; |
| 64 | } |
Patrick Williams | 24fa5a9 | 2015-10-30 14:53:57 -0500 | [diff] [blame] | 65 | |
Chris Austen | fd8c1cc | 2015-11-11 00:46:42 -0600 | [diff] [blame] | 66 | // The first bit prepresents that this is the last partial packet |
| 67 | // coming down. If that is the case advance the record id so we |
| 68 | // don't overlap logs. This allows anyone to establish a log |
| 69 | // directory system. |
| 70 | if (reqptr->progress & 1 ) { |
| 71 | g_record_id++; |
| 72 | } |
| 73 | |
Chris Austen | 4d98c1e | 2015-10-13 14:33:50 -0500 | [diff] [blame] | 74 | return rc; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void register_netfn_oem_partial_esel() |
| 79 | { |
| 80 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_OEM, IPMI_CMD_PESEL); |
| 81 | ipmi_register_callback(NETFUN_OEM, IPMI_CMD_PESEL, NULL, ipmi_ibm_oem_partial_esel); |
| 82 | return; |
| 83 | } |