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