Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1 | #include "sensorhandler.h" |
| 2 | #include "ipmid-api.h" |
| 3 | #include <stdio.h> |
| 4 | #include <string.h> |
| 5 | #include <stdint.h> |
| 6 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 7 | extern int updateSensorRecordFromSSRAESC(const void *); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 8 | extern int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) ; |
| 9 | extern int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) ; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 10 | |
| 11 | void register_netfn_sen_functions() __attribute__((constructor)); |
| 12 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 13 | struct sensorTypemap_t { |
| 14 | uint8_t number; |
| 15 | char dbusname[32]; |
| 16 | } ; |
| 17 | |
| 18 | |
| 19 | sensorTypemap_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 Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 34 | |
| 35 | struct sensor_data_t { |
| 36 | uint8_t sennum; |
| 37 | } __attribute__ ((packed)) ; |
| 38 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 39 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 40 | uint8_t dbus_to_sensor_type(char *p) { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 41 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 42 | sensorTypemap_t *s = g_SensorTypeMap; |
| 43 | char r=0; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 44 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 45 | while (s->number != 0xFF) { |
| 46 | if (!strcmp(s->dbusname,p)) { |
| 47 | r = s->number; |
| 48 | break; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 49 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 50 | s++; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 53 | if (s->number == 0xFF) |
| 54 | printf("Failed to find Sensor Type %s\n", p); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 55 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 56 | return r; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 59 | |
| 60 | uint8_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 | |
| 74 | uint8_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 | |
| 102 | ipmi_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 Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 104 | 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 Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 115 | 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 Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 130 | |
| 131 | *data_len = sizeof(buf); |
| 132 | memcpy(response, &buf, *data_len); |
| 133 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 134 | return rc; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 139 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 140 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 141 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 142 | { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 143 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 144 | ipmi_ret_t rc = IPMI_CC_OK; |
| 145 | unsigned short rlen; |
| 146 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 147 | rlen = (unsigned short) *data_len; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 148 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 149 | printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 150 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 151 | updateSensorRecordFromSSRAESC(reqptr); |
| 152 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 153 | *data_len=0; |
| 154 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 155 | return rc; |
| 156 | } |
| 157 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 158 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 159 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 160 | 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 | |
| 171 | void 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 Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 181 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 182 | return; |
| 183 | } |