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