blob: eee9540d06911342349500d207e028d8bca1b834 [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
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050067ipmi_ret_t ipmi_storage_get_sel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
68 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050069 ipmi_data_len_t data_len, ipmi_context_t context)
70{
71
72 ipmi_ret_t rc = IPMI_CC_OK;
73 unsigned char buf[] = {0x51,0,0,0xff, 0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0x06};
74
75 printf("IPMI Handling GET-SEL-INFO\n");
76
77 *data_len = sizeof(buf);
78
79 // TODO There is plently of work here. The SEL DB needs to hold a bunch
80 // of things in a header. Items like Time Stamp, number of entries, etc
81 // This is one place where the dbus object with the SEL information could
82 // mimic what IPMI needs.
83
84 // Pack the actual response
85 memcpy(response, &buf, *data_len);
86
87 return rc;
88}
89
90
91
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050092ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
93 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050094 ipmi_data_len_t data_len, ipmi_context_t context)
95{
96
97 ipmi_ret_t rc = IPMI_CC_OK;
98
99 printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve);
100
Chris Austen41a4b312015-10-25 03:45:42 -0500101
Chris Austenb4f5b922015-10-13 12:44:43 -0500102 *data_len = sizeof(g_sel_reserve);
103
104 // Pack the actual response
105 memcpy(response, &g_sel_reserve, *data_len);
106
107 return rc;
108}
109
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500110ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
111 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500112 ipmi_data_len_t data_len, ipmi_context_t context)
113{
114
115 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen41a4b312015-10-25 03:45:42 -0500116 ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request;
117 uint16_t recordid;
Chris Austenb4f5b922015-10-13 12:44:43 -0500118
Chris Austen313d95b2015-10-31 12:55:30 -0500119 recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2];
Chris Austen41a4b312015-10-25 03:45:42 -0500120
121 printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid);
Chris Austenb4f5b922015-10-13 12:44:43 -0500122
123 *data_len = sizeof(g_sel_reserve);
124
125 // Pack the actual response
Chris Austen41a4b312015-10-25 03:45:42 -0500126 memcpy(response, &recordid, 2);
Chris Austenb4f5b922015-10-13 12:44:43 -0500127
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500128 // TODO This code should grab the completed partial esel located in
129 // the /tmp/esel0100 file and commit it to the error log handler.
Chris Austen41a4b312015-10-25 03:45:42 -0500130 send_esel(recordid);
Chris Austenb4f5b922015-10-13 12:44:43 -0500131
132 return rc;
133}
134
135
136
137void register_netfn_storage_functions()
138{
139 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WILDCARD);
140 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard);
141
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500142 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME);
143 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time);
144
Chris Austenb4f5b922015-10-13 12:44:43 -0500145 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME);
146 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time);
147
Chris Austenb4f5b922015-10-13 12:44:43 -0500148 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO);
149 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, ipmi_storage_get_sel_info);
150
151 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL);
152 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel);
153
154 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL);
155 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel);
156 return;
157}
158