blob: c96b7a7515c22d804bf305d83c39c74718bd2265 [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"},
Chris Austen800ba712015-12-03 15:31:00 -060032 {0x12, 0x6F, "SYSTEM_EVENT"},
33 {0xC7, 0x03, "SYSTEM"},
34 {0xC7, 0x03, "MAIN_PLANAR"},
Chris Austend7cf0e42015-11-07 14:27:12 -060035 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050036};
37
38
Chris Austenac4604a2015-10-13 12:43:27 -050039struct sensor_data_t {
40 uint8_t sennum;
41} __attribute__ ((packed)) ;
42
Chris Austenac4604a2015-10-13 12:43:27 -050043
Chris Austen0012e9b2015-10-22 01:37:46 -050044uint8_t dbus_to_sensor_type(char *p) {
Chris Austenac4604a2015-10-13 12:43:27 -050045
Chris Austen0012e9b2015-10-22 01:37:46 -050046 sensorTypemap_t *s = g_SensorTypeMap;
47 char r=0;
Chris Austenac4604a2015-10-13 12:43:27 -050048
Chris Austen0012e9b2015-10-22 01:37:46 -050049 while (s->number != 0xFF) {
50 if (!strcmp(s->dbusname,p)) {
51 r = s->number;
52 break;
Chris Austenac4604a2015-10-13 12:43:27 -050053 }
Chris Austen0012e9b2015-10-22 01:37:46 -050054 s++;
Chris Austenac4604a2015-10-13 12:43:27 -050055 }
56
Chris Austend7cf0e42015-11-07 14:27:12 -060057
Chris Austen0012e9b2015-10-22 01:37:46 -050058 if (s->number == 0xFF)
59 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -050060
Chris Austen0012e9b2015-10-22 01:37:46 -050061 return r;
Chris Austenac4604a2015-10-13 12:43:27 -050062}
63
Chris Austen0012e9b2015-10-22 01:37:46 -050064
65uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) {
66 char fru_type_name[64];
67 int r= 0;
68
69 r = find_interface_property_fru_type(a, "fru_type", fru_type_name);
70 if (r<0) {
71 fprintf(stderr, "Failed to get a fru type: %s", strerror(-r));
72 return -1;
73 } else {
74 return dbus_to_sensor_type(fru_type_name);
75 }
76}
77
78
79uint8_t find_sensor(uint8_t sensor_number) {
80
81 dbus_interface_t a;
82 char *p;
83 char r;
84
85 r = find_openbmc_path("SENSOR", sensor_number, &a);
86
87 if (r < 0) { return 0; }
88
89 // This is where sensors that do not exist in dbus but do
90 // exist in the host code stop. This should indicate it
91 // is not a supported sensor
Chris Austend7cf0e42015-11-07 14:27:12 -060092 if (a.interface[0] == 0) { return 0;}
Chris Austen0012e9b2015-10-22 01:37:46 -050093
94 if (strstr(a.interface, "InventoryItem")) {
95 // InventoryItems are real frus. So need to get the
96 // fru_type property
97 r = dbus_to_sensor_type_from_dbus(&a);
98 } else {
99 // Non InventoryItems
100 p = strrchr (a.path, '/');
101 r = dbus_to_sensor_type(p+1);
102 }
103
104 return r;
105 }
106
107ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
108 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500109 ipmi_data_len_t data_len, ipmi_context_t context)
110{
111 sensor_data_t *reqptr = (sensor_data_t*)request;
112 ipmi_ret_t rc = IPMI_CC_OK;
113
114 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
115
116 // TODO Not sure what the System-event-sensor is suppose to return
117 // need to ask Hostboot team
118 unsigned char buf[] = {0x00,0x6F};
119
Chris Austen0012e9b2015-10-22 01:37:46 -0500120 buf[0] = find_sensor(reqptr->sennum);
121
122 // HACK UNTIL Dbus gets updated or we find a better way
123 if (buf[0] == 0) {
Chris Austen800ba712015-12-03 15:31:00 -0600124 rc = IPMI_CC_SENSOR_INVALID;
Chris Austen0012e9b2015-10-22 01:37:46 -0500125 }
126
Chris Austenac4604a2015-10-13 12:43:27 -0500127
128 *data_len = sizeof(buf);
129 memcpy(response, &buf, *data_len);
130
Chris Austenac4604a2015-10-13 12:43:27 -0500131 return rc;
132}
133
134
135
Chris Austen0012e9b2015-10-22 01:37:46 -0500136ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
137 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500138 ipmi_data_len_t data_len, ipmi_context_t context)
139{
Chris Austenac4604a2015-10-13 12:43:27 -0500140 sensor_data_t *reqptr = (sensor_data_t*)request;
141 ipmi_ret_t rc = IPMI_CC_OK;
Chris Austenac4604a2015-10-13 12:43:27 -0500142
Chris Austen0012e9b2015-10-22 01:37:46 -0500143 printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum);
Chris Austenac4604a2015-10-13 12:43:27 -0500144
Chris Austen8a45e7c2015-10-15 00:31:46 -0500145 updateSensorRecordFromSSRAESC(reqptr);
146
Chris Austenac4604a2015-10-13 12:43:27 -0500147 *data_len=0;
148
Chris Austenac4604a2015-10-13 12:43:27 -0500149 return rc;
150}
151
Chris Austen0012e9b2015-10-22 01:37:46 -0500152ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
153 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500154 ipmi_data_len_t data_len, ipmi_context_t context)
155{
156 ipmi_ret_t rc = IPMI_CC_OK;
157
158 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
159 *data_len = 0;
160
161 return rc;
162}
163
164
165void register_netfn_sen_functions()
166{
167 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD);
168 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard);
169
170 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
171 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type);
172
173 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
174 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500175
Chris Austenac4604a2015-10-13 12:43:27 -0500176 return;
177}