blob: b567d845897ae8762cb584f18ab66e7266c628c3 [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>
Norman James82330442015-11-19 16:53:26 -06005#include <sys/time.h>
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -05006#include <arpa/inet.h>
Chris Austenb4f5b922015-10-13 12:44:43 -05007
Chris Austen41a4b312015-10-25 03:45:42 -05008#include "storagehandler.h"
9#include "storageaddsel.h"
Patrick Williams37af7332016-09-02 21:21:42 -050010#include "host-ipmid/ipmid-api.h"
Chris Austen41a4b312015-10-25 03:45:42 -050011
Chris Austenb4f5b922015-10-13 12:44:43 -050012void register_netfn_storage_functions() __attribute__((constructor));
13
14
15unsigned int g_sel_time = 0xFFFFFFFF;
Nan Li36c0cb62016-03-31 11:16:08 +080016extern unsigned short g_sel_reserve;
Chris Austenb4f5b922015-10-13 12:44:43 -050017
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050018ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
19 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050020 ipmi_data_len_t data_len, ipmi_context_t context)
21{
22 printf("Handling STORAGE WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
23 // Status code.
Nan Li70aa8d92016-08-29 00:11:10 +080024 ipmi_ret_t rc = IPMI_CC_INVALID;
Chris Austenb4f5b922015-10-13 12:44:43 -050025 *data_len = 0;
26 return rc;
27}
28
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050029ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
30 ipmi_request_t request, ipmi_response_t response,
31 ipmi_data_len_t data_len, ipmi_context_t context)
32{
33 time_t currtime;
34 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austenb4f5b922015-10-13 12:44:43 -050035
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050036 // Get current time in seconds since jan 1 1970
37 time(&currtime);
38 uint32_t resp = (uint32_t)currtime;
39 resp = htole32(resp);
40
41 printf("IPMI Handling GET-SEL-TIME\n");
42
43 // From the IPMI Spec 2.0, response should be a 32-bit value
44 *data_len = sizeof(resp);
45
46 // Pack the actual response
47 memcpy(response, &resp, *data_len);
48
49 return rc;
50}
51
52ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
53 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050054 ipmi_data_len_t data_len, ipmi_context_t context)
55{
Norman James82330442015-11-19 16:53:26 -060056 uint32_t* secs = (uint32_t*)request;
Chris Austenb4f5b922015-10-13 12:44:43 -050057
58 printf("Handling Set-SEL-Time:[0x%X], Cmd:[0x%X]\n",netfn, cmd);
Norman James82330442015-11-19 16:53:26 -060059 printf("Data: 0x%X]\n",*secs);
Chris Austenb4f5b922015-10-13 12:44:43 -050060
Norman James82330442015-11-19 16:53:26 -060061 struct timeval sel_time;
62 sel_time.tv_sec = le32toh(*secs);
Norman Jamesda4bad02016-01-16 07:17:08 -060063 sel_time.tv_usec = 0;
Chris Austenb4f5b922015-10-13 12:44:43 -050064 ipmi_ret_t rc = IPMI_CC_OK;
Norman James82330442015-11-19 16:53:26 -060065 int rct = settimeofday(&sel_time, NULL);
66
67 if(rct == 0)
68 {
69 system("hwclock -w");
70 }
71 else
72 {
73 printf("settimeofday() failed\n");
74 rc = IPMI_CC_UNSPECIFIED_ERROR;
75 }
Chris Austenb4f5b922015-10-13 12:44:43 -050076 *data_len = 0;
77 return rc;
78}
79
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -050080ipmi_ret_t ipmi_storage_get_sel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
81 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -050082 ipmi_data_len_t data_len, ipmi_context_t context)
83{
84
85 ipmi_ret_t rc = IPMI_CC_OK;
86 unsigned char buf[] = {0x51,0,0,0xff, 0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0x06};
87
88 printf("IPMI Handling GET-SEL-INFO\n");
89
90 *data_len = sizeof(buf);
91
92 // TODO There is plently of work here. The SEL DB needs to hold a bunch
93 // of things in a header. Items like Time Stamp, number of entries, etc
94 // This is one place where the dbus object with the SEL information could
95 // mimic what IPMI needs.
96
97 // Pack the actual response
98 memcpy(response, &buf, *data_len);
99
100 return rc;
101}
102
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500103ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
104 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500105 ipmi_data_len_t data_len, ipmi_context_t context)
106{
Chris Austenb4f5b922015-10-13 12:44:43 -0500107 ipmi_ret_t rc = IPMI_CC_OK;
108
Nan Li36c0cb62016-03-31 11:16:08 +0800109 // IPMI spec, Reservation ID, the value simply increases against each execution of reserve_sel command.
110 if( ++g_sel_reserve == 0)
111 g_sel_reserve = 1;
Chris Austenb4f5b922015-10-13 12:44:43 -0500112
Nan Li36c0cb62016-03-31 11:16:08 +0800113 printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve);
Chris Austen41a4b312015-10-25 03:45:42 -0500114
Chris Austenb4f5b922015-10-13 12:44:43 -0500115 *data_len = sizeof(g_sel_reserve);
116
117 // Pack the actual response
118 memcpy(response, &g_sel_reserve, *data_len);
119
120 return rc;
121}
122
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500123ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
124 ipmi_request_t request, ipmi_response_t response,
Chris Austenb4f5b922015-10-13 12:44:43 -0500125 ipmi_data_len_t data_len, ipmi_context_t context)
126{
127
128 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austen41a4b312015-10-25 03:45:42 -0500129 ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request;
130 uint16_t recordid;
Chris Austenb4f5b922015-10-13 12:44:43 -0500131
Chris Austen313d95b2015-10-31 12:55:30 -0500132 recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2];
Chris Austen41a4b312015-10-25 03:45:42 -0500133
134 printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid);
Chris Austenb4f5b922015-10-13 12:44:43 -0500135
136 *data_len = sizeof(g_sel_reserve);
137
138 // Pack the actual response
Chris Austen7cc33322015-11-11 00:20:22 -0600139 memcpy(response, &p->eventdata[1], 2);
Chris Austenb4f5b922015-10-13 12:44:43 -0500140
Chris Austen41a4b312015-10-25 03:45:42 -0500141 send_esel(recordid);
Chris Austenb4f5b922015-10-13 12:44:43 -0500142
143 return rc;
144}
145
146
147
148void register_netfn_storage_functions()
149{
150 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WILDCARD);
151 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard);
152
Adriana Kobylak8e30f2a2015-10-20 10:23:51 -0500153 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME);
154 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time);
155
Chris Austenb4f5b922015-10-13 12:44:43 -0500156 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME);
157 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time);
158
Chris Austenb4f5b922015-10-13 12:44:43 -0500159 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO);
160 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, ipmi_storage_get_sel_info);
161
162 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL);
163 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel);
164
165 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL);
166 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel);
167 return;
168}
169