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