Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 1 | #include <mapper.h> |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <string.h> |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 4 | #include <bitset> |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 5 | #include <systemd/sd-bus.h> |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 6 | #include "host-ipmid/ipmid-api.h" |
| 7 | #include <phosphor-logging/log.hpp> |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 8 | #include "ipmid.hpp" |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 9 | #include "sensorhandler.h" |
| 10 | #include "types.hpp" |
| 11 | #include "utils.hpp" |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 12 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 13 | extern int updateSensorRecordFromSSRAESC(const void *); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 14 | extern sd_bus *bus; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 15 | extern const ipmi::sensor::IdInfoMap sensors; |
| 16 | using namespace phosphor::logging; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 17 | |
| 18 | void register_netfn_sen_functions() __attribute__((constructor)); |
| 19 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 20 | struct sensorTypemap_t { |
| 21 | uint8_t number; |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 22 | uint8_t typecode; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 23 | char dbusname[32]; |
| 24 | } ; |
| 25 | |
| 26 | |
| 27 | sensorTypemap_t g_SensorTypeMap[] = { |
| 28 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 29 | {0x01, 0x6F, "Temp"}, |
| 30 | {0x0C, 0x6F, "DIMM"}, |
| 31 | {0x0C, 0x6F, "MEMORY_BUFFER"}, |
| 32 | {0x07, 0x6F, "PROC"}, |
| 33 | {0x07, 0x6F, "CORE"}, |
| 34 | {0x07, 0x6F, "CPU"}, |
| 35 | {0x0F, 0x6F, "BootProgress"}, |
| 36 | {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09 |
| 37 | {0xC3, 0x6F, "BootCount"}, |
| 38 | {0x1F, 0x6F, "OperatingSystemStatus"}, |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 39 | {0x12, 0x6F, "SYSTEM_EVENT"}, |
| 40 | {0xC7, 0x03, "SYSTEM"}, |
| 41 | {0xC7, 0x03, "MAIN_PLANAR"}, |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 42 | {0xC2, 0x6F, "PowerCap"}, |
Dhruvaraj S | 0724829 | 2017-03-21 02:14:52 -0500 | [diff] [blame] | 43 | {0xD8, 0x03, "PowerSupplyRedundancy"}, |
Jayanth Othayoth | 0661beb | 2017-03-22 06:00:58 -0500 | [diff] [blame] | 44 | {0xDA, 0x03, "TurboAllowed"}, |
Jayanth Othayoth | d5b2ac0 | 2017-03-27 08:19:18 -0500 | [diff] [blame] | 45 | {0xB4, 0x6F, "PowerSupplyDerating"}, |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 46 | {0xFF, 0x00, ""}, |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 50 | struct sensor_data_t { |
| 51 | uint8_t sennum; |
| 52 | } __attribute__ ((packed)) ; |
| 53 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 54 | struct sensorreadingresp_t { |
| 55 | uint8_t value; |
| 56 | uint8_t operation; |
| 57 | uint8_t indication[2]; |
| 58 | } __attribute__ ((packed)) ; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 59 | |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 60 | // Use a lookup table to find the interface name of a specific sensor |
| 61 | // This will be used until an alternative is found. this is the first |
| 62 | // step for mapping IPMI |
| 63 | int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) { |
| 64 | |
| 65 | char *str1; |
| 66 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 67 | sd_bus_message *reply = NULL, *m=NULL; |
| 68 | |
| 69 | |
| 70 | int r; |
| 71 | |
| 72 | r = sd_bus_message_new_method_call(bus,&m,interface->bus,interface->path,"org.freedesktop.DBus.Properties","Get"); |
| 73 | if (r < 0) { |
| 74 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 75 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 76 | interface->bus, interface->path, interface->interface); |
| 77 | goto final; |
| 78 | } |
| 79 | |
| 80 | r = sd_bus_message_append(m, "ss", "org.openbmc.InventoryItem", property_name); |
| 81 | if (r < 0) { |
| 82 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 83 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 84 | interface->bus, interface->path, interface->interface); |
| 85 | goto final; |
| 86 | } |
| 87 | |
| 88 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 89 | if (r < 0) { |
| 90 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 91 | goto final; |
| 92 | } |
| 93 | |
| 94 | r = sd_bus_message_read(reply, "v", "s", &str1) ; |
| 95 | if (r < 0) { |
| 96 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 97 | goto final; |
| 98 | } |
| 99 | |
| 100 | strcpy(property_value, str1); |
| 101 | |
| 102 | final: |
| 103 | |
| 104 | sd_bus_error_free(&error); |
| 105 | m = sd_bus_message_unref(m); |
| 106 | reply = sd_bus_message_unref(reply); |
| 107 | |
| 108 | return r; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | // Use a lookup table to find the interface name of a specific sensor |
| 113 | // This will be used until an alternative is found. this is the first |
| 114 | // step for mapping IPMI |
| 115 | int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) { |
| 116 | char *busname = NULL; |
| 117 | const char *iface = "org.openbmc.managers.System"; |
| 118 | const char *objname = "/org/openbmc/managers/System"; |
| 119 | char *str1 = NULL, *str2, *str3; |
| 120 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 121 | sd_bus_message *reply = NULL; |
| 122 | |
| 123 | |
| 124 | int r; |
| 125 | r = mapper_get_service(bus, objname, &busname); |
| 126 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 127 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 128 | objname, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 129 | goto final; |
| 130 | } |
| 131 | |
| 132 | r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId", |
| 133 | &error, &reply, "sy", type, num); |
| 134 | if (r < 0) { |
| 135 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 136 | goto final; |
| 137 | } |
| 138 | |
| 139 | r = sd_bus_message_read(reply, "(ss)", &str2, &str3); |
| 140 | if (r < 0) { |
| 141 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 142 | goto final; |
| 143 | } |
| 144 | |
| 145 | r = mapper_get_service(bus, str2, &str1); |
| 146 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 147 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 148 | str2, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 149 | goto final; |
| 150 | } |
| 151 | |
| 152 | strncpy(interface->bus, str1, MAX_DBUS_PATH); |
| 153 | strncpy(interface->path, str2, MAX_DBUS_PATH); |
| 154 | strncpy(interface->interface, str3, MAX_DBUS_PATH); |
| 155 | |
| 156 | interface->sensornumber = num; |
| 157 | |
| 158 | final: |
| 159 | |
| 160 | sd_bus_error_free(&error); |
| 161 | reply = sd_bus_message_unref(reply); |
| 162 | free(busname); |
| 163 | free(str1); |
| 164 | |
| 165 | return r; |
| 166 | } |
| 167 | |
| 168 | |
| 169 | ///////////////////////////////////////////////////////////////////// |
| 170 | // |
| 171 | // Routines used by ipmi commands wanting to interact on the dbus |
| 172 | // |
| 173 | ///////////////////////////////////////////////////////////////////// |
| 174 | int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) { |
| 175 | |
| 176 | |
| 177 | dbus_interface_t a; |
| 178 | int r; |
| 179 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 180 | sd_bus_message *m=NULL; |
| 181 | |
| 182 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n", |
| 183 | number, method, value); |
| 184 | |
| 185 | r = find_openbmc_path("SENSOR", number, &a); |
| 186 | |
| 187 | if (r < 0) { |
| 188 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 193 | if (r < 0) { |
| 194 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 195 | goto final; |
| 196 | } |
| 197 | |
| 198 | r = sd_bus_message_append(m, "v", "s", value); |
| 199 | if (r < 0) { |
| 200 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 201 | goto final; |
| 202 | } |
| 203 | |
| 204 | |
| 205 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 206 | if (r < 0) { |
| 207 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 208 | } |
| 209 | |
| 210 | final: |
| 211 | sd_bus_error_free(&error); |
| 212 | m = sd_bus_message_unref(m); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) { |
| 217 | |
| 218 | |
| 219 | dbus_interface_t a; |
| 220 | int r; |
| 221 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 222 | sd_bus_message *m=NULL; |
| 223 | |
| 224 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n", |
| 225 | number, method, value); |
| 226 | |
| 227 | r = find_openbmc_path("SENSOR", number, &a); |
| 228 | |
| 229 | if (r < 0) { |
| 230 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 235 | if (r < 0) { |
| 236 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 237 | goto final; |
| 238 | } |
| 239 | |
| 240 | r = sd_bus_message_append(m, "v", "i", value); |
| 241 | if (r < 0) { |
| 242 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 243 | goto final; |
| 244 | } |
| 245 | |
| 246 | |
| 247 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 248 | if (r < 0) { |
| 249 | fprintf(stderr, "12 Failed to call the method: %s", strerror(-r)); |
| 250 | } |
| 251 | |
| 252 | final: |
| 253 | sd_bus_error_free(&error); |
| 254 | m = sd_bus_message_unref(m); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 259 | uint8_t dbus_to_sensor_type(char *p) { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 260 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 261 | sensorTypemap_t *s = g_SensorTypeMap; |
| 262 | char r=0; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 263 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 264 | while (s->number != 0xFF) { |
| 265 | if (!strcmp(s->dbusname,p)) { |
| 266 | r = s->number; |
| 267 | break; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 268 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 269 | s++; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 270 | } |
| 271 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 272 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 273 | if (s->number == 0xFF) |
| 274 | printf("Failed to find Sensor Type %s\n", p); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 275 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 276 | return r; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 279 | |
| 280 | uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) { |
| 281 | char fru_type_name[64]; |
| 282 | int r= 0; |
| 283 | |
| 284 | r = find_interface_property_fru_type(a, "fru_type", fru_type_name); |
| 285 | if (r<0) { |
| 286 | fprintf(stderr, "Failed to get a fru type: %s", strerror(-r)); |
| 287 | return -1; |
| 288 | } else { |
| 289 | return dbus_to_sensor_type(fru_type_name); |
| 290 | } |
| 291 | } |
| 292 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 293 | uint8_t get_type_from_interface(dbus_interface_t dbus_if) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 294 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 295 | char *p; |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 296 | uint8_t type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 297 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 298 | // This is where sensors that do not exist in dbus but do |
| 299 | // exist in the host code stop. This should indicate it |
| 300 | // is not a supported sensor |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 301 | if (dbus_if.interface[0] == 0) { return 0;} |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 302 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 303 | if (strstr(dbus_if.interface, "InventoryItem")) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 304 | // InventoryItems are real frus. So need to get the |
| 305 | // fru_type property |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 306 | type = dbus_to_sensor_type_from_dbus(&dbus_if); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 307 | } else { |
| 308 | // Non InventoryItems |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 309 | p = strrchr (dbus_if.path, '/'); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 310 | type = dbus_to_sensor_type(p+1); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 311 | } |
| 312 | |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 313 | return type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 316 | // Replaces find_sensor |
| 317 | uint8_t find_type_for_sensor_number(uint8_t num) { |
| 318 | int r; |
| 319 | dbus_interface_t dbus_if; |
| 320 | r = find_openbmc_path("SENSOR", num, &dbus_if); |
| 321 | if (r < 0) { |
| 322 | fprintf(stderr, "Could not find sensor %d\n", num); |
| 323 | return r; |
| 324 | } |
| 325 | return get_type_from_interface(dbus_if); |
| 326 | } |
| 327 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 328 | |
| 329 | |
| 330 | |
| 331 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 332 | ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 333 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 334 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 335 | { |
| 336 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 337 | ipmi_ret_t rc = IPMI_CC_OK; |
| 338 | |
| 339 | printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum); |
| 340 | |
| 341 | // TODO Not sure what the System-event-sensor is suppose to return |
| 342 | // need to ask Hostboot team |
| 343 | unsigned char buf[] = {0x00,0x6F}; |
| 344 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 345 | buf[0] = find_type_for_sensor_number(reqptr->sennum); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 346 | |
| 347 | // HACK UNTIL Dbus gets updated or we find a better way |
| 348 | if (buf[0] == 0) { |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 349 | rc = IPMI_CC_SENSOR_INVALID; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 350 | } |
| 351 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 352 | |
| 353 | *data_len = sizeof(buf); |
| 354 | memcpy(response, &buf, *data_len); |
| 355 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 356 | return rc; |
| 357 | } |
| 358 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 359 | ipmi_ret_t setSensorReading(void *request) |
| 360 | { |
| 361 | auto cmdData = static_cast<SetSensorReadingReq *>(request); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 362 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 363 | auto assertionStates = |
| 364 | (static_cast<uint16_t>(cmdData->assertOffset8_14)) << 8 | |
| 365 | cmdData->assertOffset0_7; |
| 366 | |
| 367 | auto deassertionStates = |
| 368 | (static_cast<uint16_t>(cmdData->deassertOffset8_14)) << 8 | |
| 369 | cmdData->deassertOffset0_7; |
| 370 | |
| 371 | std::bitset<16> assertionSet(assertionStates); |
| 372 | std::bitset<16> deassertionSet(deassertionStates); |
| 373 | |
| 374 | // Check if the Sensor Number is present |
| 375 | auto iter = sensors.find(cmdData->number); |
| 376 | if (iter == sensors.end()) |
| 377 | { |
| 378 | return IPMI_CC_SENSOR_INVALID; |
| 379 | } |
| 380 | |
| 381 | auto& interfaceList = iter->second.sensorInterfaces; |
| 382 | if (interfaceList.empty()) |
| 383 | { |
| 384 | log<level::ERR>("Interface List empty for the sensor", |
| 385 | entry("Sensor Number = %d", cmdData->number)); |
| 386 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 387 | } |
| 388 | |
| 389 | ipmi::sensor::ObjectMap objects; |
| 390 | ipmi::sensor::InterfaceMap interfaces; |
| 391 | for (const auto& interface : interfaceList) |
| 392 | { |
| 393 | for (const auto& property : interface.second) |
| 394 | { |
| 395 | ipmi::sensor::PropertyMap props; |
| 396 | bool valid = false; |
| 397 | for (const auto& value : property.second) |
| 398 | { |
| 399 | if (assertionSet.test(value.first)) |
| 400 | { |
| 401 | props.emplace(property.first, value.second.assert); |
| 402 | valid = true; |
| 403 | } |
| 404 | else if (deassertionSet.test(value.first)) |
| 405 | { |
| 406 | props.emplace(property.first, value.second.deassert); |
| 407 | valid = true; |
| 408 | } |
| 409 | } |
| 410 | if (valid) |
| 411 | { |
| 412 | interfaces.emplace(interface.first, std::move(props)); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | objects.emplace(iter->second.sensorPath, std::move(interfaces)); |
| 417 | |
Patrick Williams | 4736b91 | 2017-04-18 11:50:57 -0500 | [diff] [blame] | 418 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 419 | using namespace std::string_literals; |
| 420 | static const auto intf = "xyz.openbmc_project.Inventory.Manager"s; |
| 421 | static const auto path = "/xyz/openbmc_project/inventory"s; |
| 422 | std::string service; |
| 423 | |
| 424 | try |
| 425 | { |
| 426 | service = ipmi::getService(bus, intf, path); |
| 427 | |
| 428 | // Update the inventory manager |
| 429 | auto pimMsg = bus.new_method_call(service.c_str(), |
| 430 | path.c_str(), |
| 431 | intf.c_str(), |
| 432 | "Notify"); |
| 433 | pimMsg.append(std::move(objects)); |
| 434 | auto inventoryMgrResponseMsg = bus.call(pimMsg); |
| 435 | if (inventoryMgrResponseMsg.is_method_error()) |
| 436 | { |
| 437 | log<level::ERR>("Error in notify call"); |
| 438 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 439 | } |
| 440 | } |
| 441 | catch (const std::runtime_error& e) |
| 442 | { |
| 443 | log<level::ERR>(e.what()); |
| 444 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 445 | } |
| 446 | |
| 447 | return IPMI_CC_OK; |
| 448 | } |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 449 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 450 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 451 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 452 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 453 | { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 454 | sensor_data_t *reqptr = (sensor_data_t*)request; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 455 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 456 | printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 457 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 458 | /* |
| 459 | * This would support the Set Sensor Reading command for the presence |
| 460 | * and functional state of Processor, Core & DIMM. For the remaining |
| 461 | * sensors the existing support is invoked. |
| 462 | */ |
| 463 | auto ipmiRC = setSensorReading(request); |
| 464 | |
| 465 | if(ipmiRC == IPMI_CC_SENSOR_INVALID) |
| 466 | { |
| 467 | updateSensorRecordFromSSRAESC(reqptr); |
| 468 | ipmiRC = IPMI_CC_OK; |
| 469 | } |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 470 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 471 | *data_len=0; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 472 | return ipmiRC; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 473 | } |
| 474 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 475 | |
| 476 | ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 477 | ipmi_request_t request, ipmi_response_t response, |
| 478 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 479 | { |
| 480 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 481 | ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID; |
| 482 | uint8_t type; |
| 483 | sensorreadingresp_t *resp = (sensorreadingresp_t*) response; |
| 484 | int r; |
| 485 | dbus_interface_t a; |
| 486 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 487 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 488 | int reading = 0; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 489 | |
| 490 | |
| 491 | printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum); |
| 492 | |
| 493 | r = find_openbmc_path("SENSOR", reqptr->sennum, &a); |
| 494 | |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 495 | if (r < 0) { |
| 496 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 497 | return IPMI_CC_SENSOR_INVALID; |
| 498 | } |
| 499 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 500 | type = get_type_from_interface(a); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 501 | if(type == 0) { |
| 502 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 503 | return IPMI_CC_SENSOR_INVALID; |
| 504 | } |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 505 | |
| 506 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface); |
| 507 | |
| 508 | *data_len=0; |
| 509 | |
| 510 | switch(type) { |
| 511 | case 0xC3: |
| 512 | case 0xC2: |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 513 | r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value", NULL, &reply, "i"); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 514 | if (r < 0) { |
| 515 | fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r)); |
| 516 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 517 | a.bus, a.path, a.interface); |
| 518 | break; |
| 519 | } |
| 520 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 521 | r = sd_bus_message_read(reply, "i", &reading); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 522 | if (r < 0) { |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 523 | fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r)); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 524 | break; |
| 525 | } |
| 526 | |
| 527 | printf("Contents of a 0x%02x is 0x%02x\n", type, reading); |
| 528 | |
| 529 | rc = IPMI_CC_OK; |
| 530 | *data_len=sizeof(sensorreadingresp_t); |
| 531 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 532 | resp->value = (uint8_t)reading; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 533 | resp->operation = 0; |
| 534 | resp->indication[0] = 0; |
| 535 | resp->indication[1] = 0; |
| 536 | break; |
| 537 | |
| 538 | default: |
| 539 | *data_len=0; |
| 540 | rc = IPMI_CC_SENSOR_INVALID; |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 545 | reply = sd_bus_message_unref(reply); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 546 | |
| 547 | return rc; |
| 548 | } |
| 549 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 550 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 551 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 552 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 553 | { |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 554 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 555 | |
| 556 | printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 557 | *data_len = 0; |
| 558 | |
| 559 | return rc; |
| 560 | } |
| 561 | |
| 562 | |
| 563 | void register_netfn_sen_functions() |
| 564 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 565 | // <Wildcard Command> |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 566 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 567 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard, |
| 568 | PRIVILEGE_USER); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 569 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 570 | // <Get Sensor Type> |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 571 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 572 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type, |
| 573 | PRIVILEGE_USER); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 574 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 575 | // <Set Sensor Reading and Event Status> |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 576 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 577 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor, |
| 578 | PRIVILEGE_OPERATOR); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 579 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 580 | // <Get Sensor Reading> |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 581 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING); |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 582 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, NULL, |
| 583 | ipmi_sen_get_sensor_reading, PRIVILEGE_USER); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 584 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 585 | return; |
| 586 | } |