Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 1 | #include "sensorhandler.h" |
Patrick Williams | 37af733 | 2016-09-02 21:21:42 -0500 | [diff] [blame] | 2 | #include "host-ipmid/ipmid-api.h" |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 3 | #include <mapper.h> |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | #include <stdint.h> |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 7 | #include <systemd/sd-bus.h> |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 8 | #include "ipmid.hpp" |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 9 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 10 | extern int updateSensorRecordFromSSRAESC(const void *); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 11 | extern sd_bus *bus; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 12 | |
| 13 | void register_netfn_sen_functions() __attribute__((constructor)); |
| 14 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 15 | struct sensorTypemap_t { |
| 16 | uint8_t number; |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 17 | uint8_t typecode; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 18 | char dbusname[32]; |
| 19 | } ; |
| 20 | |
| 21 | |
| 22 | sensorTypemap_t g_SensorTypeMap[] = { |
| 23 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 24 | {0x01, 0x6F, "Temp"}, |
| 25 | {0x0C, 0x6F, "DIMM"}, |
| 26 | {0x0C, 0x6F, "MEMORY_BUFFER"}, |
| 27 | {0x07, 0x6F, "PROC"}, |
| 28 | {0x07, 0x6F, "CORE"}, |
| 29 | {0x07, 0x6F, "CPU"}, |
| 30 | {0x0F, 0x6F, "BootProgress"}, |
| 31 | {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09 |
| 32 | {0xC3, 0x6F, "BootCount"}, |
| 33 | {0x1F, 0x6F, "OperatingSystemStatus"}, |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 34 | {0x12, 0x6F, "SYSTEM_EVENT"}, |
| 35 | {0xC7, 0x03, "SYSTEM"}, |
| 36 | {0xC7, 0x03, "MAIN_PLANAR"}, |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 37 | {0xC2, 0x6F, "PowerCap"}, |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 38 | {0xFF, 0x00, ""}, |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 42 | struct sensor_data_t { |
| 43 | uint8_t sennum; |
| 44 | } __attribute__ ((packed)) ; |
| 45 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 46 | struct sensorreadingresp_t { |
| 47 | uint8_t value; |
| 48 | uint8_t operation; |
| 49 | uint8_t indication[2]; |
| 50 | } __attribute__ ((packed)) ; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 51 | |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 52 | |
| 53 | // Use a lookup table to find the interface name of a specific sensor |
| 54 | // This will be used until an alternative is found. this is the first |
| 55 | // step for mapping IPMI |
| 56 | int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) { |
| 57 | |
| 58 | char *str1; |
| 59 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 60 | sd_bus_message *reply = NULL, *m=NULL; |
| 61 | |
| 62 | |
| 63 | int r; |
| 64 | |
| 65 | r = sd_bus_message_new_method_call(bus,&m,interface->bus,interface->path,"org.freedesktop.DBus.Properties","Get"); |
| 66 | if (r < 0) { |
| 67 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 68 | fprintf(stderr,"Bus: %s Path: %s Interface: %s \n", |
| 69 | interface->bus, interface->path, interface->interface); |
| 70 | goto final; |
| 71 | } |
| 72 | |
| 73 | r = sd_bus_message_append(m, "ss", "org.openbmc.InventoryItem", property_name); |
| 74 | if (r < 0) { |
| 75 | fprintf(stderr, "Failed to create a input parameter: %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_call(bus, m, 0, &error, &reply); |
| 82 | if (r < 0) { |
| 83 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 84 | goto final; |
| 85 | } |
| 86 | |
| 87 | r = sd_bus_message_read(reply, "v", "s", &str1) ; |
| 88 | if (r < 0) { |
| 89 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 90 | goto final; |
| 91 | } |
| 92 | |
| 93 | strcpy(property_value, str1); |
| 94 | |
| 95 | final: |
| 96 | |
| 97 | sd_bus_error_free(&error); |
| 98 | m = sd_bus_message_unref(m); |
| 99 | reply = sd_bus_message_unref(reply); |
| 100 | |
| 101 | return r; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | // Use a lookup table to find the interface name of a specific sensor |
| 106 | // This will be used until an alternative is found. this is the first |
| 107 | // step for mapping IPMI |
| 108 | int find_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) { |
| 109 | char *busname = NULL; |
| 110 | const char *iface = "org.openbmc.managers.System"; |
| 111 | const char *objname = "/org/openbmc/managers/System"; |
| 112 | char *str1 = NULL, *str2, *str3; |
| 113 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 114 | sd_bus_message *reply = NULL; |
| 115 | |
| 116 | |
| 117 | int r; |
| 118 | r = mapper_get_service(bus, objname, &busname); |
| 119 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 120 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 121 | objname, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 122 | goto final; |
| 123 | } |
| 124 | |
| 125 | r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId", |
| 126 | &error, &reply, "sy", type, num); |
| 127 | if (r < 0) { |
| 128 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 129 | goto final; |
| 130 | } |
| 131 | |
| 132 | r = sd_bus_message_read(reply, "(ss)", &str2, &str3); |
| 133 | if (r < 0) { |
| 134 | fprintf(stderr, "Failed to get a response: %s", strerror(-r)); |
| 135 | goto final; |
| 136 | } |
| 137 | |
| 138 | r = mapper_get_service(bus, str2, &str1); |
| 139 | if (r < 0) { |
Brad Bishop | 819ddd4 | 2016-10-05 21:19:19 -0400 | [diff] [blame] | 140 | fprintf(stderr, "Failed to get %s busname: %s\n", |
| 141 | str2, strerror(-r)); |
Tom | d700e76 | 2016-09-20 18:24:13 +0530 | [diff] [blame] | 142 | goto final; |
| 143 | } |
| 144 | |
| 145 | strncpy(interface->bus, str1, MAX_DBUS_PATH); |
| 146 | strncpy(interface->path, str2, MAX_DBUS_PATH); |
| 147 | strncpy(interface->interface, str3, MAX_DBUS_PATH); |
| 148 | |
| 149 | interface->sensornumber = num; |
| 150 | |
| 151 | final: |
| 152 | |
| 153 | sd_bus_error_free(&error); |
| 154 | reply = sd_bus_message_unref(reply); |
| 155 | free(busname); |
| 156 | free(str1); |
| 157 | |
| 158 | return r; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | ///////////////////////////////////////////////////////////////////// |
| 163 | // |
| 164 | // Routines used by ipmi commands wanting to interact on the dbus |
| 165 | // |
| 166 | ///////////////////////////////////////////////////////////////////// |
| 167 | int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) { |
| 168 | |
| 169 | |
| 170 | dbus_interface_t a; |
| 171 | int r; |
| 172 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 173 | sd_bus_message *m=NULL; |
| 174 | |
| 175 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n", |
| 176 | number, method, value); |
| 177 | |
| 178 | r = find_openbmc_path("SENSOR", number, &a); |
| 179 | |
| 180 | if (r < 0) { |
| 181 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 186 | if (r < 0) { |
| 187 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 188 | goto final; |
| 189 | } |
| 190 | |
| 191 | r = sd_bus_message_append(m, "v", "s", value); |
| 192 | if (r < 0) { |
| 193 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 194 | goto final; |
| 195 | } |
| 196 | |
| 197 | |
| 198 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 199 | if (r < 0) { |
| 200 | fprintf(stderr, "Failed to call the method: %s", strerror(-r)); |
| 201 | } |
| 202 | |
| 203 | final: |
| 204 | sd_bus_error_free(&error); |
| 205 | m = sd_bus_message_unref(m); |
| 206 | |
| 207 | return 0; |
| 208 | } |
| 209 | int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) { |
| 210 | |
| 211 | |
| 212 | dbus_interface_t a; |
| 213 | int r; |
| 214 | sd_bus_error error = SD_BUS_ERROR_NULL; |
| 215 | sd_bus_message *m=NULL; |
| 216 | |
| 217 | fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n", |
| 218 | number, method, value); |
| 219 | |
| 220 | r = find_openbmc_path("SENSOR", number, &a); |
| 221 | |
| 222 | if (r < 0) { |
| 223 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", number); |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method); |
| 228 | if (r < 0) { |
| 229 | fprintf(stderr, "Failed to create a method call: %s", strerror(-r)); |
| 230 | goto final; |
| 231 | } |
| 232 | |
| 233 | r = sd_bus_message_append(m, "v", "i", value); |
| 234 | if (r < 0) { |
| 235 | fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r)); |
| 236 | goto final; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | r = sd_bus_call(bus, m, 0, &error, NULL); |
| 241 | if (r < 0) { |
| 242 | fprintf(stderr, "12 Failed to call the method: %s", strerror(-r)); |
| 243 | } |
| 244 | |
| 245 | final: |
| 246 | sd_bus_error_free(&error); |
| 247 | m = sd_bus_message_unref(m); |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 253 | uint8_t dbus_to_sensor_type(char *p) { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 254 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 255 | sensorTypemap_t *s = g_SensorTypeMap; |
| 256 | char r=0; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 257 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 258 | while (s->number != 0xFF) { |
| 259 | if (!strcmp(s->dbusname,p)) { |
| 260 | r = s->number; |
| 261 | break; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 262 | } |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 263 | s++; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 264 | } |
| 265 | |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 266 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 267 | if (s->number == 0xFF) |
| 268 | printf("Failed to find Sensor Type %s\n", p); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 269 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 270 | return r; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 271 | } |
| 272 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 273 | |
| 274 | uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) { |
| 275 | char fru_type_name[64]; |
| 276 | int r= 0; |
| 277 | |
| 278 | r = find_interface_property_fru_type(a, "fru_type", fru_type_name); |
| 279 | if (r<0) { |
| 280 | fprintf(stderr, "Failed to get a fru type: %s", strerror(-r)); |
| 281 | return -1; |
| 282 | } else { |
| 283 | return dbus_to_sensor_type(fru_type_name); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | |
| 288 | uint8_t find_sensor(uint8_t sensor_number) { |
| 289 | |
| 290 | dbus_interface_t a; |
| 291 | char *p; |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame^] | 292 | int r; |
| 293 | uint8_t type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 294 | |
| 295 | r = find_openbmc_path("SENSOR", sensor_number, &a); |
| 296 | |
| 297 | if (r < 0) { return 0; } |
| 298 | |
| 299 | // This is where sensors that do not exist in dbus but do |
| 300 | // exist in the host code stop. This should indicate it |
| 301 | // is not a supported sensor |
Chris Austen | d7cf0e4 | 2015-11-07 14:27:12 -0600 | [diff] [blame] | 302 | if (a.interface[0] == 0) { return 0;} |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 303 | |
| 304 | if (strstr(a.interface, "InventoryItem")) { |
| 305 | // InventoryItems are real frus. So need to get the |
| 306 | // fru_type property |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame^] | 307 | type = dbus_to_sensor_type_from_dbus(&a); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 308 | } else { |
| 309 | // Non InventoryItems |
| 310 | p = strrchr (a.path, '/'); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame^] | 311 | type = dbus_to_sensor_type(p+1); |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 312 | } |
| 313 | |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame^] | 314 | return type; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 317 | |
| 318 | |
| 319 | |
| 320 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 321 | ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 322 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 323 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 324 | { |
| 325 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 326 | ipmi_ret_t rc = IPMI_CC_OK; |
| 327 | |
| 328 | printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum); |
| 329 | |
| 330 | // TODO Not sure what the System-event-sensor is suppose to return |
| 331 | // need to ask Hostboot team |
| 332 | unsigned char buf[] = {0x00,0x6F}; |
| 333 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 334 | buf[0] = find_sensor(reqptr->sennum); |
| 335 | |
| 336 | // HACK UNTIL Dbus gets updated or we find a better way |
| 337 | if (buf[0] == 0) { |
Chris Austen | 800ba71 | 2015-12-03 15:31:00 -0600 | [diff] [blame] | 338 | rc = IPMI_CC_SENSOR_INVALID; |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 341 | |
| 342 | *data_len = sizeof(buf); |
| 343 | memcpy(response, &buf, *data_len); |
| 344 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 345 | return rc; |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 350 | ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 351 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 352 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 353 | { |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 354 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 355 | ipmi_ret_t rc = IPMI_CC_OK; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 356 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 357 | printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum); |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 358 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 359 | updateSensorRecordFromSSRAESC(reqptr); |
| 360 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 361 | *data_len=0; |
| 362 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 363 | return rc; |
| 364 | } |
| 365 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 366 | |
| 367 | ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 368 | ipmi_request_t request, ipmi_response_t response, |
| 369 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 370 | { |
| 371 | sensor_data_t *reqptr = (sensor_data_t*)request; |
| 372 | ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID; |
| 373 | uint8_t type; |
| 374 | sensorreadingresp_t *resp = (sensorreadingresp_t*) response; |
| 375 | int r; |
| 376 | dbus_interface_t a; |
| 377 | sd_bus *bus = ipmid_get_sd_bus_connection(); |
| 378 | sd_bus_message *reply = NULL; |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 379 | int reading = 0; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 380 | |
| 381 | |
| 382 | printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum); |
| 383 | |
| 384 | r = find_openbmc_path("SENSOR", reqptr->sennum, &a); |
| 385 | |
Nan Li | 36deb76 | 2016-05-12 10:23:41 +0800 | [diff] [blame] | 386 | if (r < 0) { |
| 387 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 388 | return IPMI_CC_SENSOR_INVALID; |
| 389 | } |
| 390 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 391 | type = find_sensor(reqptr->sennum); |
Brad Bishop | 5600345 | 2016-10-05 21:49:19 -0400 | [diff] [blame^] | 392 | if(type == 0) { |
| 393 | fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum); |
| 394 | return IPMI_CC_SENSOR_INVALID; |
| 395 | } |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 396 | |
| 397 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface); |
| 398 | |
| 399 | *data_len=0; |
| 400 | |
| 401 | switch(type) { |
| 402 | case 0xC3: |
| 403 | case 0xC2: |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 404 | 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] | 405 | if (r < 0) { |
| 406 | fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r)); |
| 407 | fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", |
| 408 | a.bus, a.path, a.interface); |
| 409 | break; |
| 410 | } |
| 411 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 412 | r = sd_bus_message_read(reply, "i", &reading); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 413 | if (r < 0) { |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 414 | fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r)); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | |
| 418 | printf("Contents of a 0x%02x is 0x%02x\n", type, reading); |
| 419 | |
| 420 | rc = IPMI_CC_OK; |
| 421 | *data_len=sizeof(sensorreadingresp_t); |
| 422 | |
Adriana Kobylak | 9312598 | 2016-03-01 12:48:10 -0600 | [diff] [blame] | 423 | resp->value = (uint8_t)reading; |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 424 | resp->operation = 0; |
| 425 | resp->indication[0] = 0; |
| 426 | resp->indication[1] = 0; |
| 427 | break; |
| 428 | |
| 429 | default: |
| 430 | *data_len=0; |
| 431 | rc = IPMI_CC_SENSOR_INVALID; |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | |
vishwa | 1eaea4f | 2016-02-26 11:57:40 -0600 | [diff] [blame] | 436 | reply = sd_bus_message_unref(reply); |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 437 | |
| 438 | return rc; |
| 439 | } |
| 440 | |
Chris Austen | 0012e9b | 2015-10-22 01:37:46 -0500 | [diff] [blame] | 441 | ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, |
| 442 | ipmi_request_t request, ipmi_response_t response, |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 443 | ipmi_data_len_t data_len, ipmi_context_t context) |
| 444 | { |
Nan Li | 70aa8d9 | 2016-08-29 00:11:10 +0800 | [diff] [blame] | 445 | ipmi_ret_t rc = IPMI_CC_INVALID; |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 446 | |
| 447 | printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd); |
| 448 | *data_len = 0; |
| 449 | |
| 450 | return rc; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | void register_netfn_sen_functions() |
| 455 | { |
| 456 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD); |
| 457 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard); |
| 458 | |
| 459 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE); |
| 460 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type); |
| 461 | |
| 462 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR); |
| 463 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 464 | |
Chris Austen | 10ccc0f | 2015-12-10 18:27:04 -0600 | [diff] [blame] | 465 | printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING); |
| 466 | ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, NULL, ipmi_sen_get_sensor_reading); |
| 467 | |
Chris Austen | ac4604a | 2015-10-13 12:43:27 -0500 | [diff] [blame] | 468 | return; |
| 469 | } |