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; |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 15 | uint8_t typecode; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 16 | char dbusname[32]; |
| 17 | } ; |
| 18 | |
| 19 | |
| 20 | sensorTypemap_t g_SensorTypeMap[] = { |
| 21 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 22 | {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 Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 32 | {0x12, 0x6F, "SYSTEM_EVENT"}, |
| 33 | {0xC7, 0x03, "SYSTEM"}, |
| 34 | {0xC7, 0x03, "MAIN_PLANAR"}, |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 35 | {0xFF, 0x00, ""}, |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 39 | struct sensor_data_t { |
| 40 | uint8_t sennum; |
| 41 | } __attribute__ ((packed)) ; |
| 42 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 43 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 44 | uint8_t dbus_to_sensor_type(char *p) { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 45 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 46 | sensorTypemap_t *s = g_SensorTypeMap; |
| 47 | char r=0; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 48 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 49 | while (s->number != 0xFF) { |
| 50 | if (!strcmp(s->dbusname,p)) { |
| 51 | r = s->number; |
| 52 | break; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 53 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 54 | s++; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 55 | } |
| 56 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 57 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 58 | if (s->number == 0xFF) |
| 59 | printf("Failed to find Sensor Type %s\n", p); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 60 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 61 | return r; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 62 | } |
| 63 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 64 | |
| 65 | uint8_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 | |
| 79 | uint8_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 Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 92 | if (a.interface[0] == 0) { return 0;} |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 93 | |
| 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 | |
| 107 | ipmi_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 Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 109 | 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 Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 120 | 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 Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 124 | rc = IPMI_CC_SENSOR_INVALID; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 127 | |
| 128 | *data_len = sizeof(buf); |
| 129 | memcpy(response, &buf, *data_len); |
| 130 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 131 | return rc; |
| 132 | } |
| 133 | |
| 134 | |
| 135 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 136 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 137 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 138 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 139 | { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 140 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 141 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 142 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 143 | printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 144 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 145 | updateSensorRecordFromSSRAESC(reqptr); |
| 146 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 147 | *data_len=0; |
| 148 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 149 | return rc; |
| 150 | } |
| 151 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 152 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 153 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 154 | 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 | |
| 165 | void 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 Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 175 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 176 | return; |
| 177 | } |