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