blob: 023a82a79bf9bcd8440d0e008e5e28a845bf1662 [file] [log] [blame]
Chris Austenb4f5b922015-10-13 12:44:43 -05001#include "storagehandler.h"
2#include "ipmid-api.h"
3#include <stdio.h>
4#include <string.h>
5#include <stdint.h>
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -05006#include <time.h>
7#include <arpa/inet.h>
Chris Austenb4f5b922015-10-13 12:44:43 -05008
9void register_netfn_storage_functions() __attribute__((constructor));
10
11
12unsigned int g_sel_time = 0xFFFFFFFF;
13unsigned short g_sel_reserve = 0x1;
14
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050015ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
16 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050017 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 Kobylak8e30f2a2015-10-20 10:23:51 -050026ipmi_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 Austenb4f5b922015-10-13 12:44:43 -050032
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050033 // 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
49ipmi_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 Austenb4f5b922015-10-13 12:44:43 -050051 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
65struct 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 Kobylak8e30f2a2015-10-20 10:23:51 -050072ipmi_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 Austenb4f5b922015-10-13 12:44:43 -050074 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 Kobylak8e30f2a2015-10-20 10:23:51 -050094
Chris Austenb4f5b922015-10-13 12:44:43 -050095
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 Kobylak8e30f2a2015-10-20 10:23:51 -0500101 // do what fseek asks. Modify to rb+ and fseek
Chris Austenb4f5b922015-10-13 12:44:43 -0500102 // 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500115 ipmi_ret_t rc = IPMI_CC_INVALID;
Chris Austenb4f5b922015-10-13 12:44:43 -0500116 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500117
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500118
119 // TODO : Here is where some validation code could determine if the
Chris Austenb4f5b922015-10-13 12:44:43 -0500120 // 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500122 // the various methods updating interesting properties. Perhaps
Chris Austenb4f5b922015-10-13 12:44:43 -0500123 // thinigs like Model#, Serial#, DIMM Size, etc
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500124
Chris Austenb4f5b922015-10-13 12:44:43 -0500125
126 *data_len = 0;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500127
Chris Austenb4f5b922015-10-13 12:44:43 -0500128 return rc;
129}
130
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500131ipmi_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 Austenb4f5b922015-10-13 12:44:43 -0500133 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500156ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
157 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500158 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500174ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
175 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500176 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500188 // 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 Austenb4f5b922015-10-13 12:44:43 -0500190
191
192 // TODO I advanced the sel reservation number so next time HB asks
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500193 // for a reservation they get a new number. This tech may change
Chris Austenb4f5b922015-10-13 12:44:43 -0500194 // based on how the HB team currently uses sel reservations but
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500195 // for now provide the ability to get new reservations
Chris Austenb4f5b922015-10-13 12:44:43 -0500196 g_sel_reserve++;
197
198 return rc;
199}
200
201
202
203void 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500208 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 Austenb4f5b922015-10-13 12:44:43 -0500211 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