Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdint.h> |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 4 | #include <time.h> |
| 5 | #include <arpa/inet.h> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 6 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 7 | #include "storagehandler.h" |
| 8 | #include "storageaddsel.h" |
| 9 | #include "ipmid-api.h" |
| 10 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 11 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 12 | |
| 13 | |
| 14 | unsigned int g_sel_time = 0xFFFFFFFF; |
| 15 | unsigned short g_sel_reserve = 0x1; |
| 16 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 17 | ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 18 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 19 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 20 | { |
| 21 | printf("Handling STORAGE WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 22 | // Status code. |
| 23 | ipmi_ret_t rc = IPMI_CC_OK; |
| 24 | *data_len = 0; |
| 25 | return rc; |
| 26 | } |
| 27 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 28 | ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 29 | ipmi_request_t request, ipmi_response_t response, |
| 30 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 31 | { |
| 32 | time_t currtime; |
| 33 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 34 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 35 | // Get current time in seconds since jan 1 1970 |
| 36 | time(&currtime); |
| 37 | uint32_t resp = (uint32_t)currtime; |
| 38 | resp = htole32(resp); |
| 39 | |
| 40 | printf("IPMI Handling GET-SEL-TIME\n"); |
| 41 | |
| 42 | // From the IPMI Spec 2.0, response should be a 32-bit value |
| 43 | *data_len = sizeof(resp); |
| 44 | |
| 45 | // Pack the actual response |
| 46 | memcpy(response, &resp, *data_len); |
| 47 | |
| 48 | return rc; |
| 49 | } |
| 50 | |
| 51 | ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 52 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 53 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 54 | { |
| 55 | unsigned int *bufftype = (unsigned int *) request; |
| 56 | |
| 57 | printf("Handling Set-SEL-Time:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 58 | printf("Data: 0x%X]\n",*bufftype); |
| 59 | |
| 60 | g_sel_time = *bufftype; |
| 61 | |
| 62 | ipmi_ret_t rc = IPMI_CC_OK; |
| 63 | *data_len = 0; |
| 64 | return rc; |
| 65 | } |
| 66 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 67 | ipmi_ret_t ipmi_storage_get_sel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 68 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 69 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 70 | { |
| 71 | |
| 72 | ipmi_ret_t rc = IPMI_CC_OK; |
| 73 | unsigned char buf[] = {0x51,0,0,0xff, 0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0x06}; |
| 74 | |
| 75 | printf("IPMI Handling GET-SEL-INFO\n"); |
| 76 | |
| 77 | *data_len = sizeof(buf); |
| 78 | |
| 79 | // TODO There is plently of work here. The SEL DB needs to hold a bunch |
| 80 | // of things in a header. Items like Time Stamp, number of entries, etc |
| 81 | // This is one place where the dbus object with the SEL information could |
| 82 | // mimic what IPMI needs. |
| 83 | |
| 84 | // Pack the actual response |
| 85 | memcpy(response, &buf, *data_len); |
| 86 | |
| 87 | return rc; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 92 | ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 93 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 94 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 95 | { |
| 96 | |
| 97 | ipmi_ret_t rc = IPMI_CC_OK; |
| 98 | |
| 99 | printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve); |
| 100 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 101 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 102 | *data_len = sizeof(g_sel_reserve); |
| 103 | |
| 104 | // Pack the actual response |
| 105 | memcpy(response, &g_sel_reserve, *data_len); |
| 106 | |
| 107 | return rc; |
| 108 | } |
| 109 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 110 | ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 111 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 112 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 113 | { |
| 114 | |
| 115 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 116 | ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request; |
| 117 | uint16_t recordid; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 118 | |
Chris Austen | 313d95b | 2015-10-31 12:55:30 -0500 | [diff] [blame] | 119 | recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2]; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 120 | |
| 121 | printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 122 | |
| 123 | *data_len = sizeof(g_sel_reserve); |
| 124 | |
| 125 | // Pack the actual response |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 126 | memcpy(response, &recordid, 2); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 127 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 128 | // TODO This code should grab the completed partial esel located in |
| 129 | // the /tmp/esel0100 file and commit it to the error log handler. |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 130 | send_esel(recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 131 | |
| 132 | return rc; |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | void register_netfn_storage_functions() |
| 138 | { |
| 139 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WILDCARD); |
| 140 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard); |
| 141 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 142 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME); |
| 143 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time); |
| 144 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 145 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME); |
| 146 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time); |
| 147 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 148 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO); |
| 149 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, ipmi_storage_get_sel_info); |
| 150 | |
| 151 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL); |
| 152 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel); |
| 153 | |
| 154 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL); |
| 155 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel); |
| 156 | return; |
| 157 | } |
| 158 | |