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