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> |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 5 | #include <bitset> |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame^] | 6 | #include <xyz/openbmc_project/Sensor/Value/server.hpp> |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 7 | #include <systemd/sd-bus.h> |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 8 | #include "host-ipmid/ipmid-api.h" |
| 9 | #include <phosphor-logging/log.hpp> |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 10 | #include "ipmid.hpp" |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 11 | #include "sensorhandler.h" |
| 12 | #include "types.hpp" |
| 13 | #include "utils.hpp" |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 14 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 15 | extern int updateSensorRecordFromSSRAESC(const void *); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 16 | extern sd_bus *bus; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 17 | extern const ipmi::sensor::IdInfoMap sensors; |
| 18 | using namespace phosphor::logging; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 19 | |
| 20 | void register_netfn_sen_functions() __attribute__((constructor)); |
| 21 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 22 | struct sensorTypemap_t { |
| 23 | uint8_t number; |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 24 | uint8_t typecode; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 25 | char dbusname[32]; |
| 26 | } ; |
| 27 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 28 | sensorTypemap_t g_SensorTypeMap[] = { |
| 29 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 30 | {0x01, 0x6F, "Temp"}, |
| 31 | {0x0C, 0x6F, "DIMM"}, |
| 32 | {0x0C, 0x6F, "MEMORY_BUFFER"}, |
| 33 | {0x07, 0x6F, "PROC"}, |
| 34 | {0x07, 0x6F, "CORE"}, |
| 35 | {0x07, 0x6F, "CPU"}, |
| 36 | {0x0F, 0x6F, "BootProgress"}, |
| 37 | {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09 |
| 38 | {0xC3, 0x6F, "BootCount"}, |
| 39 | {0x1F, 0x6F, "OperatingSystemStatus"}, |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 40 | {0x12, 0x6F, "SYSTEM_EVENT"}, |
| 41 | {0xC7, 0x03, "SYSTEM"}, |
| 42 | {0xC7, 0x03, "MAIN_PLANAR"}, |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 43 | {0xC2, 0x6F, "PowerCap"}, |
Dhruvaraj S | 0724829 | 2017-03-21 02:14:52 -0500 | [diff] [blame] | 44 | {0xD8, 0x03, "PowerSupplyRedundancy"}, |
Jayanth Othayoth | 0661beb | 2017-03-22 06:00:58 -0500 | [diff] [blame] | 45 | {0xDA, 0x03, "TurboAllowed"}, |
Jayanth Othayoth | d5b2ac0 | 2017-03-27 08:19:18 -0500 | [diff] [blame] | 46 | {0xB4, 0x6F, "PowerSupplyDerating"}, |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 47 | {0xFF, 0x00, ""}, |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 51 | struct sensor_data_t { |
| 52 | uint8_t sennum; |
| 53 | } __attribute__ ((packed)) ; |
| 54 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 55 | struct sensorreadingresp_t { |
| 56 | uint8_t value; |
| 57 | uint8_t operation; |
| 58 | uint8_t indication[2]; |
| 59 | } __attribute__ ((packed)) ; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 60 | |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 61 | // Use a lookup table to find the interface name of a specific sensor |
| 62 | // This will be used until an alternative is found. this is the first |
| 63 | // step for mapping IPMI |
| 64 | int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) { |
| 65 | |
| 66 | char *str1; |
| 67 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 68 | sd_bus_message *reply = NULL, *m=NULL; |
| 69 | |
| 70 | |
| 71 | int r; |
| 72 | |
| 73 | r = sd_bus_message_new_method_call(bus,&m,interface->bus,interface->path,"org.freedesktop.DBus.Properties","Get"); |
| 74 | if (r < 0) { |
| 75 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 76 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 77 | interface->bus, interface->path, interface->interface); |
| 78 | goto final; |
| 79 | } |
| 80 | |
| 81 | r = sd_bus_message_append(m, "ss", "org.openbmc.InventoryItem", property_name); |
| 82 | if (r < 0) { |
| 83 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 84 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 85 | interface->bus, interface->path, interface->interface); |
| 86 | goto final; |
| 87 | } |
| 88 | |
| 89 | r = sd_bus_call(bus, m, 0, &error, &reply); |
| 90 | if (r < 0) { |
| 91 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 92 | goto final; |
| 93 | } |
| 94 | |
| 95 | r = sd_bus_message_read(reply, "v", "s", &str1) ; |
| 96 | if (r < 0) { |
| 97 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 98 | goto final; |
| 99 | } |
| 100 | |
| 101 | strcpy(property_value, str1); |
| 102 | |
| 103 | final: |
| 104 | |
| 105 | sd_bus_error_free(&error); |
| 106 | m = sd_bus_message_unref(m); |
| 107 | reply = sd_bus_message_unref(reply); |
| 108 | |
| 109 | return r; |
| 110 | } |
| 111 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 112 | int get_bus_for_path(const char *path, char **busname) { |
| 113 | return mapper_get_service(bus, path, busname); |
| 114 | } |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 115 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 116 | 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] | 117 | char *busname = NULL; |
| 118 | const char *iface = "org.openbmc.managers.System"; |
| 119 | const char *objname = "/org/openbmc/managers/System"; |
| 120 | char *str1 = NULL, *str2, *str3; |
| 121 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 122 | sd_bus_message *reply = NULL; |
| 123 | |
| 124 | |
| 125 | int r; |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 126 | r = get_bus_for_path(objname, &busname); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 127 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 128 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 129 | objname, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 130 | goto final; |
| 131 | } |
| 132 | |
| 133 | r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId", |
| 134 | &error, &reply, "sy", type, num); |
| 135 | if (r < 0) { |
| 136 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 137 | goto final; |
| 138 | } |
| 139 | |
| 140 | r = sd_bus_message_read(reply, "(ss)", &str2, &str3); |
| 141 | if (r < 0) { |
| 142 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 143 | goto final; |
| 144 | } |
| 145 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 146 | r = get_bus_for_path(str2, &str1); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 147 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 148 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 149 | str2, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 150 | goto final; |
| 151 | } |
| 152 | |
| 153 | strncpy(interface->bus, str1, MAX_DBUS_PATH); |
| 154 | strncpy(interface->path, str2, MAX_DBUS_PATH); |
| 155 | strncpy(interface->interface, str3, MAX_DBUS_PATH); |
| 156 | |
| 157 | interface->sensornumber = num; |
Emily Shaffer | 7117441 | 2017-04-05 15:10:40 -0700 | [diff] [blame] | 158 | // Make sure we know that the type hasn't been set, as newer codebase will |
| 159 | // set it automatically from the YAML at this step. |
| 160 | interface->sensortype = 0; |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 161 | |
| 162 | final: |
| 163 | |
| 164 | sd_bus_error_free(&error); |
| 165 | reply = sd_bus_message_unref(reply); |
| 166 | free(busname); |
| 167 | free(str1); |
| 168 | |
| 169 | return r; |
| 170 | } |
| 171 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 172 | // Use a lookup table to find the interface name of a specific sensor |
| 173 | // This will be used until an alternative is found. this is the first |
| 174 | // step for mapping IPMI |
| 175 | int find_openbmc_path(uint8_t num, dbus_interface_t *interface) { |
| 176 | int rc; |
| 177 | |
| 178 | // When the sensor map does not contain the sensor requested, |
| 179 | // fall back to the legacy DBus lookup (deprecated) |
| 180 | const auto& sensor_it = sensors.find(num); |
| 181 | if (sensor_it == sensors.end()) |
| 182 | { |
| 183 | return legacy_dbus_openbmc_path("SENSOR", num, interface); |
| 184 | } |
| 185 | |
| 186 | const auto& info = sensor_it->second; |
| 187 | |
Patrick Williams | 8451edf | 2017-06-13 09:01:06 -0500 | [diff] [blame] | 188 | char* busname = nullptr; |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 189 | rc = get_bus_for_path(info.sensorPath.c_str(), &busname); |
| 190 | if (rc < 0) { |
| 191 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 192 | info.sensorPath.c_str(), |
| 193 | busname); |
| 194 | goto final; |
| 195 | } |
| 196 | |
| 197 | interface->sensortype = info.sensorType; |
| 198 | strcpy(interface->bus, busname); |
| 199 | strcpy(interface->path, info.sensorPath.c_str()); |
| 200 | // Take the interface name from the beginning of the DbusInterfaceMap. This |
| 201 | // works for the Value interface but may not suffice for more complex |
| 202 | // sensors. |
| 203 | // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103 |
| 204 | strcpy(interface->interface, info.sensorInterfaces.begin()->first.c_str()); |
| 205 | interface->sensornumber = num; |
| 206 | |
| 207 | final: |
| 208 | free(busname); |
| 209 | return rc; |
| 210 | } |
| 211 | |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 212 | |
| 213 | ///////////////////////////////////////////////////////////////////// |
| 214 | // |
| 215 | // Routines used by ipmi commands wanting to interact on the dbus |
| 216 | // |
| 217 | ///////////////////////////////////////////////////////////////////// |
| 218 | int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) { |
| 219 | |
| 220 | |
| 221 | dbus_interface_t a; |
| 222 | int r; |
| 223 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 224 | sd_bus_message *m=NULL; |
| 225 | |
| 226 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n", |
| 227 | number, method, value); |
| 228 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 229 | r = find_openbmc_path(number, &a); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 230 | |
| 231 | if (r < 0) { |
| 232 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 237 | if (r < 0) { |
| 238 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 239 | goto final; |
| 240 | } |
| 241 | |
| 242 | r = sd_bus_message_append(m, "v", "s", value); |
| 243 | if (r < 0) { |
| 244 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 245 | goto final; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 250 | if (r < 0) { |
| 251 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 252 | } |
| 253 | |
| 254 | final: |
| 255 | sd_bus_error_free(&error); |
| 256 | m = sd_bus_message_unref(m); |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) { |
| 261 | |
| 262 | |
| 263 | dbus_interface_t a; |
| 264 | int r; |
| 265 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 266 | sd_bus_message *m=NULL; |
| 267 | |
| 268 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n", |
| 269 | number, method, value); |
| 270 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 271 | r = find_openbmc_path(number, &a); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 272 | |
| 273 | if (r < 0) { |
| 274 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 279 | if (r < 0) { |
| 280 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 281 | goto final; |
| 282 | } |
| 283 | |
| 284 | r = sd_bus_message_append(m, "v", "i", value); |
| 285 | if (r < 0) { |
| 286 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 287 | goto final; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 292 | if (r < 0) { |
| 293 | fprintf(stderr, "12 Failed to call the method: %s", strerror(-r)); |
| 294 | } |
| 295 | |
| 296 | final: |
| 297 | sd_bus_error_free(&error); |
| 298 | m = sd_bus_message_unref(m); |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 303 | uint8_t dbus_to_sensor_type(char *p) { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 304 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 305 | sensorTypemap_t *s = g_SensorTypeMap; |
| 306 | char r=0; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 307 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 308 | while (s->number != 0xFF) { |
| 309 | if (!strcmp(s->dbusname,p)) { |
| 310 | r = s->number; |
| 311 | break; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 312 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 313 | s++; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 314 | } |
| 315 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 316 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 317 | if (s->number == 0xFF) |
| 318 | printf("Failed to find Sensor Type %s\n", p); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 319 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 320 | return r; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 323 | |
| 324 | uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) { |
| 325 | char fru_type_name[64]; |
| 326 | int r= 0; |
| 327 | |
| 328 | r = find_interface_property_fru_type(a, "fru_type", fru_type_name); |
| 329 | if (r<0) { |
| 330 | fprintf(stderr, "Failed to get a fru type: %s", strerror(-r)); |
| 331 | return -1; |
| 332 | } else { |
| 333 | return dbus_to_sensor_type(fru_type_name); |
| 334 | } |
| 335 | } |
| 336 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 337 | uint8_t get_type_from_interface(dbus_interface_t dbus_if) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 338 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 339 | char *p; |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 340 | uint8_t type; |
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 | // This is where sensors that do not exist in dbus but do |
| 343 | // exist in the host code stop. This should indicate it |
| 344 | // is not a supported sensor |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 345 | if (dbus_if.interface[0] == 0) { return 0;} |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 346 | |
Emily Shaffer | 7117441 | 2017-04-05 15:10:40 -0700 | [diff] [blame] | 347 | // Fetch type from interface itself. |
| 348 | if (dbus_if.sensortype != 0) |
| 349 | { |
| 350 | type = dbus_if.sensortype; |
| 351 | } |
| 352 | // Legacy codebase does not populate type during initial handling: |
| 353 | else if (strstr(dbus_if.interface, "InventoryItem")) { |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 354 | // InventoryItems are real frus. So need to get the |
| 355 | // fru_type property |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 356 | type = dbus_to_sensor_type_from_dbus(&dbus_if); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 357 | } else { |
| 358 | // Non InventoryItems |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 359 | p = strrchr (dbus_if.path, '/'); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 360 | type = dbus_to_sensor_type(p+1); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 361 | } |
| 362 | |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 363 | return type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 364 | } |
| 365 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 366 | // Replaces find_sensor |
| 367 | uint8_t find_type_for_sensor_number(uint8_t num) { |
| 368 | int r; |
| 369 | dbus_interface_t dbus_if; |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 370 | r = find_openbmc_path(num, &dbus_if); |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 371 | if (r < 0) { |
| 372 | fprintf(stderr, "Could not find sensor %d\n", num); |
| 373 | return r; |
| 374 | } |
| 375 | return get_type_from_interface(dbus_if); |
| 376 | } |
| 377 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 378 | |
| 379 | |
| 380 | |
| 381 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 382 | ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 383 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 384 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 385 | { |
| 386 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 387 | ipmi_ret_t rc = IPMI_CC_OK; |
| 388 | |
| 389 | printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum); |
| 390 | |
| 391 | // TODO Not sure what the System-event-sensor is suppose to return |
| 392 | // need to ask Hostboot team |
| 393 | unsigned char buf[] = {0x00,0x6F}; |
| 394 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 395 | buf[0] = find_type_for_sensor_number(reqptr->sennum); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 396 | |
| 397 | // HACK UNTIL Dbus gets updated or we find a better way |
| 398 | if (buf[0] == 0) { |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 399 | rc = IPMI_CC_SENSOR_INVALID; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 400 | } |
| 401 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 402 | |
| 403 | *data_len = sizeof(buf); |
| 404 | memcpy(response, &buf, *data_len); |
| 405 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 406 | return rc; |
| 407 | } |
| 408 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 409 | ipmi_ret_t setSensorReading(void *request) |
| 410 | { |
| 411 | auto cmdData = static_cast<SetSensorReadingReq *>(request); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 412 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 413 | auto assertionStates = |
| 414 | (static_cast<uint16_t>(cmdData->assertOffset8_14)) << 8 | |
| 415 | cmdData->assertOffset0_7; |
| 416 | |
| 417 | auto deassertionStates = |
| 418 | (static_cast<uint16_t>(cmdData->deassertOffset8_14)) << 8 | |
| 419 | cmdData->deassertOffset0_7; |
| 420 | |
| 421 | std::bitset<16> assertionSet(assertionStates); |
| 422 | std::bitset<16> deassertionSet(deassertionStates); |
| 423 | |
| 424 | // Check if the Sensor Number is present |
| 425 | auto iter = sensors.find(cmdData->number); |
| 426 | if (iter == sensors.end()) |
| 427 | { |
| 428 | return IPMI_CC_SENSOR_INVALID; |
| 429 | } |
| 430 | |
| 431 | auto& interfaceList = iter->second.sensorInterfaces; |
| 432 | if (interfaceList.empty()) |
| 433 | { |
| 434 | log<level::ERR>("Interface List empty for the sensor", |
| 435 | entry("Sensor Number = %d", cmdData->number)); |
| 436 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 437 | } |
| 438 | |
| 439 | ipmi::sensor::ObjectMap objects; |
| 440 | ipmi::sensor::InterfaceMap interfaces; |
| 441 | for (const auto& interface : interfaceList) |
| 442 | { |
| 443 | for (const auto& property : interface.second) |
| 444 | { |
| 445 | ipmi::sensor::PropertyMap props; |
| 446 | bool valid = false; |
| 447 | for (const auto& value : property.second) |
| 448 | { |
| 449 | if (assertionSet.test(value.first)) |
| 450 | { |
| 451 | props.emplace(property.first, value.second.assert); |
| 452 | valid = true; |
| 453 | } |
| 454 | else if (deassertionSet.test(value.first)) |
| 455 | { |
| 456 | props.emplace(property.first, value.second.deassert); |
| 457 | valid = true; |
| 458 | } |
| 459 | } |
| 460 | if (valid) |
| 461 | { |
| 462 | interfaces.emplace(interface.first, std::move(props)); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | objects.emplace(iter->second.sensorPath, std::move(interfaces)); |
| 467 | |
Patrick Williams | 4736b91 | 2017-04-18 11:50:57 -0500 | [diff] [blame] | 468 | sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()}; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 469 | using namespace std::string_literals; |
| 470 | static const auto intf = "xyz.openbmc_project.Inventory.Manager"s; |
| 471 | static const auto path = "/xyz/openbmc_project/inventory"s; |
| 472 | std::string service; |
| 473 | |
| 474 | try |
| 475 | { |
| 476 | service = ipmi::getService(bus, intf, path); |
| 477 | |
| 478 | // Update the inventory manager |
| 479 | auto pimMsg = bus.new_method_call(service.c_str(), |
| 480 | path.c_str(), |
| 481 | intf.c_str(), |
| 482 | "Notify"); |
| 483 | pimMsg.append(std::move(objects)); |
| 484 | auto inventoryMgrResponseMsg = bus.call(pimMsg); |
| 485 | if (inventoryMgrResponseMsg.is_method_error()) |
| 486 | { |
| 487 | log<level::ERR>("Error in notify call"); |
| 488 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 489 | } |
| 490 | } |
| 491 | catch (const std::runtime_error& e) |
| 492 | { |
| 493 | log<level::ERR>(e.what()); |
| 494 | return IPMI_CC_UNSPECIFIED_ERROR; |
| 495 | } |
| 496 | |
| 497 | return IPMI_CC_OK; |
| 498 | } |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 499 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 500 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 501 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 502 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 503 | { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 504 | sensor_data_t *reqptr = (sensor_data_t*)request; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 505 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 506 | printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 507 | |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 508 | /* |
| 509 | * This would support the Set Sensor Reading command for the presence |
| 510 | * and functional state of Processor, Core & DIMM. For the remaining |
| 511 | * sensors the existing support is invoked. |
| 512 | */ |
| 513 | auto ipmiRC = setSensorReading(request); |
| 514 | |
| 515 | if(ipmiRC == IPMI_CC_SENSOR_INVALID) |
| 516 | { |
| 517 | updateSensorRecordFromSSRAESC(reqptr); |
| 518 | ipmiRC = IPMI_CC_OK; |
| 519 | } |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 520 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 521 | *data_len=0; |
Tom Joseph | be703f7 | 2017-03-09 12:34:35 +0530 | [diff] [blame] | 522 | return ipmiRC; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 523 | } |
| 524 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 525 | |
| 526 | ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 527 | ipmi_request_t request, ipmi_response_t response, |
| 528 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 529 | { |
| 530 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 531 | ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID; |
| 532 | uint8_t type; |
| 533 | sensorreadingresp_t *resp = (sensorreadingresp_t*) response; |
| 534 | int r; |
| 535 | dbus_interface_t a; |
| 536 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 537 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 538 | int reading = 0; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 539 | |
| 540 | |
| 541 | printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum); |
| 542 | |
Emily Shaffer | 2ae09b9 | 2017-04-05 15:09:41 -0700 | [diff] [blame] | 543 | r = find_openbmc_path(reqptr->sennum, &a); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 544 | |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 545 | if (r < 0) { |
| 546 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 547 | return IPMI_CC_SENSOR_INVALID; |
| 548 | } |
| 549 | |
Emily Shaffer | 391f330 | 2017-04-03 10:27:08 -0700 | [diff] [blame] | 550 | type = get_type_from_interface(a); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame] | 551 | if(type == 0) { |
| 552 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 553 | return IPMI_CC_SENSOR_INVALID; |
| 554 | } |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 555 | |
| 556 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface); |
| 557 | |
| 558 | *data_len=0; |
| 559 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 560 | int64_t raw_value, scale; |
| 561 | ipmi::sensor::Info sensor; |
| 562 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 563 | switch(type) { |
| 564 | case 0xC3: |
| 565 | case 0xC2: |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 566 | 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] | 567 | if (r < 0) { |
| 568 | fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r)); |
| 569 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 570 | a.bus, a.path, a.interface); |
| 571 | break; |
| 572 | } |
| 573 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 574 | r = sd_bus_message_read(reply, "i", &reading); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 575 | if (r < 0) { |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 576 | fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r)); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 577 | break; |
| 578 | } |
| 579 | |
| 580 | printf("Contents of a 0x%02x is 0x%02x\n", type, reading); |
| 581 | |
| 582 | rc = IPMI_CC_OK; |
| 583 | *data_len=sizeof(sensorreadingresp_t); |
| 584 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 585 | resp->value = (uint8_t)reading; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 586 | resp->operation = 0; |
| 587 | resp->indication[0] = 0; |
| 588 | resp->indication[1] = 0; |
| 589 | break; |
| 590 | |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 591 | case IPMI_SENSOR_TEMP: |
| 592 | case IPMI_SENSOR_VOLTAGE: |
| 593 | case IPMI_SENSOR_CURRENT: |
| 594 | case IPMI_SENSOR_FAN: |
| 595 | // Get reading for /xyz/openbmc_project/Sensor/Value.interface |
| 596 | |
| 597 | // Get value |
| 598 | r = sd_bus_get_property_trivial(bus, |
| 599 | a.bus, |
| 600 | a.path, |
| 601 | a.interface, |
| 602 | "Value", |
| 603 | NULL, |
| 604 | 'x', |
| 605 | &raw_value); |
| 606 | if (r < 0) { |
| 607 | fprintf(stderr, |
| 608 | "Failed to call sd_bus_get_property:%d, %s, 'value'\n", |
| 609 | r, |
| 610 | strerror(-r)); |
| 611 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 612 | a.bus, a.path, a.interface); |
| 613 | break; |
| 614 | } |
| 615 | |
| 616 | // Get scale |
| 617 | r = sd_bus_get_property_trivial(bus, |
| 618 | a.bus, |
| 619 | a.path, |
| 620 | a.interface, |
| 621 | "Scale", |
| 622 | NULL, |
| 623 | 'x', |
| 624 | &scale); |
| 625 | if (r < 0) { |
| 626 | fprintf(stderr, |
| 627 | "Failed to call sd_bus_get_property:%d, %s (scale)\n", |
| 628 | r, |
| 629 | strerror(-r)); |
| 630 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 631 | a.bus, a.path, a.interface); |
| 632 | break; |
| 633 | } |
| 634 | |
| 635 | resp->value = raw_value * pow(10,scale); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame^] | 636 | resp->operation = 1<<6; // scanning enabled |
| 637 | resp->indication[0] = 0; // not a threshold sensor. ignore |
Emily Shaffer | 1fabf22 | 2017-04-05 08:53:21 -0700 | [diff] [blame] | 638 | resp->indication[1] = 0; |
| 639 | rc = IPMI_CC_OK; |
| 640 | *data_len=sizeof(sensorreadingresp_t); |
| 641 | break; |
| 642 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 643 | default: |
| 644 | *data_len=0; |
| 645 | rc = IPMI_CC_SENSOR_INVALID; |
| 646 | break; |
| 647 | } |
| 648 | |
| 649 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 650 | reply = sd_bus_message_unref(reply); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 651 | |
| 652 | return rc; |
| 653 | } |
| 654 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 655 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 656 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 657 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 658 | { |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 659 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 660 | |
| 661 | printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 662 | *data_len = 0; |
| 663 | |
| 664 | return rc; |
| 665 | } |
| 666 | |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 667 | ipmi_ret_t ipmi_sen_get_sdr_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 668 | ipmi_request_t request, |
| 669 | ipmi_response_t response, |
| 670 | ipmi_data_len_t data_len, |
| 671 | ipmi_context_t context) |
| 672 | { |
| 673 | auto resp = static_cast<get_sdr_info::GetSdrInfoResp*>(response); |
| 674 | if (request == nullptr || |
| 675 | get_sdr_info::request::get_count(request) == false) |
| 676 | { |
| 677 | // Get Sensor Count |
| 678 | resp->count = sensors.size(); |
| 679 | } |
| 680 | else |
| 681 | { |
| 682 | resp->count = 1; |
| 683 | } |
| 684 | |
| 685 | // Multiple LUNs not supported. |
| 686 | namespace response = get_sdr_info::response; |
| 687 | response::set_lun_present(0, &(resp->luns_and_dynamic_population)); |
| 688 | response::set_lun_not_present(1, &(resp->luns_and_dynamic_population)); |
| 689 | response::set_lun_not_present(2, &(resp->luns_and_dynamic_population)); |
| 690 | response::set_lun_not_present(3, &(resp->luns_and_dynamic_population)); |
| 691 | response::set_static_population(&(resp->luns_and_dynamic_population)); |
| 692 | |
| 693 | *data_len = SDR_INFO_RESP_SIZE; |
| 694 | |
| 695 | return IPMI_CC_OK; |
| 696 | } |
| 697 | |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 698 | ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 699 | ipmi_request_t request, |
| 700 | ipmi_response_t response, |
| 701 | ipmi_data_len_t data_len, |
| 702 | ipmi_context_t context) |
| 703 | { |
| 704 | // A constant reservation ID is okay until we implement add/remove SDR. |
| 705 | const uint16_t reservation_id = 1; |
| 706 | *(uint16_t*)response = reservation_id; |
| 707 | |
| 708 | printf("Created new IPMI SDR reservation ID %d\n", *(uint16_t*)response); |
| 709 | return IPMI_CC_OK; |
| 710 | } |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 711 | |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame^] | 712 | ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body, |
| 713 | const ipmi::sensor::Info *info, |
| 714 | ipmi_data_len_t data_len) |
| 715 | { |
| 716 | /* Functional sensor case */ |
| 717 | if (info->sensorInterfaces.begin()->first == |
| 718 | "xyz.openbmc_project.Sensor.Value") |
| 719 | { |
| 720 | // Get bus |
| 721 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 722 | dbus_interface_t iface; |
| 723 | |
| 724 | if (0 > find_openbmc_path(body->entity_id, &iface)) |
| 725 | return IPMI_CC_SENSOR_INVALID; |
| 726 | |
| 727 | body->sensor_units_1 = 0; // unsigned, no rate, no modifier, not a % |
| 728 | |
| 729 | /* Unit info */ |
| 730 | char *raw_cstr; |
| 731 | if (0 > sd_bus_get_property_string(bus, iface.bus, iface.path, |
| 732 | iface.interface, "Unit", NULL, |
| 733 | &raw_cstr)) { |
| 734 | fprintf(stderr, "Expected to find Unit interface in bus %s, path %s, but it was missing.\n", |
| 735 | iface.bus, iface.path); |
| 736 | return IPMI_CC_SENSOR_INVALID; |
| 737 | } |
| 738 | |
| 739 | std::string raw_str(raw_cstr); |
| 740 | namespace server = sdbusplus::xyz::openbmc_project::Sensor::server; |
| 741 | server::Value::Unit unit = |
| 742 | server::Value::convertUnitFromString(raw_str); |
| 743 | |
| 744 | // Unit strings defined in |
| 745 | // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml |
| 746 | switch (unit) |
| 747 | { |
| 748 | case server::Value::Unit::DegreesC: |
| 749 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C; |
| 750 | break; |
| 751 | case server::Value::Unit::RPMS: |
| 752 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions |
| 753 | get_sdr::body::set_rate_unit(0b100, body); // per minute |
| 754 | break; |
| 755 | case server::Value::Unit::Volts: |
| 756 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS; |
| 757 | break; |
| 758 | case server::Value::Unit::Meters: |
| 759 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS; |
| 760 | break; |
| 761 | case server::Value::Unit::Amperes: |
| 762 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES; |
| 763 | break; |
| 764 | case server::Value::Unit::Joules: |
| 765 | body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES; |
| 766 | break; |
| 767 | default: |
| 768 | fprintf(stderr, "Unknown value unit type: = %s\n", raw_cstr); |
| 769 | } |
| 770 | |
| 771 | free(raw_cstr); |
| 772 | |
| 773 | /* Modifiers to reading info */ |
| 774 | get_sdr::body::set_b(0, body); |
| 775 | get_sdr::body::set_m(1, body); |
| 776 | body->r_b_exponents = 0; |
| 777 | |
| 778 | /* ID string */ |
| 779 | std::string id_string = info->sensorPath.substr( |
| 780 | info->sensorPath.find_last_of('/')+1, info->sensorPath.length()); |
| 781 | get_sdr::body::set_id_type(0b00, body); // 00 = unicode |
| 782 | if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH) |
| 783 | { |
| 784 | get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH, body); |
| 785 | } |
| 786 | else |
| 787 | { |
| 788 | get_sdr::body::set_id_strlen(id_string.length(), body); |
| 789 | } |
| 790 | strncpy(body->id_string, id_string.c_str(), |
| 791 | get_sdr::body::get_id_strlen(body)); |
| 792 | } |
| 793 | |
| 794 | return IPMI_CC_OK; |
| 795 | }; |
| 796 | |
| 797 | ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 798 | ipmi_request_t request, ipmi_response_t response, |
| 799 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 800 | { |
| 801 | ipmi_ret_t ret = IPMI_CC_OK; |
| 802 | get_sdr::GetSdrReq *req = (get_sdr::GetSdrReq*)request; |
| 803 | get_sdr::GetSdrResp *resp = (get_sdr::GetSdrResp*)response; |
| 804 | get_sdr::SensorDataFullRecord record = {0}; |
| 805 | if (req != NULL) |
| 806 | { |
| 807 | // Note: we use an iterator so we can provide the next ID at the end of |
| 808 | // the call. |
| 809 | auto sensor = sensors.begin(); |
| 810 | |
| 811 | // At the beginning of a scan, the host side will send us id=0. |
| 812 | if (get_sdr::request::get_record_id(req) != 0) |
| 813 | { |
| 814 | sensor = sensors.find(get_sdr::request::get_record_id(req)); |
| 815 | if(sensor == sensors.end()) { |
| 816 | return IPMI_CC_SENSOR_INVALID; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | uint8_t sensor_id = sensor->first; |
| 821 | |
| 822 | /* Header */ |
| 823 | get_sdr::header::set_record_id(sensor_id, &(record.header)); |
| 824 | record.header.sdr_version = 0x51; // Based on IPMI Spec v2.0 rev 1.1 |
| 825 | record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD; |
| 826 | record.header.record_length = sizeof(get_sdr::SensorDataFullRecord); |
| 827 | |
| 828 | /* Key */ |
| 829 | record.key.sensor_number = sensor_id; |
| 830 | |
| 831 | /* Body */ |
| 832 | record.body.entity_id = sensor_id; |
| 833 | record.body.sensor_type = sensor->second.sensorType; |
| 834 | record.body.event_reading_type = sensor->second.sensorReadingType; |
| 835 | |
| 836 | // Set the type-specific details given the DBus interface |
| 837 | ret = populate_record_from_dbus(&(record.body), &(sensor->second), |
| 838 | data_len); |
| 839 | |
| 840 | if (++sensor == sensors.end()) |
| 841 | { |
| 842 | get_sdr::response::set_next_record_id(0xFFFF, resp); // last record |
| 843 | } |
| 844 | else |
| 845 | { |
| 846 | get_sdr::response::set_next_record_id(sensor->first, resp); |
| 847 | } |
| 848 | |
| 849 | *data_len = sizeof(get_sdr::GetSdrResp) - req->offset; |
| 850 | memcpy(resp->record_data, (char*)&record + req->offset, |
| 851 | sizeof(get_sdr::SensorDataFullRecord) - req->offset); |
| 852 | } |
| 853 | |
| 854 | return ret; |
| 855 | } |
| 856 | |
| 857 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 858 | void register_netfn_sen_functions() |
| 859 | { |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 860 | // <Wildcard Command> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 861 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 862 | NETFUN_SENSOR, IPMI_CMD_WILDCARD); |
| 863 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, |
| 864 | nullptr, ipmi_sen_wildcard, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 865 | PRIVILEGE_USER); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 866 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 867 | // <Get Sensor Type> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 868 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 869 | NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE); |
| 870 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, |
| 871 | nullptr, ipmi_sen_get_sensor_type, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 872 | PRIVILEGE_USER); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 873 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 874 | // <Set Sensor Reading and Event Status> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 875 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 876 | NETFUN_SENSOR, IPMI_CMD_SET_SENSOR); |
| 877 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, |
| 878 | nullptr, ipmi_sen_set_sensor, |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 879 | PRIVILEGE_OPERATOR); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 880 | |
Tom | 0573237 | 2016-09-06 17:21:23 +0530 | [diff] [blame] | 881 | // <Get Sensor Reading> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 882 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 883 | NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING); |
| 884 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, |
| 885 | nullptr, ipmi_sen_get_sensor_reading, |
| 886 | PRIVILEGE_USER); |
| 887 | |
| 888 | // <Reserve SDR> |
| 889 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n", |
| 890 | NETFUN_SENSOR, IPMI_CMD_RESERVE_SDR_REPO); |
| 891 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_RESERVE_SDR_REPO, |
| 892 | nullptr, ipmi_sen_reserve_sdr, |
| 893 | PRIVILEGE_USER); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 894 | |
Emily Shaffer | d06e0e7 | 2017-04-05 09:08:57 -0700 | [diff] [blame] | 895 | // <Get SDR Info> |
Emily Shaffer | a344afc | 2017-04-13 15:09:39 -0700 | [diff] [blame] | 896 | printf("Registering NetFn:[0x%X], Cmd:[0x%x]\n", |
| 897 | NETFUN_SENSOR, IPMI_CMD_GET_SDR_INFO); |
| 898 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SDR_INFO, |
| 899 | nullptr, ipmi_sen_get_sdr_info, |
| 900 | PRIVILEGE_USER); |
Emily Shaffer | bbef71c | 2017-05-08 16:36:17 -0700 | [diff] [blame^] | 901 | |
| 902 | // <Get SDR> |
| 903 | printf("Registering NetFn:[0x%X], Cmd:[0x%x]\n", |
| 904 | NETFUN_SENSOR, IPMI_CMD_GET_SDR); |
| 905 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SDR, |
| 906 | nullptr, ipmi_sen_get_sdr, |
| 907 | PRIVILEGE_USER); |
| 908 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 909 | return; |
| 910 | } |