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 | |
| 67 | struct write_fru_data_t { |
| 68 | uint8_t frunum; |
| 69 | uint8_t offsetls; |
| 70 | uint8_t offsetms; |
| 71 | uint8_t data; |
| 72 | } __attribute__ ((packed)) ; |
| 73 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 74 | ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 75 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 76 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 77 | { |
| 78 | write_fru_data_t *reqptr = (write_fru_data_t*) request; |
| 79 | FILE *fp; |
| 80 | char string[16]; |
| 81 | short offset = 0; |
| 82 | uint16_t rlen; |
| 83 | ipmi_ret_t rc = IPMI_CC_OK; |
| 84 | char iocmd[4]; |
| 85 | |
| 86 | sprintf(string, "%s%02x", "/tmp/fru", reqptr->frunum); |
| 87 | |
| 88 | offset = ((uint16_t)reqptr->offsetms) << 8 | reqptr->offsetls; |
| 89 | |
| 90 | |
| 91 | // Length is the number of request bytes minus the header itself. |
| 92 | // The header contains an extra byte to indicate the start of |
| 93 | // the data (so didn't need to worry about word/byte boundaries) |
| 94 | // hence the -1... |
| 95 | rlen = ((uint16_t)*data_len) - (sizeof(write_fru_data_t)-1); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 96 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 97 | |
| 98 | printf("IPMI WRITE-FRU-DATA for %s Offset = %d Length = %d\n", |
| 99 | string, offset, rlen); |
| 100 | |
| 101 | |
| 102 | // I was thinking "ab+" but it appears it doesn't |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 103 | // do what fseek asks. Modify to rb+ and fseek |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 104 | // works great... |
| 105 | if (offset == 0) { |
| 106 | strcpy(iocmd, "wb"); |
| 107 | } else { |
| 108 | strcpy(iocmd, "rb+"); |
| 109 | } |
| 110 | |
| 111 | if ((fp = fopen(string, iocmd)) != NULL) { |
| 112 | fseek(fp, offset, SEEK_SET); |
| 113 | fwrite(&reqptr->data,rlen,1,fp); |
| 114 | fclose(fp); |
| 115 | } else { |
| 116 | fprintf(stderr, "Error trying to write to fru file %s\n",string); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 117 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 118 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 119 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 120 | |
| 121 | // TODO : Here is where some validation code could determine if the |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 122 | // fru data is a legitimate FRU record (not just a partial). Once |
| 123 | // the record is valid the code should call a parser routine to call |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 124 | // the various methods updating interesting properties. Perhaps |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 125 | // thinigs like Model#, Serial#, DIMM Size, etc |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 126 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 127 | |
| 128 | *data_len = 0; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 129 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 130 | return rc; |
| 131 | } |
| 132 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 133 | ipmi_ret_t ipmi_storage_get_sel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 134 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 135 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 136 | { |
| 137 | |
| 138 | ipmi_ret_t rc = IPMI_CC_OK; |
| 139 | unsigned char buf[] = {0x51,0,0,0xff, 0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0x06}; |
| 140 | |
| 141 | printf("IPMI Handling GET-SEL-INFO\n"); |
| 142 | |
| 143 | *data_len = sizeof(buf); |
| 144 | |
| 145 | // TODO There is plently of work here. The SEL DB needs to hold a bunch |
| 146 | // of things in a header. Items like Time Stamp, number of entries, etc |
| 147 | // This is one place where the dbus object with the SEL information could |
| 148 | // mimic what IPMI needs. |
| 149 | |
| 150 | // Pack the actual response |
| 151 | memcpy(response, &buf, *data_len); |
| 152 | |
| 153 | return rc; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 158 | ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 159 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 160 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 161 | { |
| 162 | |
| 163 | ipmi_ret_t rc = IPMI_CC_OK; |
| 164 | |
| 165 | printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve); |
| 166 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 167 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 168 | *data_len = sizeof(g_sel_reserve); |
| 169 | |
| 170 | // Pack the actual response |
| 171 | memcpy(response, &g_sel_reserve, *data_len); |
| 172 | |
| 173 | return rc; |
| 174 | } |
| 175 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 176 | ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 177 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 178 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 179 | { |
| 180 | |
| 181 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 182 | ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request; |
| 183 | uint16_t recordid; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 184 | |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 185 | recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2]; |
| 186 | |
| 187 | printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 188 | |
| 189 | *data_len = sizeof(g_sel_reserve); |
| 190 | |
| 191 | // Pack the actual response |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 192 | memcpy(response, &recordid, 2); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 193 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 194 | // TODO This code should grab the completed partial esel located in |
| 195 | // the /tmp/esel0100 file and commit it to the error log handler. |
Chris Austen | 41a4b31 | 2015-10-25 03:45:42 -0500 | [diff] [blame] | 196 | send_esel(recordid); |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 197 | |
| 198 | return rc; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | |
| 203 | void register_netfn_storage_functions() |
| 204 | { |
| 205 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WILDCARD); |
| 206 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard); |
| 207 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 208 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME); |
| 209 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time); |
| 210 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 211 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME); |
| 212 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time); |
| 213 | |
| 214 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA); |
| 215 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WRITE_FRU_DATA, NULL, ipmi_storage_write_fru_data); |
| 216 | |
| 217 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO); |
| 218 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, ipmi_storage_get_sel_info); |
| 219 | |
| 220 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL); |
| 221 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel); |
| 222 | |
| 223 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL); |
| 224 | ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel); |
| 225 | return; |
| 226 | } |
| 227 | |