blob: 9344abdc1d703a4f65ba6c2976cb1f2e34a8b799 [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 Austen0012e9b2015-10-22 01:37:46 -05008extern int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) ;
9extern int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) ;
Chris Austenac4604a2015-10-13 12:43:27 -050010
11void register_netfn_sen_functions() __attribute__((constructor));
12
Chris Austen0012e9b2015-10-22 01:37:46 -050013struct sensorTypemap_t {
14 uint8_t number;
15 char dbusname[32];
16} ;
17
18
19sensorTypemap_t g_SensorTypeMap[] = {
20
21 {0x01, "Temp"},
22 {0x0C, "DIMM"},
23 {0x0C, "MEMORY_BUFFER"},
24 {0x07, "PROC"},
25 {0x07, "CORE"},
26 {0x07, "CPU"},
27 {0x0F, "BootProgress"},
28 {0xC3, "OccStatus"},
29 {0xC3, "BootCount"},
30 {0xFF, ""}
31};
32
33
Chris Austenac4604a2015-10-13 12:43:27 -050034
35struct sensor_data_t {
36 uint8_t sennum;
37} __attribute__ ((packed)) ;
38
Chris Austenac4604a2015-10-13 12:43:27 -050039
Chris Austen0012e9b2015-10-22 01:37:46 -050040uint8_t dbus_to_sensor_type(char *p) {
Chris Austenac4604a2015-10-13 12:43:27 -050041
Chris Austen0012e9b2015-10-22 01:37:46 -050042 sensorTypemap_t *s = g_SensorTypeMap;
43 char r=0;
Chris Austenac4604a2015-10-13 12:43:27 -050044
Chris Austen0012e9b2015-10-22 01:37:46 -050045 while (s->number != 0xFF) {
46 if (!strcmp(s->dbusname,p)) {
47 r = s->number;
48 break;
Chris Austenac4604a2015-10-13 12:43:27 -050049 }
Chris Austen0012e9b2015-10-22 01:37:46 -050050 s++;
Chris Austenac4604a2015-10-13 12:43:27 -050051 }
52
Chris Austen0012e9b2015-10-22 01:37:46 -050053 if (s->number == 0xFF)
54 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -050055
Chris Austen0012e9b2015-10-22 01:37:46 -050056 return r;
Chris Austenac4604a2015-10-13 12:43:27 -050057}
58
Chris Austen0012e9b2015-10-22 01:37:46 -050059
60uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) {
61 char fru_type_name[64];
62 int r= 0;
63
64 r = find_interface_property_fru_type(a, "fru_type", fru_type_name);
65 if (r<0) {
66 fprintf(stderr, "Failed to get a fru type: %s", strerror(-r));
67 return -1;
68 } else {
69 return dbus_to_sensor_type(fru_type_name);
70 }
71}
72
73
74uint8_t find_sensor(uint8_t sensor_number) {
75
76 dbus_interface_t a;
77 char *p;
78 char r;
79
80 r = find_openbmc_path("SENSOR", sensor_number, &a);
81
82 if (r < 0) { return 0; }
83
84 // This is where sensors that do not exist in dbus but do
85 // exist in the host code stop. This should indicate it
86 // is not a supported sensor
87 if (a.bus[0] == 0) { return 0;}
88
89 if (strstr(a.interface, "InventoryItem")) {
90 // InventoryItems are real frus. So need to get the
91 // fru_type property
92 r = dbus_to_sensor_type_from_dbus(&a);
93 } else {
94 // Non InventoryItems
95 p = strrchr (a.path, '/');
96 r = dbus_to_sensor_type(p+1);
97 }
98
99 return r;
100 }
101
102ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
103 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500104 ipmi_data_len_t data_len, ipmi_context_t context)
105{
106 sensor_data_t *reqptr = (sensor_data_t*)request;
107 ipmi_ret_t rc = IPMI_CC_OK;
108
109 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
110
111 // TODO Not sure what the System-event-sensor is suppose to return
112 // need to ask Hostboot team
113 unsigned char buf[] = {0x00,0x6F};
114
Chris Austen0012e9b2015-10-22 01:37:46 -0500115 buf[0] = find_sensor(reqptr->sennum);
116
117 // HACK UNTIL Dbus gets updated or we find a better way
118 if (buf[0] == 0) {
119
120 switch(reqptr->sennum) {
121 case 0x35 : buf[0] = 0x12; buf[1] = 0x6F; break;
122 case 0x37 : buf[0] = 0xC7; buf[1] = 0x03; break;
123 case 0x38 : buf[0] = 0xC7; buf[1] = 0x03; break;
124 case 0x39 : buf[0] = 0xC7; buf[1] = 0x03; break;
125 case 0x3A : buf[0] = 0xC7; buf[1] = 0x03; break;
126 default: rc = IPMI_CC_SENSOR_INVALID;
127 }
128 }
129
Chris Austenac4604a2015-10-13 12:43:27 -0500130
131 *data_len = sizeof(buf);
132 memcpy(response, &buf, *data_len);
133
Chris Austenac4604a2015-10-13 12:43:27 -0500134 return rc;
135}
136
137
138
Chris Austen0012e9b2015-10-22 01:37:46 -0500139ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
140 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500141 ipmi_data_len_t data_len, ipmi_context_t context)
142{
Chris Austenac4604a2015-10-13 12:43:27 -0500143 sensor_data_t *reqptr = (sensor_data_t*)request;
144 ipmi_ret_t rc = IPMI_CC_OK;
145 unsigned short rlen;
146
Chris Austen8a45e7c2015-10-15 00:31:46 -0500147 rlen = (unsigned short) *data_len;
Chris Austenac4604a2015-10-13 12:43:27 -0500148
Chris Austen0012e9b2015-10-22 01:37:46 -0500149 printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum);
Chris Austenac4604a2015-10-13 12:43:27 -0500150
Chris Austen8a45e7c2015-10-15 00:31:46 -0500151 updateSensorRecordFromSSRAESC(reqptr);
152
Chris Austenac4604a2015-10-13 12:43:27 -0500153 *data_len=0;
154
Chris Austenac4604a2015-10-13 12:43:27 -0500155 return rc;
156}
157
Chris Austen0012e9b2015-10-22 01:37:46 -0500158ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
159 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500160 ipmi_data_len_t data_len, ipmi_context_t context)
161{
162 ipmi_ret_t rc = IPMI_CC_OK;
163
164 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
165 *data_len = 0;
166
167 return rc;
168}
169
170
171void register_netfn_sen_functions()
172{
173 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD);
174 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard);
175
176 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
177 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type);
178
179 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
180 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500181
Chris Austenac4604a2015-10-13 12:43:27 -0500182 return;
183}