Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 1 | #include <mapper.h> |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 2 | #include <math.h> |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include <string.h> |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 5 | #include <set> |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 6 | #include <bitset> |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 8 | #include <systemd/sd-bus.h> |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 9 | #include "host-ipmid/ipmid-api.h" |
| 10 | #include <phosphor-logging/log.hpp> |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/elog-errors.hpp> |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 12 | #include "ipmid.hpp" |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 13 | #include "sensorhandler.h" |
| 14 | #include "types.hpp" |
| 15 | #include "utils.hpp" |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 16 | #include "xyz/openbmc_project/Common/error.hpp" |
| 17 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 18 | extern int updateSensorRecordFromSSRAESC(const void *); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 19 | extern sd_bus *bus; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 20 | extern const ipmi::sensor::IdInfoMap sensors; |
| 21 | using namespace phosphor::logging; |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 22 | using InternalFailure = |
| 23 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 24 | |
| 25 | void register_netfn_sen_functions() __attribute__((constructor)); |
| 26 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 27 | struct sensorTypemap_t { |
| 28 | uint8_t number; |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 29 | uint8_t typecode; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 30 | char dbusname[32]; |
| 31 | } ; |
| 32 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 33 | sensorTypemap_t g_SensorTypeMap[] = { |
| 34 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 35 | {0x01, 0x6F, "Temp"}, |
| 36 | {0x0C, 0x6F, "DIMM"}, |
| 37 | {0x0C, 0x6F, "MEMORY_BUFFER"}, |
| 38 | {0x07, 0x6F, "PROC"}, |
| 39 | {0x07, 0x6F, "CORE"}, |
| 40 | {0x07, 0x6F, "CPU"}, |
| 41 | {0x0F, 0x6F, "BootProgress"}, |
| 42 | {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09 |
| 43 | {0xC3, 0x6F, "BootCount"}, |
| 44 | {0x1F, 0x6F, "OperatingSystemStatus"}, |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 45 | {0x12, 0x6F, "SYSTEM_EVENT"}, |
| 46 | {0xC7, 0x03, "SYSTEM"}, |
| 47 | {0xC7, 0x03, "MAIN_PLANAR"}, |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 48 | {0xC2, 0x6F, "PowerCap"}, |
Tom Joseph | 558184e | 2017-09-01 13:45:05 +0530 | [diff] [blame] | 49 | {0x0b, 0xCA, "PowerSupplyRedundancy"}, |
Jayanth Othayoth | 0661beb | 2017-03-22 06:00:58 -0500 | [diff] [blame] | 50 | {0xDA, 0x03, "TurboAllowed"}, |
Tom Joseph | 558184e | 2017-09-01 13:45:05 +0530 | [diff] [blame] | 51 | {0xD8, 0xC8, "PowerSupplyDerating"}, |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 52 | {0xFF, 0x00, ""}, |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 56 | struct sensor_data_t { |
| 57 | uint8_t sennum; |
| 58 | } __attribute__ ((packed)) ; |
| 59 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 60 | struct sensorreadingresp_t { |
| 61 | uint8_t value; |
| 62 | uint8_t operation; |
| 63 | uint8_t indication[2]; |
| 64 | } __attribute__ ((packed)) ; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 65 | |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 66 | // Use a lookup table to find the interface name of a specific sensor |
| 67 | // This will be used until an alternative is found. this is the first |
| 68 | // step for mapping IPMI |
| 69 | int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) { |
| 70 | |
| 71 | char *str1; |
| 72 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 73 | sd_bus_message *reply = NULL, *m=NULL; |
| 74 | |
| 75 | |
| 76 | int r; |
| 77 | |
| 78 | r = sd_bus_message_new_method_call(bus,&m,interface->bus,interface->path,"org.freedesktop.DBus.Properties","Get"); |
| 79 | if (r < 0) { |
| 80 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 81 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 82 | interface->bus, interface->path, interface->interface); |
| 83 | goto final; |
| 84 | } |
| 85 | |
| 86 | r = sd_bus_message_append(m, "ss", "org.openbmc.InventoryItem", property_name); |
| 87 | if (r < 0) { |
| 88 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 89 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 90 | interface->bus, interface->path, interface->interface); |
| 91 | goto final; |
| 92 | } |
| 93 | |
| 94 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 95 | if (r < 0) { |
| 96 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 97 | goto final; |
| 98 | } |
| 99 | |
| 100 | r = sd_bus_message_read(reply, "v", "s", &str1) ; |
| 101 | if (r < 0) { |
| 102 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 103 | goto final; |
| 104 | } |
| 105 | |
| 106 | strcpy(property_value, str1); |
| 107 | |
| 108 | final: |
| 109 | |
| 110 | sd_bus_error_free(&error); |
| 111 | m = sd_bus_message_unref(m); |
| 112 | reply = sd_bus_message_unref(reply); |
| 113 | |
| 114 | return r; |
| 115 | } |
| 116 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 117 | int get_bus_for_path(const char *path, char **busname) { |
| 118 | return mapper_get_service(bus, path, busname); |
| 119 | } |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 120 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 121 | int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) { |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 122 | char *busname = NULL; |
| 123 | const char *iface = "org.openbmc.managers.System"; |
| 124 | const char *objname = "/org/openbmc/managers/System"; |
| 125 | char *str1 = NULL, *str2, *str3; |
| 126 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 127 | sd_bus_message *reply = NULL; |
| 128 | |
| 129 | |
| 130 | int r; |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 131 | r = get_bus_for_path(objname, &busname); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 132 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 133 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 134 | objname, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 135 | goto final; |
| 136 | } |
| 137 | |
| 138 | r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId", |
| 139 | &error, &reply, "sy", type, num); |
| 140 | if (r < 0) { |
| 141 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 142 | goto final; |
| 143 | } |
| 144 | |
| 145 | r = sd_bus_message_read(reply, "(ss)", &str2, &str3); |
| 146 | if (r < 0) { |
| 147 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 148 | goto final; |
| 149 | } |
| 150 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 151 | r = get_bus_for_path(str2, &str1); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 152 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 153 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 154 | str2, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 155 | goto final; |
| 156 | } |
| 157 | |
| 158 | strncpy(interface->bus, str1, MAX_DBUS_PATH); |
| 159 | strncpy(interface->path, str2, MAX_DBUS_PATH); |
| 160 | strncpy(interface->interface, str3, MAX_DBUS_PATH); |
| 161 | |
| 162 | interface->sensornumber = num; |
Emily Shaffer | 7117441 | 2017-04-05 15:10:40 -0700 | [diff] [blame] | 163 | // Make sure we know that the type hasn't been set, as newer codebase will |
| 164 | // set it automatically from the YAML at this step. |
| 165 | interface->sensortype = 0; |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 166 | |
| 167 | final: |
| 168 | |
| 169 | sd_bus_error_free(&error); |
| 170 | reply = sd_bus_message_unref(reply); |
| 171 | free(busname); |
| 172 | free(str1); |
| 173 | |
| 174 | return r; |
| 175 | } |
| 176 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 177 | // Use a lookup table to find the interface name of a specific sensor |
| 178 | // This will be used until an alternative is found. this is the first |
| 179 | // step for mapping IPMI |
| 180 | int find_openbmc_path(uint8_t num, dbus_interface_t *interface) { |
| 181 | int rc; |
| 182 | |
| 183 | // When the sensor map does not contain the sensor requested, |
| 184 | // fall back to the legacy DBus lookup (deprecated) |
| 185 | const auto& sensor_it = sensors.find(num); |
| 186 | if (sensor_it == sensors.end()) |
| 187 | { |
| 188 | return legacy_dbus_openbmc_path("SENSOR", num, interface); |
| 189 | } |
| 190 | |
| 191 | const auto& info = sensor_it->second; |
| 192 | |
Patrick Williams | 8451edf | 2017-06-13 09:01:06 -0500 | [diff] [blame] | 193 | char* busname = nullptr; |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 194 | rc = get_bus_for_path(info.sensorPath.c_str(), &busname); |
| 195 | if (rc < 0) { |
| 196 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 197 | info.sensorPath.c_str(), |
| 198 | busname); |
| 199 | goto final; |
| 200 | } |
| 201 | |
| 202 | interface->sensortype = info.sensorType; |
| 203 | strcpy(interface->bus, busname); |
| 204 | strcpy(interface->path, info.sensorPath.c_str()); |
| 205 | // Take the interface name from the beginning of the DbusInterfaceMap. This |
| 206 | // works for the Value interface but may not suffice for more complex |
| 207 | // sensors. |
| 208 | // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103 |
Deepak Kodihalli | 1bb0d38 | 2017-08-12 02:01:27 -0500 | [diff] [blame] | 209 | strcpy(interface->interface, info.propertyInterfaces.begin()->first.c_str()); |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 210 | interface->sensornumber = num; |
| 211 | |
| 212 | final: |
| 213 | free(busname); |
| 214 | return rc; |
| 215 | } |
| 216 | |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 217 | |
| 218 | ///////////////////////////////////////////////////////////////////// |
| 219 | // |
| 220 | // Routines used by ipmi commands wanting to interact on the dbus |
| 221 | // |
| 222 | ///////////////////////////////////////////////////////////////////// |
| 223 | int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) { |
| 224 | |
| 225 | |
| 226 | dbus_interface_t a; |
| 227 | int r; |
| 228 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 229 | sd_bus_message *m=NULL; |
| 230 | |
| 231 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n", |
| 232 | number, method, value); |
| 233 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 234 | r = find_openbmc_path(number, &a); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 235 | |
| 236 | if (r < 0) { |
| 237 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 242 | if (r < 0) { |
| 243 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 244 | goto final; |
| 245 | } |
| 246 | |
| 247 | r = sd_bus_message_append(m, "v", "s", value); |
| 248 | if (r < 0) { |
| 249 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 250 | goto final; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 255 | if (r < 0) { |
| 256 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 257 | } |
| 258 | |
| 259 | final: |
| 260 | sd_bus_error_free(&error); |
| 261 | m = sd_bus_message_unref(m); |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) { |
| 266 | |
| 267 | |
| 268 | dbus_interface_t a; |
| 269 | int r; |
| 270 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 271 | sd_bus_message *m=NULL; |
| 272 | |
| 273 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n", |
| 274 | number, method, value); |
| 275 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 276 | r = find_openbmc_path(number, &a); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 277 | |
| 278 | if (r < 0) { |
| 279 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 284 | if (r < 0) { |
| 285 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 286 | goto final; |
| 287 | } |
| 288 | |
| 289 | r = sd_bus_message_append(m, "v", "i", value); |
| 290 | if (r < 0) { |
| 291 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 292 | goto final; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 297 | if (r < 0) { |
| 298 | fprintf(stderr, "12 Failed to call the method: %s", strerror(-r)); |
| 299 | } |
| 300 | |
| 301 | final: |
| 302 | sd_bus_error_free(&error); |
| 303 | m = sd_bus_message_unref(m); |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 308 | uint8_t dbus_to_sensor_type(char *p) { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 309 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 310 | sensorTypemap_t *s = g_SensorTypeMap; |
| 311 | char r=0; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 312 | while (s->number != 0xFF) { |
| 313 | if (!strcmp(s->dbusname,p)) { |
Tom Joseph | 558184e | 2017-09-01 13:45:05 +0530 | [diff] [blame] | 314 | r = s->typecode; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 315 | break; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 316 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 317 | s++; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 320 | if (s->number == 0xFF) |
| 321 | printf("Failed to find Sensor Type %s\n", p); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 322 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 323 | return r; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 324 | } |
| 325 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 326 | |
| 327 | uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) { |
| 328 | char fru_type_name[64]; |
| 329 | int r= 0; |
| 330 | |
| 331 | r = find_interface_property_fru_type(a, "fru_type", fru_type_name); |
| 332 | if (r<0) { |
| 333 | fprintf(stderr, "Failed to get a fru type: %s", strerror(-r)); |
| 334 | return -1; |
| 335 | } else { |
| 336 | return dbus_to_sensor_type(fru_type_name); |
| 337 | } |
| 338 | } |
| 339 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 340 | uint8_t get_type_from_interface(dbus_interface_t dbus_if) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 341 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 342 | char *p; |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 343 | uint8_t type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 344 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 345 | // This is where sensors that do not exist in dbus but do |
| 346 | // exist in the host code stop. This should indicate it |
| 347 | // is not a supported sensor |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 348 | if (dbus_if.interface[0] == 0) { return 0;} |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 349 | |
Emily Shaffer | 7117441 | 2017-04-05 15:10:40 -0700 | [diff] [blame] | 350 | // Fetch type from interface itself. |
| 351 | if (dbus_if.sensortype != 0) |
| 352 | { |
| 353 | type = dbus_if.sensortype; |
| 354 | } |
| 355 | // Legacy codebase does not populate type during initial handling: |
| 356 | else if (strstr(dbus_if.interface, "InventoryItem")) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 357 | // InventoryItems are real frus. So need to get the |
| 358 | // fru_type property |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 359 | type = dbus_to_sensor_type_from_dbus(&dbus_if); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 360 | } else { |
| 361 | // Non InventoryItems |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 362 | p = strrchr (dbus_if.path, '/'); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 363 | type = dbus_to_sensor_type(p+1); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 364 | } |
| 365 | |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 366 | return type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 367 | } |
| 368 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 369 | // Replaces find_sensor |
| 370 | uint8_t find_type_for_sensor_number(uint8_t num) { |
| 371 | int r; |
| 372 | dbus_interface_t dbus_if; |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 373 | r = find_openbmc_path(num, &dbus_if); |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 374 | if (r < 0) { |
| 375 | fprintf(stderr, "Could not find sensor %d\n", num); |
| 376 | return r; |
| 377 | } |
| 378 | return get_type_from_interface(dbus_if); |
| 379 | } |
| 380 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 381 | |
| 382 | |
| 383 | |
| 384 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 385 | ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 386 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 387 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 388 | { |
| 389 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 390 | ipmi_ret_t rc = IPMI_CC_OK; |
| 391 | |
| 392 | printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum); |
| 393 | |
| 394 | // TODO Not sure what the System-event-sensor is suppose to return |
| 395 | // need to ask Hostboot team |
| 396 | unsigned char buf[] = {0x00,0x6F}; |
| 397 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 398 | buf[0] = find_type_for_sensor_number(reqptr->sennum); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 399 | |
| 400 | // HACK UNTIL Dbus gets updated or we find a better way |
| 401 | if (buf[0] == 0) { |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 402 | rc = IPMI_CC_SENSOR_INVALID; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 405 | |
| 406 | *data_len = sizeof(buf); |
| 407 | memcpy(response, &buf, *data_len); |
| 408 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 409 | return rc; |
| 410 | } |
| 411 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 412 | const std::set<std::string> analogSensorInterfaces = |
| 413 | { |
| 414 | "xyz.openbmc_project.Sensor.Value", |
| 415 | }; |
| 416 | |
| 417 | bool isAnalogSensor(const std::string& interface) |
| 418 | { |
| 419 | return (analogSensorInterfaces.count(interface)); |
| 420 | } |
| 421 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 422 | ipmi_ret_t setSensorReading(void *request) |
| 423 | { |
Tom Joseph | 816e92b | 2017-09-06 19:23:00 +0530 | [diff] [blame] | 424 | ipmi::sensor::SetSensorReadingReq cmdData = |
| 425 | *(static_cast<ipmi::sensor::SetSensorReadingReq *>(request)); |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 426 | |
| 427 | // Check if the Sensor Number is present |
Dhruvaraj Subhashchandran | e0af720 | 2017-07-12 06:35:20 -0500 | [diff] [blame] | 428 | const auto iter = sensors.find(cmdData.number); |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 429 | if (iter == sensors.end()) |
| 430 | { |
| 431 | return IPMI_CC_SENSOR_INVALID; |
| 432 | } |
| 433 | |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 434 | try |
| 435 | { |
| 436 | return iter->second.updateFunc(cmdData, iter->second); |
| 437 | } |
| 438 | catch (InternalFailure& e) |
| 439 | { |
| 440 | log<level::ERR>("Set sensor failed", |
| 441 | entry("SENSOR_NUM=%d", cmdData.number)); |
| 442 | commit<InternalFailure>(); |
| 443 | } |
Tom Joseph | 8202432 | 2017-09-28 20:07:29 +0530 | [diff] [blame] | 444 | catch (const std::runtime_error& e) |
| 445 | { |
| 446 | log<level::ERR>(e.what()); |
| 447 | } |
Dhruvaraj Subhashchandran | 18e9999 | 2017-08-09 09:10:47 -0500 | [diff] [blame] | 448 | |
| 449 | return IPMI_CC_UNSPECIFIED_ERROR; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 450 | } |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 451 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 452 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 453 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 454 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 455 | { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 456 | sensor_data_t *reqptr = (sensor_data_t*)request; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 457 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 458 | printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 459 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 460 | /* |
| 461 | * This would support the Set Sensor Reading command for the presence |
| 462 | * and functional state of Processor, Core & DIMM. For the remaining |
| 463 | * sensors the existing support is invoked. |
| 464 | */ |
| 465 | auto ipmiRC = setSensorReading(request); |
| 466 | |
| 467 | if(ipmiRC == IPMI_CC_SENSOR_INVALID) |
| 468 | { |
| 469 | updateSensorRecordFromSSRAESC(reqptr); |
| 470 | ipmiRC = IPMI_CC_OK; |
| 471 | } |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 472 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 473 | *data_len=0; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 474 | return ipmiRC; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 475 | } |
| 476 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 477 | |
| 478 | ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 479 | ipmi_request_t request, ipmi_response_t response, |
| 480 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 481 | { |
| 482 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 483 | ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID; |
Tom Joseph | 40c35b1 | 2017-09-07 02:04:42 +0530 | [diff] [blame] | 484 | uint8_t type = 0; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 485 | sensorreadingresp_t *resp = (sensorreadingresp_t*) response; |
| 486 | int r; |
| 487 | dbus_interface_t a; |
| 488 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 489 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 490 | int reading = 0; |
Dhruvaraj Subhashchandran | 6244f93 | 2017-11-23 01:08:46 -0600 | [diff] [blame] | 491 | char* assertion = NULL; |
Tom Joseph | c6162fb | 2018-01-25 01:55:20 +0530 | [diff] [blame] | 492 | ipmi::sensor::GetSensorResponse getResponse {}; |
| 493 | static constexpr auto scanningEnabledBit = 6; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 494 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 495 | printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum); |
| 496 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 497 | r = find_openbmc_path(reqptr->sennum, &a); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 498 | |
Tom Joseph | 40c35b1 | 2017-09-07 02:04:42 +0530 | [diff] [blame] | 499 | if (r < 0) |
| 500 | { |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 501 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 502 | } |
Tom Joseph | 40c35b1 | 2017-09-07 02:04:42 +0530 | [diff] [blame] | 503 | else |
| 504 | { |
| 505 | type = get_type_from_interface(a); |
| 506 | if(type == 0) { |
| 507 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 508 | return IPMI_CC_SENSOR_INVALID; |
| 509 | } |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 510 | |
Tom Joseph | 40c35b1 | 2017-09-07 02:04:42 +0530 | [diff] [blame] | 511 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, |
| 512 | a.interface); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 513 | } |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 514 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 515 | *data_len=0; |
| 516 | |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 517 | int64_t raw_value; |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 518 | ipmi::sensor::Info sensor; |
| 519 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 520 | switch(type) { |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 521 | case 0xC2: |
Dhruvaraj Subhashchandran | d12ae75 | 2017-10-04 00:33:27 -0500 | [diff] [blame] | 522 | case 0xC8: |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 523 | 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] | 524 | if (r < 0) { |
| 525 | fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r)); |
| 526 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 527 | a.bus, a.path, a.interface); |
| 528 | break; |
| 529 | } |
| 530 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 531 | r = sd_bus_message_read(reply, "i", &reading); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 532 | if (r < 0) { |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 533 | fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r)); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 534 | break; |
| 535 | } |
| 536 | |
| 537 | printf("Contents of a 0x%02x is 0x%02x\n", type, reading); |
| 538 | |
| 539 | rc = IPMI_CC_OK; |
| 540 | *data_len=sizeof(sensorreadingresp_t); |
| 541 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 542 | resp->value = (uint8_t)reading; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 543 | resp->operation = 0; |
| 544 | resp->indication[0] = 0; |
| 545 | resp->indication[1] = 0; |
| 546 | break; |
| 547 | |
Dhruvaraj Subhashchandran | 6244f93 | 2017-11-23 01:08:46 -0600 | [diff] [blame] | 548 | //TODO openbmc/openbmc#2154 Move this sensor to right place. |
| 549 | case 0xCA: |
| 550 | r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value", NULL, &reply, "s"); |
| 551 | if (r < 0) { |
| 552 | fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r)); |
| 553 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 554 | a.bus, a.path, a.interface); |
| 555 | break; |
| 556 | } |
| 557 | |
| 558 | r = sd_bus_message_read(reply, "s", &assertion); |
| 559 | if (r < 0) { |
| 560 | fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r)); |
| 561 | break; |
| 562 | } |
| 563 | |
| 564 | rc = IPMI_CC_OK; |
| 565 | *data_len=sizeof(sensorreadingresp_t); |
| 566 | |
| 567 | resp->value = 0; |
| 568 | resp->operation = 0; |
| 569 | if (strcmp(assertion,"Enabled") == 0) |
| 570 | { |
| 571 | resp->indication[0] = 0x02; |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | resp->indication[0] = 0x1; |
| 576 | } |
| 577 | resp->indication[1] = 0; |
Dhruvaraj Subhashchandran | 6244f93 | 2017-11-23 01:08:46 -0600 | [diff] [blame] | 578 | break; |
| 579 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 580 | case IPMI_SENSOR_TEMP: |
| 581 | case IPMI_SENSOR_VOLTAGE: |
| 582 | case IPMI_SENSOR_CURRENT: |
| 583 | case IPMI_SENSOR_FAN: |
| 584 | // Get reading for /xyz/openbmc_project/Sensor/Value.interface |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 585 | if(sensors.find(reqptr->sennum) == sensors.end()) |
| 586 | { |
| 587 | fprintf(stderr, "Failed to find config entry for Sensor 0x%02x\n", |
| 588 | reqptr->sennum); |
| 589 | return IPMI_CC_SENSOR_INVALID; |
| 590 | } |
| 591 | |
| 592 | sensor = sensors.at(reqptr->sennum); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 593 | if (ipmi::sensor::Mutability::Read != |
| 594 | (sensor.mutability & ipmi::sensor::Mutability::Read)) |
| 595 | { |
| 596 | log<level::ERR>("Sensor was not readable.\n"); |
| 597 | return IPMI_CC_SENSOR_INVALID; |
| 598 | } |
| 599 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 600 | |
| 601 | // Get value |
| 602 | r = sd_bus_get_property_trivial(bus, |
| 603 | a.bus, |
| 604 | a.path, |
| 605 | a.interface, |
| 606 | "Value", |
| 607 | NULL, |
| 608 | 'x', |
| 609 | &raw_value); |
| 610 | if (r < 0) { |
| 611 | fprintf(stderr, |
| 612 | "Failed to call sd_bus_get_property:%d, %s, 'value'\n", |
| 613 | r, |
| 614 | strerror(-r)); |
| 615 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 616 | a.bus, a.path, a.interface); |
| 617 | break; |
| 618 | } |
| 619 | |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 620 | // Prevent div0 |
| 621 | if (sensor.coefficientM == 0) { |
| 622 | sensor.coefficientM = 1; |
| 623 | }; |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 624 | |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 625 | resp->value = static_cast<uint8_t>( |
| 626 | (raw_value - sensor.scaledOffset) / sensor.coefficientM); |
Tom Joseph | c6162fb | 2018-01-25 01:55:20 +0530 | [diff] [blame] | 627 | resp->operation = 1 << scanningEnabledBit; // scanning enabled |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 628 | resp->indication[0] = 0; // not a threshold sensor. ignore |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 629 | resp->indication[1] = 0; |
| 630 | rc = IPMI_CC_OK; |
| 631 | *data_len=sizeof(sensorreadingresp_t); |
| 632 | break; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 633 | default: |
Tom Joseph | 14c1546 | 2017-09-07 02:16:51 +0530 | [diff] [blame] | 634 | { |
| 635 | const auto iter = sensors.find(reqptr->sennum); |
| 636 | if (iter == sensors.end()) |
| 637 | { |
| 638 | return IPMI_CC_SENSOR_INVALID; |
| 639 | } |
| 640 | |
| 641 | try |
| 642 | { |
Tom Joseph | c6162fb | 2018-01-25 01:55:20 +0530 | [diff] [blame] | 643 | getResponse = iter->second.getFunc(iter->second); |
Tom Joseph | 14c1546 | 2017-09-07 02:16:51 +0530 | [diff] [blame] | 644 | *data_len = getResponse.size(); |
| 645 | memcpy(resp, getResponse.data(), *data_len); |
Tom Joseph | c6162fb | 2018-01-25 01:55:20 +0530 | [diff] [blame] | 646 | resp->operation = 1 << scanningEnabledBit; |
Tom Joseph | 14c1546 | 2017-09-07 02:16:51 +0530 | [diff] [blame] | 647 | return IPMI_CC_OK; |
| 648 | } |
| 649 | catch (InternalFailure& e) |
| 650 | { |
Tom Joseph | c6162fb | 2018-01-25 01:55:20 +0530 | [diff] [blame] | 651 | *data_len = getResponse.size(); |
| 652 | memcpy(resp, getResponse.data(), *data_len); |
| 653 | return IPMI_CC_OK; |
Tom Joseph | 14c1546 | 2017-09-07 02:16:51 +0530 | [diff] [blame] | 654 | } |
Tom Joseph | 8202432 | 2017-09-28 20:07:29 +0530 | [diff] [blame] | 655 | catch (const std::runtime_error& e) |
| 656 | { |
Tom Joseph | c6162fb | 2018-01-25 01:55:20 +0530 | [diff] [blame] | 657 | *data_len = getResponse.size(); |
| 658 | memcpy(resp, getResponse.data(), *data_len); |
| 659 | return IPMI_CC_OK; |
Tom Joseph | 8202432 | 2017-09-28 20:07:29 +0530 | [diff] [blame] | 660 | } |
Tom Joseph | 14c1546 | 2017-09-07 02:16:51 +0530 | [diff] [blame] | 661 | } |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 662 | } |
| 663 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 664 | reply = sd_bus_message_unref(reply); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 665 | |
| 666 | return rc; |
| 667 | } |
| 668 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 669 | ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 670 | ipmi_request_t request, ipmi_response_t response, |
| 671 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 672 | { |
| 673 | constexpr auto warningThresholdInterface = |
| 674 | "xyz.openbmc_project.Sensor.Threshold.Warning"; |
| 675 | constexpr auto criticalThresholdInterface = |
| 676 | "xyz.openbmc_project.Sensor.Threshold.Critical"; |
| 677 | constexpr auto valueInterface = |
| 678 | "xyz.openbmc_project.Sensor.Value"; |
| 679 | constexpr auto sensorRoot = "/xyz/openbmc_project/sensors"; |
| 680 | |
| 681 | ipmi::sensor::Thresholds thresholds = |
| 682 | { |
| 683 | { |
| 684 | warningThresholdInterface, |
| 685 | { |
| 686 | { |
| 687 | "WarningLow", |
| 688 | ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK, |
| 689 | ipmi::sensor::ThresholdIndex::NON_CRITICAL_LOW_IDX |
| 690 | }, |
| 691 | { |
| 692 | "WarningHigh", |
| 693 | ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK, |
| 694 | ipmi::sensor::ThresholdIndex::NON_CRITICAL_HIGH_IDX |
| 695 | } |
| 696 | } |
| 697 | }, |
| 698 | { |
| 699 | criticalThresholdInterface, |
| 700 | { |
| 701 | { |
| 702 | "CriticalLow", |
| 703 | ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK, |
| 704 | ipmi::sensor::ThresholdIndex::CRITICAL_LOW_IDX |
| 705 | }, |
| 706 | { |
| 707 | "CriticalHigh", |
| 708 | ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK, |
| 709 | ipmi::sensor::ThresholdIndex::CRITICAL_HIGH_IDX |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | }; |
| 714 | |
| 715 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
| 716 | |
| 717 | if (*data_len != sizeof(uint8_t)) |
| 718 | { |
| 719 | return IPMI_CC_REQ_DATA_LEN_INVALID; |
| 720 | } |
| 721 | auto sensorNum = *(reinterpret_cast<uint8_t*>(request)); |
| 722 | |
| 723 | auto responseData = |
| 724 | reinterpret_cast<get_sdr::GetSensorThresholdsResponse*>(response); |
| 725 | |
| 726 | responseData->validMask = 0; |
| 727 | |
| 728 | const auto iter = sensors.find(sensorNum); |
| 729 | if (iter == sensors.end()) |
| 730 | { |
| 731 | return IPMI_CC_SENSOR_INVALID; |
| 732 | } |
| 733 | |
| 734 | const auto sensorInfo = iter->second; |
| 735 | |
| 736 | //Proceed only if the sensor value interface is implemented. |
| 737 | if (sensorInfo.propertyInterfaces.find(valueInterface) == |
| 738 | sensorInfo.propertyInterfaces.end()) |
| 739 | { |
| 740 | //return with valid mask as 0 |
| 741 | return IPMI_CC_OK; |
| 742 | } |
| 743 | |
| 744 | std::string service; |
| 745 | try |
| 746 | { |
| 747 | service = ipmi::getService(bus, |
| 748 | sensorInfo.sensorInterface, |
| 749 | sensorInfo.sensorPath); |
| 750 | } |
| 751 | catch (const std::runtime_error& e) |
| 752 | { |
| 753 | log<level::ERR>(e.what()); |
| 754 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 755 | } |
| 756 | |
| 757 | //prevent divide by 0 |
| 758 | auto coefficientM = |
| 759 | sensorInfo.coefficientM ? sensorInfo.coefficientM : 1; |
| 760 | |
| 761 | try |
| 762 | { |
| 763 | auto mngObjects = ipmi::getManagedObjects(bus, |
| 764 | service, |
| 765 | sensorRoot); |
| 766 | |
| 767 | auto senIter = mngObjects.find(sensorInfo.sensorPath); |
| 768 | if (senIter == mngObjects.end()) |
| 769 | { |
| 770 | return IPMI_CC_SENSOR_INVALID; |
| 771 | } |
| 772 | |
| 773 | for (const auto& threshold : thresholds) |
| 774 | { |
| 775 | auto thresholdType = senIter->second.find(threshold.first); |
| 776 | if (thresholdType != senIter->second.end()) |
| 777 | { |
| 778 | for (const auto& threshLevel : threshold.second) |
| 779 | { |
| 780 | auto val = thresholdType-> |
| 781 | second[threshLevel.property].get<int64_t>(); |
| 782 | if (val != 0) |
| 783 | { |
| 784 | auto idx = static_cast<uint8_t>(threshLevel.idx); |
| 785 | responseData->data[idx] = static_cast<uint8_t>( |
| 786 | (val - sensorInfo.scaledOffset) / coefficientM); |
| 787 | responseData->validMask |= |
| 788 | static_cast<uint8_t>(threshLevel.maskValue); |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | catch (InternalFailure& e) |
| 795 | { |
| 796 | //Not able to get the values, reset the mask. |
| 797 | responseData->validMask = 0; |
| 798 | } |
| 799 | |
| 800 | *data_len = sizeof(get_sdr::GetSensorThresholdsResponse); |
| 801 | return IPMI_CC_OK; |
| 802 | } |
| 803 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 804 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 805 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 806 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 807 | { |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 808 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 809 | |
| 810 | printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 811 | *data_len = 0; |
| 812 | |
| 813 | return rc; |
| 814 | } |
| 815 | |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 816 | ipmi_ret_t ipmi_sen_get_sdr_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 817 | ipmi_request_t request, |
| 818 | ipmi_response_t response, |
| 819 | ipmi_data_len_t data_len, |
| 820 | ipmi_context_t context) |
| 821 | { |
| 822 | auto resp = static_cast<get_sdr_info::GetSdrInfoResp*>(response); |
| 823 | if (request == nullptr || |
| 824 | get_sdr_info::request::get_count(request) == false) |
| 825 | { |
| 826 | // Get Sensor Count |
| 827 | resp->count = sensors.size(); |
| 828 | } |
| 829 | else |
| 830 | { |
| 831 | resp->count = 1; |
| 832 | } |
| 833 | |
| 834 | // Multiple LUNs not supported. |
| 835 | namespace response = get_sdr_info::response; |
| 836 | response::set_lun_present(0, &(resp->luns_and_dynamic_population)); |
| 837 | response::set_lun_not_present(1, &(resp->luns_and_dynamic_population)); |
| 838 | response::set_lun_not_present(2, &(resp->luns_and_dynamic_population)); |
| 839 | response::set_lun_not_present(3, &(resp->luns_and_dynamic_population)); |
| 840 | response::set_static_population(&(resp->luns_and_dynamic_population)); |
| 841 | |
| 842 | *data_len = SDR_INFO_RESP_SIZE; |
| 843 | |
| 844 | return IPMI_CC_OK; |
| 845 | } |
| 846 | |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 847 | ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 848 | ipmi_request_t request, |
| 849 | ipmi_response_t response, |
| 850 | ipmi_data_len_t data_len, |
| 851 | ipmi_context_t context) |
| 852 | { |
| 853 | // A constant reservation ID is okay until we implement add/remove SDR. |
| 854 | const uint16_t reservation_id = 1; |
| 855 | *(uint16_t*)response = reservation_id; |
Emily Shaffer | 5a5a628 | 2017-08-15 11:17:17 -0700 | [diff] [blame] | 856 | *data_len = sizeof(uint16_t); |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 857 | |
| 858 | printf("Created new IPMI SDR reservation ID %d\n", *(uint16_t*)response); |
| 859 | return IPMI_CC_OK; |
| 860 | } |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 861 | |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 862 | void setUnitFieldsForObject(sd_bus *bus, |
| 863 | const dbus_interface_t &iface, |
| 864 | const ipmi::sensor::Info *info, |
| 865 | get_sdr::SensorDataFullRecordBody *body) |
| 866 | { |
| 867 | if (info->propertyInterfaces.begin()->first == |
| 868 | "xyz.openbmc_project.Sensor.Value") |
| 869 | { |
| 870 | std::string result {}; |
Emily Shaffer | 6223561 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 871 | if (info->unit.empty()) |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 872 | { |
Emily Shaffer | 6223561 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 873 | char *raw_cstr = NULL; |
| 874 | if (0 > sd_bus_get_property_string(bus, iface.bus, iface.path, |
| 875 | iface.interface, "Unit", NULL, |
| 876 | &raw_cstr)) |
| 877 | { |
| 878 | log<level::WARNING>("Unit interface missing.", |
| 879 | entry("BUS=%s", iface.bus), |
| 880 | entry("PATH=%s", iface.path)); |
| 881 | } |
| 882 | else |
| 883 | { |
| 884 | result = raw_cstr; |
| 885 | } |
| 886 | free(raw_cstr); |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 887 | } |
| 888 | else |
| 889 | { |
Emily Shaffer | 6223561 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 890 | result = info->unit; |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 891 | } |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 892 | |
| 893 | namespace server = sdbusplus::xyz::openbmc_project::Sensor::server; |
| 894 | try { |
| 895 | auto unit = server::Value::convertUnitFromString(result); |
| 896 | // Unit strings defined in |
| 897 | // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml |
| 898 | switch (unit) |
| 899 | { |
| 900 | case server::Value::Unit::DegreesC: |
| 901 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C; |
| 902 | break; |
| 903 | case server::Value::Unit::RPMS: |
| 904 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions |
| 905 | get_sdr::body::set_rate_unit(0b100, body); // per minute |
| 906 | break; |
| 907 | case server::Value::Unit::Volts: |
| 908 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS; |
| 909 | break; |
| 910 | case server::Value::Unit::Meters: |
| 911 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS; |
| 912 | break; |
| 913 | case server::Value::Unit::Amperes: |
| 914 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES; |
| 915 | break; |
| 916 | case server::Value::Unit::Joules: |
| 917 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES; |
| 918 | break; |
| 919 | default: |
| 920 | // Cannot be hit. |
| 921 | fprintf(stderr, "Unknown value unit type: = %s\n", result.c_str()); |
| 922 | } |
| 923 | } |
| 924 | catch (sdbusplus::exception::InvalidEnumString e) |
| 925 | { |
| 926 | log<level::WARNING>("Warning: no unit provided for sensor!"); |
| 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | int64_t getScaleForObject(sd_bus *bus, |
| 932 | const dbus_interface_t& iface, |
| 933 | const ipmi::sensor::Info *info) |
| 934 | { |
| 935 | int64_t result = 0; |
| 936 | if (info->propertyInterfaces.begin()->first == |
| 937 | "xyz.openbmc_project.Sensor.Value") |
| 938 | { |
Emily Shaffer | 6223561 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 939 | if (info->hasScale) |
| 940 | { |
| 941 | result = info->scale; |
| 942 | } |
| 943 | else |
| 944 | { |
| 945 | if (0 > sd_bus_get_property_trivial(bus, |
| 946 | iface.bus, |
| 947 | iface.path, |
| 948 | iface.interface, |
| 949 | "Scale", |
| 950 | NULL, |
| 951 | 'x', |
| 952 | &result)) { |
| 953 | log<level::WARNING>("Scale interface missing.", |
| 954 | entry("BUS=%s", iface.bus), |
| 955 | entry("PATH=%s", iface.path)); |
| 956 | } |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
| 960 | return result; |
| 961 | } |
| 962 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 963 | ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body, |
| 964 | const ipmi::sensor::Info *info, |
| 965 | ipmi_data_len_t data_len) |
| 966 | { |
| 967 | /* Functional sensor case */ |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 968 | if (isAnalogSensor(info->propertyInterfaces.begin()->first)) |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 969 | { |
| 970 | // Get bus |
| 971 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 972 | dbus_interface_t iface; |
| 973 | |
| 974 | if (0 > find_openbmc_path(body->entity_id, &iface)) |
| 975 | return IPMI_CC_SENSOR_INVALID; |
| 976 | |
| 977 | body->sensor_units_1 = 0; // unsigned, no rate, no modifier, not a % |
| 978 | |
| 979 | /* Unit info */ |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 980 | setUnitFieldsForObject(bus, iface, info, body); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 981 | |
| 982 | /* Modifiers to reading info */ |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 983 | // Get scale |
Emily Shaffer | cc941e1 | 2017-06-14 13:06:26 -0700 | [diff] [blame] | 984 | int64_t scale = getScaleForObject(bus, iface, info); |
Emily Shaffer | 10f4959 | 2017-05-10 12:01:10 -0700 | [diff] [blame] | 985 | |
| 986 | get_sdr::body::set_b(info->coefficientB, body); |
| 987 | get_sdr::body::set_m(info->coefficientM, body); |
| 988 | get_sdr::body::set_b_exp(info->exponentB, body); |
| 989 | get_sdr::body::set_r_exp(scale, body); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 990 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 991 | get_sdr::body::set_id_type(0b00, body); // 00 = unicode |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 992 | } |
| 993 | |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 994 | /* ID string */ |
| 995 | auto id_string = info->sensorNameFunc(*info); |
| 996 | |
| 997 | if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH) |
| 998 | { |
| 999 | get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH, body); |
| 1000 | } |
| 1001 | else |
| 1002 | { |
| 1003 | get_sdr::body::set_id_strlen(id_string.length(), body); |
| 1004 | } |
| 1005 | strncpy(body->id_string, id_string.c_str(), |
| 1006 | get_sdr::body::get_id_strlen(body)); |
| 1007 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 1008 | return IPMI_CC_OK; |
| 1009 | }; |
| 1010 | |
| 1011 | ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 1012 | ipmi_request_t request, ipmi_response_t response, |
| 1013 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 1014 | { |
| 1015 | ipmi_ret_t ret = IPMI_CC_OK; |
| 1016 | get_sdr::GetSdrReq *req = (get_sdr::GetSdrReq*)request; |
| 1017 | get_sdr::GetSdrResp *resp = (get_sdr::GetSdrResp*)response; |
| 1018 | get_sdr::SensorDataFullRecord record = {0}; |
| 1019 | if (req != NULL) |
| 1020 | { |
| 1021 | // Note: we use an iterator so we can provide the next ID at the end of |
| 1022 | // the call. |
| 1023 | auto sensor = sensors.begin(); |
| 1024 | |
| 1025 | // At the beginning of a scan, the host side will send us id=0. |
| 1026 | if (get_sdr::request::get_record_id(req) != 0) |
| 1027 | { |
| 1028 | sensor = sensors.find(get_sdr::request::get_record_id(req)); |
| 1029 | if(sensor == sensors.end()) { |
| 1030 | return IPMI_CC_SENSOR_INVALID; |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | uint8_t sensor_id = sensor->first; |
| 1035 | |
| 1036 | /* Header */ |
| 1037 | get_sdr::header::set_record_id(sensor_id, &(record.header)); |
| 1038 | record.header.sdr_version = 0x51; // Based on IPMI Spec v2.0 rev 1.1 |
| 1039 | record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD; |
| 1040 | record.header.record_length = sizeof(get_sdr::SensorDataFullRecord); |
| 1041 | |
| 1042 | /* Key */ |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 1043 | get_sdr::key::set_owner_id_bmc(&(record.key)); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 1044 | record.key.sensor_number = sensor_id; |
| 1045 | |
| 1046 | /* Body */ |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 1047 | record.body.entity_id = sensor->second.entityType; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 1048 | record.body.sensor_type = sensor->second.sensorType; |
| 1049 | record.body.event_reading_type = sensor->second.sensorReadingType; |
Tom Joseph | 9642391 | 2018-01-25 00:14:34 +0530 | [diff] [blame] | 1050 | record.body.entity_instance = sensor->second.instance; |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 1051 | |
| 1052 | // Set the type-specific details given the DBus interface |
| 1053 | ret = populate_record_from_dbus(&(record.body), &(sensor->second), |
| 1054 | data_len); |
| 1055 | |
| 1056 | if (++sensor == sensors.end()) |
| 1057 | { |
| 1058 | get_sdr::response::set_next_record_id(0xFFFF, resp); // last record |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | get_sdr::response::set_next_record_id(sensor->first, resp); |
| 1063 | } |
| 1064 | |
| 1065 | *data_len = sizeof(get_sdr::GetSdrResp) - req->offset; |
| 1066 | memcpy(resp->record_data, (char*)&record + req->offset, |
| 1067 | sizeof(get_sdr::SensorDataFullRecord) - req->offset); |
| 1068 | } |
| 1069 | |
| 1070 | return ret; |
| 1071 | } |
| 1072 | |
| 1073 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1074 | void register_netfn_sen_functions() |
| 1075 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1076 | // <Wildcard Command> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 1077 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 1078 | NETFUN_SENSOR, IPMI_CMD_WILDCARD); |
| 1079 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, |
| 1080 | nullptr, ipmi_sen_wildcard, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1081 | PRIVILEGE_USER); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1082 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1083 | // <Get Sensor Type> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 1084 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 1085 | NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE); |
| 1086 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, |
| 1087 | nullptr, ipmi_sen_get_sensor_type, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1088 | PRIVILEGE_USER); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1089 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1090 | // <Set Sensor Reading and Event Status> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 1091 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 1092 | NETFUN_SENSOR, IPMI_CMD_SET_SENSOR); |
| 1093 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, |
| 1094 | nullptr, ipmi_sen_set_sensor, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1095 | PRIVILEGE_OPERATOR); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 1096 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 1097 | // <Get Sensor Reading> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 1098 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 1099 | NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING); |
| 1100 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, |
| 1101 | nullptr, ipmi_sen_get_sensor_reading, |
| 1102 | PRIVILEGE_USER); |
| 1103 | |
| 1104 | // <Reserve SDR> |
| 1105 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 1106 | NETFUN_SENSOR, IPMI_CMD_RESERVE_SDR_REPO); |
| 1107 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_RESERVE_SDR_REPO, |
| 1108 | nullptr, ipmi_sen_reserve_sdr, |
| 1109 | PRIVILEGE_USER); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 1110 | |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 1111 | // <Get SDR Info> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 1112 | printf("Registering NetFn:[0x%X], Cmd:[0x%x]\n", |
| 1113 | NETFUN_SENSOR, IPMI_CMD_GET_SDR_INFO); |
| 1114 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SDR_INFO, |
| 1115 | nullptr, ipmi_sen_get_sdr_info, |
| 1116 | PRIVILEGE_USER); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame] | 1117 | |
| 1118 | // <Get SDR> |
| 1119 | printf("Registering NetFn:[0x%X], Cmd:[0x%x]\n", |
| 1120 | NETFUN_SENSOR, IPMI_CMD_GET_SDR); |
| 1121 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SDR, |
| 1122 | nullptr, ipmi_sen_get_sdr, |
| 1123 | PRIVILEGE_USER); |
| 1124 | |
Dhruvaraj Subhashchandran | 5c0beec | 2018-01-23 04:47:06 -0600 | [diff] [blame] | 1125 | // <Get Sensor Thresholds> |
| 1126 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_THRESHOLDS, |
| 1127 | nullptr, ipmi_sen_get_sensor_thresholds, |
| 1128 | PRIVILEGE_USER); |
| 1129 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1130 | return; |
| 1131 | } |