blob: cd57dd4f6cadb5930a584e0f66fc622960635d87 [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;
Chris Austend7cf0e42015-11-07 14:27:12 -060015 uint8_t typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -050016 char dbusname[32];
17} ;
18
19
20sensorTypemap_t g_SensorTypeMap[] = {
21
Chris Austend7cf0e42015-11-07 14:27:12 -060022 {0x01, 0x6F, "Temp"},
23 {0x0C, 0x6F, "DIMM"},
24 {0x0C, 0x6F, "MEMORY_BUFFER"},
25 {0x07, 0x6F, "PROC"},
26 {0x07, 0x6F, "CORE"},
27 {0x07, 0x6F, "CPU"},
28 {0x0F, 0x6F, "BootProgress"},
29 {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09
30 {0xC3, 0x6F, "BootCount"},
31 {0x1F, 0x6F, "OperatingSystemStatus"},
32 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050033};
34
35
Chris Austenac4604a2015-10-13 12:43:27 -050036
37struct sensor_data_t {
38 uint8_t sennum;
39} __attribute__ ((packed)) ;
40
Chris Austenac4604a2015-10-13 12:43:27 -050041
Chris Austen0012e9b2015-10-22 01:37:46 -050042uint8_t dbus_to_sensor_type(char *p) {
Chris Austenac4604a2015-10-13 12:43:27 -050043
Chris Austen0012e9b2015-10-22 01:37:46 -050044 sensorTypemap_t *s = g_SensorTypeMap;
45 char r=0;
Chris Austenac4604a2015-10-13 12:43:27 -050046
Chris Austen0012e9b2015-10-22 01:37:46 -050047 while (s->number != 0xFF) {
48 if (!strcmp(s->dbusname,p)) {
49 r = s->number;
50 break;
Chris Austenac4604a2015-10-13 12:43:27 -050051 }
Chris Austen0012e9b2015-10-22 01:37:46 -050052 s++;
Chris Austenac4604a2015-10-13 12:43:27 -050053 }
54
Chris Austend7cf0e42015-11-07 14:27:12 -060055
Chris Austen0012e9b2015-10-22 01:37:46 -050056 if (s->number == 0xFF)
57 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -050058
Chris Austen0012e9b2015-10-22 01:37:46 -050059 return r;
Chris Austenac4604a2015-10-13 12:43:27 -050060}
61
Chris Austen0012e9b2015-10-22 01:37:46 -050062
63uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) {
64 char fru_type_name[64];
65 int r= 0;
66
67 r = find_interface_property_fru_type(a, "fru_type", fru_type_name);
68 if (r<0) {
69 fprintf(stderr, "Failed to get a fru type: %s", strerror(-r));
70 return -1;
71 } else {
72 return dbus_to_sensor_type(fru_type_name);
73 }
74}
75
76
77uint8_t find_sensor(uint8_t sensor_number) {
78
79 dbus_interface_t a;
80 char *p;
81 char r;
82
83 r = find_openbmc_path("SENSOR", sensor_number, &a);
84
85 if (r < 0) { return 0; }
86
87 // This is where sensors that do not exist in dbus but do
88 // exist in the host code stop. This should indicate it
89 // is not a supported sensor
Chris Austend7cf0e42015-11-07 14:27:12 -060090 if (a.interface[0] == 0) { return 0;}
Chris Austen0012e9b2015-10-22 01:37:46 -050091
92 if (strstr(a.interface, "InventoryItem")) {
93 // InventoryItems are real frus. So need to get the
94 // fru_type property
95 r = dbus_to_sensor_type_from_dbus(&a);
96 } else {
97 // Non InventoryItems
98 p = strrchr (a.path, '/');
99 r = dbus_to_sensor_type(p+1);
100 }
101
102 return r;
103 }
104
105ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
106 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500107 ipmi_data_len_t data_len, ipmi_context_t context)
108{
109 sensor_data_t *reqptr = (sensor_data_t*)request;
110 ipmi_ret_t rc = IPMI_CC_OK;
111
112 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
113
114 // TODO Not sure what the System-event-sensor is suppose to return
115 // need to ask Hostboot team
116 unsigned char buf[] = {0x00,0x6F};
117
Chris Austen0012e9b2015-10-22 01:37:46 -0500118 buf[0] = find_sensor(reqptr->sennum);
119
120 // HACK UNTIL Dbus gets updated or we find a better way
121 if (buf[0] == 0) {
122
123 switch(reqptr->sennum) {
124 case 0x35 : buf[0] = 0x12; buf[1] = 0x6F; break;
125 case 0x37 : buf[0] = 0xC7; buf[1] = 0x03; break;
126 case 0x38 : buf[0] = 0xC7; buf[1] = 0x03; break;
127 case 0x39 : buf[0] = 0xC7; buf[1] = 0x03; break;
128 case 0x3A : buf[0] = 0xC7; buf[1] = 0x03; break;
129 default: rc = IPMI_CC_SENSOR_INVALID;
130 }
131 }
132
Chris Austenac4604a2015-10-13 12:43:27 -0500133
134 *data_len = sizeof(buf);
135 memcpy(response, &buf, *data_len);
136
Chris Austenac4604a2015-10-13 12:43:27 -0500137 return rc;
138}
139
140
141
Chris Austen0012e9b2015-10-22 01:37:46 -0500142ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
143 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500144 ipmi_data_len_t data_len, ipmi_context_t context)
145{
Chris Austenac4604a2015-10-13 12:43:27 -0500146 sensor_data_t *reqptr = (sensor_data_t*)request;
147 ipmi_ret_t rc = IPMI_CC_OK;
148 unsigned short rlen;
149
Chris Austen8a45e7c2015-10-15 00:31:46 -0500150 rlen = (unsigned short) *data_len;
Chris Austenac4604a2015-10-13 12:43:27 -0500151
Chris Austen0012e9b2015-10-22 01:37:46 -0500152 printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum);
Chris Austenac4604a2015-10-13 12:43:27 -0500153
Chris Austen8a45e7c2015-10-15 00:31:46 -0500154 updateSensorRecordFromSSRAESC(reqptr);
155
Chris Austenac4604a2015-10-13 12:43:27 -0500156 *data_len=0;
157
Chris Austenac4604a2015-10-13 12:43:27 -0500158 return rc;
159}
160
Chris Austen0012e9b2015-10-22 01:37:46 -0500161ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
162 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500163 ipmi_data_len_t data_len, ipmi_context_t context)
164{
165 ipmi_ret_t rc = IPMI_CC_OK;
166
167 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
168 *data_len = 0;
169
170 return rc;
171}
172
173
174void register_netfn_sen_functions()
175{
176 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD);
177 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard);
178
179 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
180 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type);
181
182 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
183 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500184
Chris Austenac4604a2015-10-13 12:43:27 -0500185 return;
186}