Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 1 | #include "storagehandler.h" |
| 2 | #include "ipmid-api.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <stdint.h> |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 6 | #include <time.h> |
| 7 | #include <arpa/inet.h> |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 8 | |
| 9 | void register_netfn_storage_functions() __attribute__((constructor)); |
| 10 | |
| 11 | |
| 12 | unsigned int g_sel_time = 0xFFFFFFFF; |
| 13 | unsigned short g_sel_reserve = 0x1; |
| 14 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 15 | ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 16 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 17 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 18 | { |
| 19 | printf("Handling STORAGE WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 20 | // Status code. |
| 21 | ipmi_ret_t rc = IPMI_CC_OK; |
| 22 | *data_len = 0; |
| 23 | return rc; |
| 24 | } |
| 25 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 26 | ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 27 | ipmi_request_t request, ipmi_response_t response, |
| 28 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 29 | { |
| 30 | time_t currtime; |
| 31 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 32 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 33 | // Get current time in seconds since jan 1 1970 |
| 34 | time(&currtime); |
| 35 | uint32_t resp = (uint32_t)currtime; |
| 36 | resp = htole32(resp); |
| 37 | |
| 38 | printf("IPMI Handling GET-SEL-TIME\n"); |
| 39 | |
| 40 | // From the IPMI Spec 2.0, response should be a 32-bit value |
| 41 | *data_len = sizeof(resp); |
| 42 | |
| 43 | // Pack the actual response |
| 44 | memcpy(response, &resp, *data_len); |
| 45 | |
| 46 | return rc; |
| 47 | } |
| 48 | |
| 49 | ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 50 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 51 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 52 | { |
| 53 | unsigned int *bufftype = (unsigned int *) request; |
| 54 | |
| 55 | printf("Handling Set-SEL-Time:[0x%X], Cmd:[0x%X]\n",netfn, cmd); |
| 56 | printf("Data: 0x%X]\n",*bufftype); |
| 57 | |
| 58 | g_sel_time = *bufftype; |
| 59 | |
| 60 | ipmi_ret_t rc = IPMI_CC_OK; |
| 61 | *data_len = 0; |
| 62 | return rc; |
| 63 | } |
| 64 | |
| 65 | struct write_fru_data_t { |
| 66 | uint8_t frunum; |
| 67 | uint8_t offsetls; |
| 68 | uint8_t offsetms; |
| 69 | uint8_t data; |
| 70 | } __attribute__ ((packed)) ; |
| 71 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 72 | ipmi_ret_t ipmi_storage_write_fru_data(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 73 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 74 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 75 | { |
| 76 | write_fru_data_t *reqptr = (write_fru_data_t*) request; |
| 77 | FILE *fp; |
| 78 | char string[16]; |
| 79 | short offset = 0; |
| 80 | uint16_t rlen; |
| 81 | ipmi_ret_t rc = IPMI_CC_OK; |
| 82 | char iocmd[4]; |
| 83 | |
| 84 | sprintf(string, "%s%02x", "/tmp/fru", reqptr->frunum); |
| 85 | |
| 86 | offset = ((uint16_t)reqptr->offsetms) << 8 | reqptr->offsetls; |
| 87 | |
| 88 | |
| 89 | // Length is the number of request bytes minus the header itself. |
| 90 | // The header contains an extra byte to indicate the start of |
| 91 | // the data (so didn't need to worry about word/byte boundaries) |
| 92 | // hence the -1... |
| 93 | rlen = ((uint16_t)*data_len) - (sizeof(write_fru_data_t)-1); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 94 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 95 | |
| 96 | printf("IPMI WRITE-FRU-DATA for %s Offset = %d Length = %d\n", |
| 97 | string, offset, rlen); |
| 98 | |
| 99 | |
| 100 | // I was thinking "ab+" but it appears it doesn't |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 101 | // do what fseek asks. Modify to rb+ and fseek |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 102 | // works great... |
| 103 | if (offset == 0) { |
| 104 | strcpy(iocmd, "wb"); |
| 105 | } else { |
| 106 | strcpy(iocmd, "rb+"); |
| 107 | } |
| 108 | |
| 109 | if ((fp = fopen(string, iocmd)) != NULL) { |
| 110 | fseek(fp, offset, SEEK_SET); |
| 111 | fwrite(&reqptr->data,rlen,1,fp); |
| 112 | fclose(fp); |
| 113 | } else { |
| 114 | fprintf(stderr, "Error trying to write to fru file %s\n",string); |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 115 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 116 | } |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 117 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 118 | |
| 119 | // TODO : Here is where some validation code could determine if the |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 120 | // fru data is a legitimate FRU record (not just a partial). Once |
| 121 | // 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] | 122 | // the various methods updating interesting properties. Perhaps |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 123 | // thinigs like Model#, Serial#, DIMM Size, etc |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 124 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 125 | |
| 126 | *data_len = 0; |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 127 | |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 128 | return rc; |
| 129 | } |
| 130 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 131 | ipmi_ret_t ipmi_storage_get_sel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 132 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 133 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 134 | { |
| 135 | |
| 136 | ipmi_ret_t rc = IPMI_CC_OK; |
| 137 | unsigned char buf[] = {0x51,0,0,0xff, 0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0x06}; |
| 138 | |
| 139 | printf("IPMI Handling GET-SEL-INFO\n"); |
| 140 | |
| 141 | *data_len = sizeof(buf); |
| 142 | |
| 143 | // TODO There is plently of work here. The SEL DB needs to hold a bunch |
| 144 | // of things in a header. Items like Time Stamp, number of entries, etc |
| 145 | // This is one place where the dbus object with the SEL information could |
| 146 | // mimic what IPMI needs. |
| 147 | |
| 148 | // Pack the actual response |
| 149 | memcpy(response, &buf, *data_len); |
| 150 | |
| 151 | return rc; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 156 | ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 157 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 158 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 159 | { |
| 160 | |
| 161 | ipmi_ret_t rc = IPMI_CC_OK; |
| 162 | |
| 163 | printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve); |
| 164 | |
| 165 | *data_len = sizeof(g_sel_reserve); |
| 166 | |
| 167 | // Pack the actual response |
| 168 | memcpy(response, &g_sel_reserve, *data_len); |
| 169 | |
| 170 | return rc; |
| 171 | } |
| 172 | |
| 173 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 174 | ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 175 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 176 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 177 | { |
| 178 | |
| 179 | ipmi_ret_t rc = IPMI_CC_OK; |
| 180 | |
| 181 | printf("IPMI Handling ADD-SEL \n"); |
| 182 | |
| 183 | *data_len = sizeof(g_sel_reserve); |
| 184 | |
| 185 | // Pack the actual response |
| 186 | memcpy(response, &g_sel_reserve, *data_len); |
| 187 | |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 188 | // TODO This code should grab the completed partial esel located in |
| 189 | // the /tmp/esel0100 file and commit it to the error log handler. |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 190 | |
| 191 | |
| 192 | // TODO I advanced the sel reservation number so next time HB asks |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 193 | // for a reservation they get a new number. This tech may change |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 194 | // based on how the HB team currently uses sel reservations but |
Adriana Kobylak | 8e30f2a | 2015-10-20 10:23:51 -0500 | [diff] [blame] | 195 | // for now provide the ability to get new reservations |
Chris Austen | b4f5b92 | 2015-10-13 12:44:43 -0500 | [diff] [blame] | 196 | g_sel_reserve++; |
| 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 | |