blob: 9355fe334d54dec01eb144b2404fdcabff876bbe [file] [log] [blame]
Tomd700e762016-09-20 18:24:13 +05301#include <mapper.h>
Chris Austenac4604a2015-10-13 12:43:27 -05002#include <stdio.h>
3#include <string.h>
Tom Josephbe703f72017-03-09 12:34:35 +05304#include <bitset>
Chris Austen10ccc0f2015-12-10 18:27:04 -06005#include <systemd/sd-bus.h>
Tom Josephbe703f72017-03-09 12:34:35 +05306#include "host-ipmid/ipmid-api.h"
7#include <phosphor-logging/log.hpp>
Tomd700e762016-09-20 18:24:13 +05308#include "ipmid.hpp"
Tom Josephbe703f72017-03-09 12:34:35 +05309#include "sensorhandler.h"
10#include "types.hpp"
11#include "utils.hpp"
Chris Austenac4604a2015-10-13 12:43:27 -050012
Chris Austen8a45e7c2015-10-15 00:31:46 -050013extern int updateSensorRecordFromSSRAESC(const void *);
Tomd700e762016-09-20 18:24:13 +053014extern sd_bus *bus;
Tom Josephbe703f72017-03-09 12:34:35 +053015extern const ipmi::sensor::IdInfoMap sensors;
16using namespace phosphor::logging;
Chris Austenac4604a2015-10-13 12:43:27 -050017
18void register_netfn_sen_functions() __attribute__((constructor));
19
Chris Austen0012e9b2015-10-22 01:37:46 -050020struct sensorTypemap_t {
21 uint8_t number;
Chris Austend7cf0e42015-11-07 14:27:12 -060022 uint8_t typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -050023 char dbusname[32];
24} ;
25
26
27sensorTypemap_t g_SensorTypeMap[] = {
28
Chris Austend7cf0e42015-11-07 14:27:12 -060029 {0x01, 0x6F, "Temp"},
30 {0x0C, 0x6F, "DIMM"},
31 {0x0C, 0x6F, "MEMORY_BUFFER"},
32 {0x07, 0x6F, "PROC"},
33 {0x07, 0x6F, "CORE"},
34 {0x07, 0x6F, "CPU"},
35 {0x0F, 0x6F, "BootProgress"},
36 {0xe9, 0x09, "OccStatus"}, // E9 is an internal mapping to handle sensor type code os 0x09
37 {0xC3, 0x6F, "BootCount"},
38 {0x1F, 0x6F, "OperatingSystemStatus"},
Chris Austen800ba712015-12-03 15:31:00 -060039 {0x12, 0x6F, "SYSTEM_EVENT"},
40 {0xC7, 0x03, "SYSTEM"},
41 {0xC7, 0x03, "MAIN_PLANAR"},
Chris Austen10ccc0f2015-12-10 18:27:04 -060042 {0xC2, 0x6F, "PowerCap"},
Dhruvaraj S07248292017-03-21 02:14:52 -050043 {0xD8, 0x03, "PowerSupplyRedundancy"},
Jayanth Othayoth0661beb2017-03-22 06:00:58 -050044 {0xDA, 0x03, "TurboAllowed"},
Jayanth Othayothd5b2ac02017-03-27 08:19:18 -050045 {0xB4, 0x6F, "PowerSupplyDerating"},
Chris Austend7cf0e42015-11-07 14:27:12 -060046 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050047};
48
49
Chris Austenac4604a2015-10-13 12:43:27 -050050struct sensor_data_t {
51 uint8_t sennum;
52} __attribute__ ((packed)) ;
53
Chris Austen10ccc0f2015-12-10 18:27:04 -060054struct sensorreadingresp_t {
55 uint8_t value;
56 uint8_t operation;
57 uint8_t indication[2];
58} __attribute__ ((packed)) ;
Chris Austenac4604a2015-10-13 12:43:27 -050059
Tomd700e762016-09-20 18:24:13 +053060// Use a lookup table to find the interface name of a specific sensor
61// This will be used until an alternative is found. this is the first
62// step for mapping IPMI
63int find_interface_property_fru_type(dbus_interface_t *interface, const char *property_name, char *property_value) {
64
65 char *str1;
66 sd_bus_error error = SD_BUS_ERROR_NULL;
67 sd_bus_message *reply = NULL, *m=NULL;
68
69
70 int r;
71
72 r = sd_bus_message_new_method_call(bus,&m,interface->bus,interface->path,"org.freedesktop.DBus.Properties","Get");
73 if (r < 0) {
74 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
75 fprintf(stderr,"Bus: %s Path: %s Interface: %s \n",
76 interface->bus, interface->path, interface->interface);
77 goto final;
78 }
79
80 r = sd_bus_message_append(m, "ss", "org.openbmc.InventoryItem", property_name);
81 if (r < 0) {
82 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
83 fprintf(stderr,"Bus: %s Path: %s Interface: %s \n",
84 interface->bus, interface->path, interface->interface);
85 goto final;
86 }
87
88 r = sd_bus_call(bus, m, 0, &error, &reply);
89 if (r < 0) {
90 fprintf(stderr, "Failed to call the method: %s", strerror(-r));
91 goto final;
92 }
93
94 r = sd_bus_message_read(reply, "v", "s", &str1) ;
95 if (r < 0) {
96 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
97 goto final;
98 }
99
100 strcpy(property_value, str1);
101
102final:
103
104 sd_bus_error_free(&error);
105 m = sd_bus_message_unref(m);
106 reply = sd_bus_message_unref(reply);
107
108 return r;
109}
110
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700111int get_bus_for_path(const char *path, char **busname) {
112 return mapper_get_service(bus, path, busname);
113}
Tomd700e762016-09-20 18:24:13 +0530114
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700115int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) {
Tomd700e762016-09-20 18:24:13 +0530116 char *busname = NULL;
117 const char *iface = "org.openbmc.managers.System";
118 const char *objname = "/org/openbmc/managers/System";
119 char *str1 = NULL, *str2, *str3;
120 sd_bus_error error = SD_BUS_ERROR_NULL;
121 sd_bus_message *reply = NULL;
122
123
124 int r;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700125 r = get_bus_for_path(objname, &busname);
Tomd700e762016-09-20 18:24:13 +0530126 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400127 fprintf(stderr, "Failed to get %s busname: %s\n",
128 objname, strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530129 goto final;
130 }
131
132 r = sd_bus_call_method(bus,busname,objname,iface, "getObjectFromByteId",
133 &error, &reply, "sy", type, num);
134 if (r < 0) {
135 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
136 goto final;
137 }
138
139 r = sd_bus_message_read(reply, "(ss)", &str2, &str3);
140 if (r < 0) {
141 fprintf(stderr, "Failed to get a response: %s", strerror(-r));
142 goto final;
143 }
144
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700145 r = get_bus_for_path(str2, &str1);
Tomd700e762016-09-20 18:24:13 +0530146 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400147 fprintf(stderr, "Failed to get %s busname: %s\n",
148 str2, strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530149 goto final;
150 }
151
152 strncpy(interface->bus, str1, MAX_DBUS_PATH);
153 strncpy(interface->path, str2, MAX_DBUS_PATH);
154 strncpy(interface->interface, str3, MAX_DBUS_PATH);
155
156 interface->sensornumber = num;
157
158final:
159
160 sd_bus_error_free(&error);
161 reply = sd_bus_message_unref(reply);
162 free(busname);
163 free(str1);
164
165 return r;
166}
167
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700168// Use a lookup table to find the interface name of a specific sensor
169// This will be used until an alternative is found. this is the first
170// step for mapping IPMI
171int find_openbmc_path(uint8_t num, dbus_interface_t *interface) {
172 int rc;
173
174 // When the sensor map does not contain the sensor requested,
175 // fall back to the legacy DBus lookup (deprecated)
176 const auto& sensor_it = sensors.find(num);
177 if (sensor_it == sensors.end())
178 {
179 return legacy_dbus_openbmc_path("SENSOR", num, interface);
180 }
181
182 const auto& info = sensor_it->second;
183
184 char* busname;
185 rc = get_bus_for_path(info.sensorPath.c_str(), &busname);
186 if (rc < 0) {
187 fprintf(stderr, "Failed to get %s busname: %s\n",
188 info.sensorPath.c_str(),
189 busname);
190 goto final;
191 }
192
193 interface->sensortype = info.sensorType;
194 strcpy(interface->bus, busname);
195 strcpy(interface->path, info.sensorPath.c_str());
196 // Take the interface name from the beginning of the DbusInterfaceMap. This
197 // works for the Value interface but may not suffice for more complex
198 // sensors.
199 // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103
200 strcpy(interface->interface, info.sensorInterfaces.begin()->first.c_str());
201 interface->sensornumber = num;
202
203final:
204 free(busname);
205 return rc;
206}
207
Tomd700e762016-09-20 18:24:13 +0530208
209/////////////////////////////////////////////////////////////////////
210//
211// Routines used by ipmi commands wanting to interact on the dbus
212//
213/////////////////////////////////////////////////////////////////////
214int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) {
215
216
217 dbus_interface_t a;
218 int r;
219 sd_bus_error error = SD_BUS_ERROR_NULL;
220 sd_bus_message *m=NULL;
221
222 fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n",
223 number, method, value);
224
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700225 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530226
227 if (r < 0) {
228 fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
229 return 0;
230 }
231
232 r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
233 if (r < 0) {
234 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
235 goto final;
236 }
237
238 r = sd_bus_message_append(m, "v", "s", value);
239 if (r < 0) {
240 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
241 goto final;
242 }
243
244
245 r = sd_bus_call(bus, m, 0, &error, NULL);
246 if (r < 0) {
247 fprintf(stderr, "Failed to call the method: %s", strerror(-r));
248 }
249
250final:
251 sd_bus_error_free(&error);
252 m = sd_bus_message_unref(m);
253
254 return 0;
255}
256int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) {
257
258
259 dbus_interface_t a;
260 int r;
261 sd_bus_error error = SD_BUS_ERROR_NULL;
262 sd_bus_message *m=NULL;
263
264 fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n",
265 number, method, value);
266
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700267 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530268
269 if (r < 0) {
270 fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
271 return 0;
272 }
273
274 r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
275 if (r < 0) {
276 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
277 goto final;
278 }
279
280 r = sd_bus_message_append(m, "v", "i", value);
281 if (r < 0) {
282 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
283 goto final;
284 }
285
286
287 r = sd_bus_call(bus, m, 0, &error, NULL);
288 if (r < 0) {
289 fprintf(stderr, "12 Failed to call the method: %s", strerror(-r));
290 }
291
292final:
293 sd_bus_error_free(&error);
294 m = sd_bus_message_unref(m);
295
296 return 0;
297}
298
Chris Austen0012e9b2015-10-22 01:37:46 -0500299uint8_t dbus_to_sensor_type(char *p) {
Chris Austenac4604a2015-10-13 12:43:27 -0500300
Chris Austen0012e9b2015-10-22 01:37:46 -0500301 sensorTypemap_t *s = g_SensorTypeMap;
302 char r=0;
Chris Austenac4604a2015-10-13 12:43:27 -0500303
Chris Austen0012e9b2015-10-22 01:37:46 -0500304 while (s->number != 0xFF) {
305 if (!strcmp(s->dbusname,p)) {
306 r = s->number;
307 break;
Chris Austenac4604a2015-10-13 12:43:27 -0500308 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500309 s++;
Chris Austenac4604a2015-10-13 12:43:27 -0500310 }
311
Chris Austend7cf0e42015-11-07 14:27:12 -0600312
Chris Austen0012e9b2015-10-22 01:37:46 -0500313 if (s->number == 0xFF)
314 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -0500315
Chris Austen0012e9b2015-10-22 01:37:46 -0500316 return r;
Chris Austenac4604a2015-10-13 12:43:27 -0500317}
318
Chris Austen0012e9b2015-10-22 01:37:46 -0500319
320uint8_t dbus_to_sensor_type_from_dbus(dbus_interface_t *a) {
321 char fru_type_name[64];
322 int r= 0;
323
324 r = find_interface_property_fru_type(a, "fru_type", fru_type_name);
325 if (r<0) {
326 fprintf(stderr, "Failed to get a fru type: %s", strerror(-r));
327 return -1;
328 } else {
329 return dbus_to_sensor_type(fru_type_name);
330 }
331}
332
Emily Shaffer391f3302017-04-03 10:27:08 -0700333uint8_t get_type_from_interface(dbus_interface_t dbus_if) {
Chris Austen0012e9b2015-10-22 01:37:46 -0500334
Chris Austen0012e9b2015-10-22 01:37:46 -0500335 char *p;
Brad Bishop56003452016-10-05 21:49:19 -0400336 uint8_t type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500337
Chris Austen0012e9b2015-10-22 01:37:46 -0500338 // This is where sensors that do not exist in dbus but do
339 // exist in the host code stop. This should indicate it
340 // is not a supported sensor
Emily Shaffer391f3302017-04-03 10:27:08 -0700341 if (dbus_if.interface[0] == 0) { return 0;}
Chris Austen0012e9b2015-10-22 01:37:46 -0500342
Emily Shaffer391f3302017-04-03 10:27:08 -0700343 if (strstr(dbus_if.interface, "InventoryItem")) {
Chris Austen0012e9b2015-10-22 01:37:46 -0500344 // InventoryItems are real frus. So need to get the
345 // fru_type property
Emily Shaffer391f3302017-04-03 10:27:08 -0700346 type = dbus_to_sensor_type_from_dbus(&dbus_if);
Chris Austen0012e9b2015-10-22 01:37:46 -0500347 } else {
348 // Non InventoryItems
Emily Shaffer391f3302017-04-03 10:27:08 -0700349 p = strrchr (dbus_if.path, '/');
Brad Bishop56003452016-10-05 21:49:19 -0400350 type = dbus_to_sensor_type(p+1);
Chris Austen0012e9b2015-10-22 01:37:46 -0500351 }
352
Brad Bishop56003452016-10-05 21:49:19 -0400353 return type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500354 }
355
Emily Shaffer391f3302017-04-03 10:27:08 -0700356// Replaces find_sensor
357uint8_t find_type_for_sensor_number(uint8_t num) {
358 int r;
359 dbus_interface_t dbus_if;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700360 r = find_openbmc_path(num, &dbus_if);
Emily Shaffer391f3302017-04-03 10:27:08 -0700361 if (r < 0) {
362 fprintf(stderr, "Could not find sensor %d\n", num);
363 return r;
364 }
365 return get_type_from_interface(dbus_if);
366}
367
Chris Austen10ccc0f2015-12-10 18:27:04 -0600368
369
370
371
Chris Austen0012e9b2015-10-22 01:37:46 -0500372ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
373 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500374 ipmi_data_len_t data_len, ipmi_context_t context)
375{
376 sensor_data_t *reqptr = (sensor_data_t*)request;
377 ipmi_ret_t rc = IPMI_CC_OK;
378
379 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
380
381 // TODO Not sure what the System-event-sensor is suppose to return
382 // need to ask Hostboot team
383 unsigned char buf[] = {0x00,0x6F};
384
Emily Shaffer391f3302017-04-03 10:27:08 -0700385 buf[0] = find_type_for_sensor_number(reqptr->sennum);
Chris Austen0012e9b2015-10-22 01:37:46 -0500386
387 // HACK UNTIL Dbus gets updated or we find a better way
388 if (buf[0] == 0) {
Chris Austen800ba712015-12-03 15:31:00 -0600389 rc = IPMI_CC_SENSOR_INVALID;
Chris Austen0012e9b2015-10-22 01:37:46 -0500390 }
391
Chris Austenac4604a2015-10-13 12:43:27 -0500392
393 *data_len = sizeof(buf);
394 memcpy(response, &buf, *data_len);
395
Chris Austenac4604a2015-10-13 12:43:27 -0500396 return rc;
397}
398
Tom Josephbe703f72017-03-09 12:34:35 +0530399ipmi_ret_t setSensorReading(void *request)
400{
401 auto cmdData = static_cast<SetSensorReadingReq *>(request);
Chris Austenac4604a2015-10-13 12:43:27 -0500402
Tom Josephbe703f72017-03-09 12:34:35 +0530403 auto assertionStates =
404 (static_cast<uint16_t>(cmdData->assertOffset8_14)) << 8 |
405 cmdData->assertOffset0_7;
406
407 auto deassertionStates =
408 (static_cast<uint16_t>(cmdData->deassertOffset8_14)) << 8 |
409 cmdData->deassertOffset0_7;
410
411 std::bitset<16> assertionSet(assertionStates);
412 std::bitset<16> deassertionSet(deassertionStates);
413
414 // Check if the Sensor Number is present
415 auto iter = sensors.find(cmdData->number);
416 if (iter == sensors.end())
417 {
418 return IPMI_CC_SENSOR_INVALID;
419 }
420
421 auto& interfaceList = iter->second.sensorInterfaces;
422 if (interfaceList.empty())
423 {
424 log<level::ERR>("Interface List empty for the sensor",
425 entry("Sensor Number = %d", cmdData->number));
426 return IPMI_CC_UNSPECIFIED_ERROR;
427 }
428
429 ipmi::sensor::ObjectMap objects;
430 ipmi::sensor::InterfaceMap interfaces;
431 for (const auto& interface : interfaceList)
432 {
433 for (const auto& property : interface.second)
434 {
435 ipmi::sensor::PropertyMap props;
436 bool valid = false;
437 for (const auto& value : property.second)
438 {
439 if (assertionSet.test(value.first))
440 {
441 props.emplace(property.first, value.second.assert);
442 valid = true;
443 }
444 else if (deassertionSet.test(value.first))
445 {
446 props.emplace(property.first, value.second.deassert);
447 valid = true;
448 }
449 }
450 if (valid)
451 {
452 interfaces.emplace(interface.first, std::move(props));
453 }
454 }
455 }
456 objects.emplace(iter->second.sensorPath, std::move(interfaces));
457
Patrick Williams4736b912017-04-18 11:50:57 -0500458 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Tom Josephbe703f72017-03-09 12:34:35 +0530459 using namespace std::string_literals;
460 static const auto intf = "xyz.openbmc_project.Inventory.Manager"s;
461 static const auto path = "/xyz/openbmc_project/inventory"s;
462 std::string service;
463
464 try
465 {
466 service = ipmi::getService(bus, intf, path);
467
468 // Update the inventory manager
469 auto pimMsg = bus.new_method_call(service.c_str(),
470 path.c_str(),
471 intf.c_str(),
472 "Notify");
473 pimMsg.append(std::move(objects));
474 auto inventoryMgrResponseMsg = bus.call(pimMsg);
475 if (inventoryMgrResponseMsg.is_method_error())
476 {
477 log<level::ERR>("Error in notify call");
478 return IPMI_CC_UNSPECIFIED_ERROR;
479 }
480 }
481 catch (const std::runtime_error& e)
482 {
483 log<level::ERR>(e.what());
484 return IPMI_CC_UNSPECIFIED_ERROR;
485 }
486
487 return IPMI_CC_OK;
488}
Chris Austenac4604a2015-10-13 12:43:27 -0500489
Chris Austen0012e9b2015-10-22 01:37:46 -0500490ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
491 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500492 ipmi_data_len_t data_len, ipmi_context_t context)
493{
Chris Austenac4604a2015-10-13 12:43:27 -0500494 sensor_data_t *reqptr = (sensor_data_t*)request;
Chris Austenac4604a2015-10-13 12:43:27 -0500495
Chris Austen0012e9b2015-10-22 01:37:46 -0500496 printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum);
Chris Austenac4604a2015-10-13 12:43:27 -0500497
Tom Josephbe703f72017-03-09 12:34:35 +0530498 /*
499 * This would support the Set Sensor Reading command for the presence
500 * and functional state of Processor, Core & DIMM. For the remaining
501 * sensors the existing support is invoked.
502 */
503 auto ipmiRC = setSensorReading(request);
504
505 if(ipmiRC == IPMI_CC_SENSOR_INVALID)
506 {
507 updateSensorRecordFromSSRAESC(reqptr);
508 ipmiRC = IPMI_CC_OK;
509 }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500510
Chris Austenac4604a2015-10-13 12:43:27 -0500511 *data_len=0;
Tom Josephbe703f72017-03-09 12:34:35 +0530512 return ipmiRC;
Chris Austenac4604a2015-10-13 12:43:27 -0500513}
514
Chris Austen10ccc0f2015-12-10 18:27:04 -0600515
516ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
517 ipmi_request_t request, ipmi_response_t response,
518 ipmi_data_len_t data_len, ipmi_context_t context)
519{
520 sensor_data_t *reqptr = (sensor_data_t*)request;
521 ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID;
522 uint8_t type;
523 sensorreadingresp_t *resp = (sensorreadingresp_t*) response;
524 int r;
525 dbus_interface_t a;
526 sd_bus *bus = ipmid_get_sd_bus_connection();
527 sd_bus_message *reply = NULL;
Adriana Kobylak93125982016-03-01 12:48:10 -0600528 int reading = 0;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600529
530
531 printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum);
532
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700533 r = find_openbmc_path(reqptr->sennum, &a);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600534
Nan Li36deb762016-05-12 10:23:41 +0800535 if (r < 0) {
536 fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
537 return IPMI_CC_SENSOR_INVALID;
538 }
539
Emily Shaffer391f3302017-04-03 10:27:08 -0700540 type = get_type_from_interface(a);
Brad Bishop56003452016-10-05 21:49:19 -0400541 if(type == 0) {
542 fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
543 return IPMI_CC_SENSOR_INVALID;
544 }
Chris Austen10ccc0f2015-12-10 18:27:04 -0600545
546 fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path, a.interface);
547
548 *data_len=0;
549
550 switch(type) {
551 case 0xC3:
552 case 0xC2:
Adriana Kobylak93125982016-03-01 12:48:10 -0600553 r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value", NULL, &reply, "i");
Chris Austen10ccc0f2015-12-10 18:27:04 -0600554 if (r < 0) {
555 fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r));
556 fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n",
557 a.bus, a.path, a.interface);
558 break;
559 }
560
Adriana Kobylak93125982016-03-01 12:48:10 -0600561 r = sd_bus_message_read(reply, "i", &reading);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600562 if (r < 0) {
Adriana Kobylak93125982016-03-01 12:48:10 -0600563 fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r));
Chris Austen10ccc0f2015-12-10 18:27:04 -0600564 break;
565 }
566
567 printf("Contents of a 0x%02x is 0x%02x\n", type, reading);
568
569 rc = IPMI_CC_OK;
570 *data_len=sizeof(sensorreadingresp_t);
571
Adriana Kobylak93125982016-03-01 12:48:10 -0600572 resp->value = (uint8_t)reading;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600573 resp->operation = 0;
574 resp->indication[0] = 0;
575 resp->indication[1] = 0;
576 break;
577
578 default:
579 *data_len=0;
580 rc = IPMI_CC_SENSOR_INVALID;
581 break;
582 }
583
584
vishwa1eaea4f2016-02-26 11:57:40 -0600585 reply = sd_bus_message_unref(reply);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600586
587 return rc;
588}
589
Chris Austen0012e9b2015-10-22 01:37:46 -0500590ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
591 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500592 ipmi_data_len_t data_len, ipmi_context_t context)
593{
Nan Li70aa8d92016-08-29 00:11:10 +0800594 ipmi_ret_t rc = IPMI_CC_INVALID;
Chris Austenac4604a2015-10-13 12:43:27 -0500595
596 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
597 *data_len = 0;
598
599 return rc;
600}
601
602
603void register_netfn_sen_functions()
604{
Tom05732372016-09-06 17:21:23 +0530605 // <Wildcard Command>
Chris Austenac4604a2015-10-13 12:43:27 -0500606 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_WILDCARD);
Tom05732372016-09-06 17:21:23 +0530607 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD, NULL, ipmi_sen_wildcard,
608 PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -0500609
Tom05732372016-09-06 17:21:23 +0530610 // <Get Sensor Type>
Chris Austenac4604a2015-10-13 12:43:27 -0500611 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
Tom05732372016-09-06 17:21:23 +0530612 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE, NULL, ipmi_sen_get_sensor_type,
613 PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -0500614
Tom05732372016-09-06 17:21:23 +0530615 // <Set Sensor Reading and Event Status>
Chris Austenac4604a2015-10-13 12:43:27 -0500616 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
Tom05732372016-09-06 17:21:23 +0530617 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR, NULL, ipmi_sen_set_sensor,
618 PRIVILEGE_OPERATOR);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500619
Tom05732372016-09-06 17:21:23 +0530620 // <Get Sensor Reading>
Chris Austen10ccc0f2015-12-10 18:27:04 -0600621 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING);
Tom05732372016-09-06 17:21:23 +0530622 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING, NULL,
623 ipmi_sen_get_sensor_reading, PRIVILEGE_USER);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600624
Chris Austenac4604a2015-10-13 12:43:27 -0500625 return;
626}