blob: dc0217e524dd45aa735bdc41416fb7c64f250227 [file] [log] [blame]
Chris Austenb4f5b922015-10-13 12:44:43 -05001#include <stdio.h>
2#include <string.h>
3#include <stdint.h>
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -05004#include <time.h>
5#include <arpa/inet.h>
Chris Austenb4f5b922015-10-13 12:44:43 -05006
Chris Austen41a4b312015-10-25 03:45:42 -05007#include "storagehandler.h"
8#include "storageaddsel.h"
9#include "ipmid-api.h"
10
Chris Austenb4f5b922015-10-13 12:44:43 -050011void register_netfn_storage_functions() __attribute__((constructor));
12
13
14unsigned int g_sel_time = 0xFFFFFFFF;
15unsigned short g_sel_reserve = 0x1;
16
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050017ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
18 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050019 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 Kobylak8e30f2a2015-10-20 10:23:51 -050028ipmi_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 Austenb4f5b922015-10-13 12:44:43 -050034
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050035 // 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
51ipmi_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 Austenb4f5b922015-10-13 12:44:43 -050053 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
67struct 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 Kobylak8e30f2a2015-10-20 10:23:51 -050074ipmi_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 Austenb4f5b922015-10-13 12:44:43 -050076 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 Kobylak8e30f2a2015-10-20 10:23:51 -050096
Chris Austenb4f5b922015-10-13 12:44:43 -050097
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 Kobylak8e30f2a2015-10-20 10:23:51 -0500103 // do what fseek asks. Modify to rb+ and fseek
Chris Austenb4f5b922015-10-13 12:44:43 -0500104 // 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500117 ipmi_ret_t rc = IPMI_CC_INVALID;
Chris Austenb4f5b922015-10-13 12:44:43 -0500118 }
Chris Austenb4f5b922015-10-13 12:44:43 -0500119
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500120
121 // TODO : Here is where some validation code could determine if the
Chris Austenb4f5b922015-10-13 12:44:43 -0500122 // 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500124 // the various methods updating interesting properties. Perhaps
Chris Austenb4f5b922015-10-13 12:44:43 -0500125 // thinigs like Model#, Serial#, DIMM Size, etc
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500126
Chris Austenb4f5b922015-10-13 12:44:43 -0500127
128 *data_len = 0;
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500129
Chris Austenb4f5b922015-10-13 12:44:43 -0500130 return rc;
131}
132
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500133ipmi_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 Austenb4f5b922015-10-13 12:44:43 -0500135 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 Kobylak8e30f2a2015-10-20 10:23:51 -0500158ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
159 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500160 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 Austen41a4b312015-10-25 03:45:42 -0500167
Chris Austenb4f5b922015-10-13 12:44:43 -0500168 *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 Kobylak8e30f2a2015-10-20 10:23:51 -0500176ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
177 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500178 ipmi_data_len_t data_len, ipmi_context_t context)
179{
180
181 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen41a4b312015-10-25 03:45:42 -0500182 ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request;
183 uint16_t recordid;
Chris Austenb4f5b922015-10-13 12:44:43 -0500184
Chris Austen41a4b312015-10-25 03:45:42 -0500185 recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2];
186
187 printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid);
Chris Austenb4f5b922015-10-13 12:44:43 -0500188
189 *data_len = sizeof(g_sel_reserve);
190
191 // Pack the actual response
Chris Austen41a4b312015-10-25 03:45:42 -0500192 memcpy(response, &recordid, 2);
Chris Austenb4f5b922015-10-13 12:44:43 -0500193
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500194 // 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 Austen41a4b312015-10-25 03:45:42 -0500196 send_esel(recordid);
Chris Austenb4f5b922015-10-13 12:44:43 -0500197
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