blob: 0b16d10232fbf707fe2688d16e16a19ab7353917 [file] [log] [blame]
Chris Austenac4604a2015-10-13 12:43:27 -05001#include "sensorhandler.h"
2#include "ipmid-api.h"
3#include <stdio.h>
4#include <string.h>
5#include <stdint.h>
6
Chris Austen8a45e7c2015-10-15 00:31:46 -05007extern int updateSensorRecordFromSSRAESC(const void *);
Chris Austenac4604a2015-10-13 12:43:27 -05008
9void register_netfn_sen_functions() __attribute__((constructor));
10
11
12struct sensor_data_t {
13 uint8_t sennum;
14} __attribute__ ((packed)) ;
15
16unsigned char g_sensortype [][2] = {
17 {0xc7, 58},
18{0x01, 113},
19{0xc7, 56},
20{0x01, 114},
21{0xc6, 54},
22{0x07, 40},
23{0xC1, 121},
24{0xC2, 137},
25{0x07, 36},
26{0x07, 43},
27{0xC1, 122},
28{0xC1, 119},
29{0x01, 12},
30{0x01, 111},
31{0x01, 116},
32{0xC1, 127},
33{0xC2, 134},
34{0xC2, 130},
35{0xc, 33},
36{0xC1, 125},
37{0x01, 115},
38{0x22, 4},
39{0xC2, 138},
40{0x01, 108},
41{0x01, 102},
42{0xc, 46},
43{0x7, 11},
44{0xC1, 120},
45{0x07, 39},
46{0x07, 42},
47{0x5, 21},
48{0xC2, 131},
49{0xc1, 48},
50{0x12, 53},
51{0xC1, 124},
52{0x01, 117},
53{0xC1, 126},
54{0xf, 5},
55{0x23, 0},
56{0xC2, 139},
57{0x07, 34},
58{0x09, 146},
59{0x02, 178},
60{0xC2, 140},
61{0xC1, 118},
62{0xC2, 133},
63{0x07, 38},
64{0xC2, 143},
65{0x01, 101},
66{0xc3, 9},
67{0x7, 10},
68{0xc2, 51},
69{0x01, 109},
70{0xc, 32},
71{0x7, 8},
72{0xC1, 129},
73{0x01, 112},
74{0x01, 107},
75{0x07, 37},
76{0x07, 44},
77{0x1f, 50},
78{0xC2, 144},
79{0xc7, 52},
80{0xC2, 141},
81{0x01, 106},
82{0x01, 110},
83{0x01, 103},
84{0x9, 28},
85{0x07, 35},
86{0xc7, 55},
87{0x03, 179},
88{0x07, 41},
89{0xc, 30},
90{0x01, 100},
91{0xC1, 128},
92{0xC2, 135},
93{0x01, 105},
94{0x7, 47},
95{0xC2, 145},
96{0xc7, 57},
97{0x01, 104},
98{0x07, 45},
99{0xC2, 132},
100{0xc4, 49},
101{0xC1, 123},
102{0xC2, 142},
103{0x01, 13},
104{0xC2, 136},
105{0xc, 31},
106{0xff,0xff}
107};
108
109
110unsigned char findSensor(char sensor_number) {
111
112 int i=0;
113
114 // TODO : This function should actually call
115 // a dbus object and have it return the data
116 // it is not ready yet so use a Palmetto
117 // based lookup table for now. The g_sensortype
118 // can be removed once the dbus method exists
119 while (g_sensortype[i][0] != 0xff) {
120 if (g_sensortype[i][1] == sensor_number) {
121 break;
122 } else {
123 i++;
124 }
125
126 }
127
128 return g_sensortype[i][0];
129
130}
131
132ipmi_ret_t ipmi_sen_get_sensor_type(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 sensor_data_t *reqptr = (sensor_data_t*)request;
137 ipmi_ret_t rc = IPMI_CC_OK;
138
139 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
140
141 // TODO Not sure what the System-event-sensor is suppose to return
142 // need to ask Hostboot team
143 unsigned char buf[] = {0x00,0x6F};
144
145 buf[0] = findSensor(reqptr->sennum);
146
147 *data_len = sizeof(buf);
148 memcpy(response, &buf, *data_len);
149
150
151
152 return rc;
153}
154
155
156
157// TODO: Saves the sensor information to a file in /tmp. This
158// will need to change to calling the correct method
159// once it exists in the stack.
160ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
161 ipmi_request_t request, ipmi_response_t response,
162 ipmi_data_len_t data_len, ipmi_context_t context)
163{
164 FILE *fp;
165 char string[16];
166 sensor_data_t *reqptr = (sensor_data_t*)request;
167 ipmi_ret_t rc = IPMI_CC_OK;
168 unsigned short rlen;
169
Chris Austen8a45e7c2015-10-15 00:31:46 -0500170 rlen = (unsigned short) *data_len;
Chris Austenac4604a2015-10-13 12:43:27 -0500171
172 sprintf(string, "%s%02x", "/tmp/sen", reqptr->sennum);
173
174 printf("IPMI SET_SENSOR [%s]\n",string);
175
176 if ((fp = fopen(string, "wb")) != NULL) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500177 fwrite(reqptr,rlen,1,fp);
Chris Austenac4604a2015-10-13 12:43:27 -0500178 fclose(fp);
179 } else {
180 fprintf(stderr, "Error trying to write to sensor file %s\n",string);
181 ipmi_ret_t rc = IPMI_CC_INVALID;
182 }
183
Chris Austen8a45e7c2015-10-15 00:31:46 -0500184 updateSensorRecordFromSSRAESC(reqptr);
185
Chris Austenac4604a2015-10-13 12:43:27 -0500186 *data_len=0;
187
188
189 return rc;
190}
191
192ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
193 ipmi_request_t request, ipmi_response_t response,
194 ipmi_data_len_t data_len, ipmi_context_t context)
195{
196 ipmi_ret_t rc = IPMI_CC_OK;
197
198 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
199 *data_len = 0;
200
201 return rc;
202}
203
204
205void register_netfn_sen_functions()
206{
207 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD);
208 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard);
209
210 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
211 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type);
212
213 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
214 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500215
Chris Austenac4604a2015-10-13 12:43:27 -0500216 return;
217}