blob: f6ccc131d077345722513cf374794287a22a5942 [file] [log] [blame]
Tomd700e762016-09-20 18:24:13 +05301#include <mapper.h>
Emily Shaffer1fabf222017-04-05 08:53:21 -07002#include <math.h>
Chris Austenac4604a2015-10-13 12:43:27 -05003#include <stdio.h>
4#include <string.h>
Emily Shaffercc941e12017-06-14 13:06:26 -07005#include <set>
Tom Josephbe703f72017-03-09 12:34:35 +05306#include <bitset>
Emily Shafferbbef71c2017-05-08 16:36:17 -07007#include <xyz/openbmc_project/Sensor/Value/server.hpp>
Chris Austen10ccc0f2015-12-10 18:27:04 -06008#include <systemd/sd-bus.h>
Tom Josephbe703f72017-03-09 12:34:35 +05309#include "host-ipmid/ipmid-api.h"
10#include <phosphor-logging/log.hpp>
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050011#include <phosphor-logging/elog-errors.hpp>
Ratan Guptae0cc8552018-01-22 14:23:04 +053012#include "fruread.hpp"
Tomd700e762016-09-20 18:24:13 +053013#include "ipmid.hpp"
Tom Josephbe703f72017-03-09 12:34:35 +053014#include "sensorhandler.h"
15#include "types.hpp"
16#include "utils.hpp"
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050017#include "xyz/openbmc_project/Common/error.hpp"
18
Ratan Guptae0cc8552018-01-22 14:23:04 +053019static constexpr uint8_t fruInventoryDevice = 0x10;
20static constexpr uint8_t IPMIFruInventory = 0x02;
21static constexpr uint8_t BMCSlaveAddress = 0x20;
22
Chris Austen8a45e7c2015-10-15 00:31:46 -050023extern int updateSensorRecordFromSSRAESC(const void *);
Tomd700e762016-09-20 18:24:13 +053024extern sd_bus *bus;
Tom Josephbe703f72017-03-09 12:34:35 +053025extern const ipmi::sensor::IdInfoMap sensors;
Ratan Guptae0cc8552018-01-22 14:23:04 +053026extern const FruMap frus;
27
28
Tom Josephbe703f72017-03-09 12:34:35 +053029using namespace phosphor::logging;
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -050030using InternalFailure =
31 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
Chris Austenac4604a2015-10-13 12:43:27 -050032
33void register_netfn_sen_functions() __attribute__((constructor));
34
Chris Austen0012e9b2015-10-22 01:37:46 -050035struct sensorTypemap_t {
36 uint8_t number;
Chris Austend7cf0e42015-11-07 14:27:12 -060037 uint8_t typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -050038 char dbusname[32];
39} ;
40
Chris Austen0012e9b2015-10-22 01:37:46 -050041sensorTypemap_t g_SensorTypeMap[] = {
42
Chris Austend7cf0e42015-11-07 14:27:12 -060043 {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 Austen800ba712015-12-03 15:31:00 -060053 {0x12, 0x6F, "SYSTEM_EVENT"},
54 {0xC7, 0x03, "SYSTEM"},
55 {0xC7, 0x03, "MAIN_PLANAR"},
Chris Austen10ccc0f2015-12-10 18:27:04 -060056 {0xC2, 0x6F, "PowerCap"},
Tom Joseph558184e2017-09-01 13:45:05 +053057 {0x0b, 0xCA, "PowerSupplyRedundancy"},
Jayanth Othayoth0661beb2017-03-22 06:00:58 -050058 {0xDA, 0x03, "TurboAllowed"},
Tom Joseph558184e2017-09-01 13:45:05 +053059 {0xD8, 0xC8, "PowerSupplyDerating"},
Chris Austend7cf0e42015-11-07 14:27:12 -060060 {0xFF, 0x00, ""},
Chris Austen0012e9b2015-10-22 01:37:46 -050061};
62
63
Chris Austenac4604a2015-10-13 12:43:27 -050064struct sensor_data_t {
65 uint8_t sennum;
66} __attribute__ ((packed)) ;
67
Chris Austen10ccc0f2015-12-10 18:27:04 -060068struct sensorreadingresp_t {
69 uint8_t value;
70 uint8_t operation;
71 uint8_t indication[2];
72} __attribute__ ((packed)) ;
Chris Austenac4604a2015-10-13 12:43:27 -050073
Emily Shaffer2ae09b92017-04-05 15:09:41 -070074int get_bus_for_path(const char *path, char **busname) {
75 return mapper_get_service(bus, path, busname);
76}
Tomd700e762016-09-20 18:24:13 +053077
Emily Shaffer2ae09b92017-04-05 15:09:41 -070078int legacy_dbus_openbmc_path(const char *type, const uint8_t num, dbus_interface_t *interface) {
Tomd700e762016-09-20 18:24:13 +053079 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 Shaffer2ae09b92017-04-05 15:09:41 -070088 r = get_bus_for_path(objname, &busname);
Tomd700e762016-09-20 18:24:13 +053089 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -040090 fprintf(stderr, "Failed to get %s busname: %s\n",
91 objname, strerror(-r));
Tomd700e762016-09-20 18:24:13 +053092 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
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700108 r = get_bus_for_path(str2, &str1);
Tomd700e762016-09-20 18:24:13 +0530109 if (r < 0) {
Brad Bishop819ddd42016-10-05 21:19:19 -0400110 fprintf(stderr, "Failed to get %s busname: %s\n",
111 str2, strerror(-r));
Tomd700e762016-09-20 18:24:13 +0530112 goto final;
113 }
114
115 strncpy(interface->bus, str1, MAX_DBUS_PATH);
116 strncpy(interface->path, str2, MAX_DBUS_PATH);
117 strncpy(interface->interface, str3, MAX_DBUS_PATH);
118
119 interface->sensornumber = num;
Emily Shaffer71174412017-04-05 15:10:40 -0700120 // Make sure we know that the type hasn't been set, as newer codebase will
121 // set it automatically from the YAML at this step.
122 interface->sensortype = 0;
Tomd700e762016-09-20 18:24:13 +0530123
124final:
125
126 sd_bus_error_free(&error);
127 reply = sd_bus_message_unref(reply);
128 free(busname);
129 free(str1);
130
131 return r;
132}
133
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700134// Use a lookup table to find the interface name of a specific sensor
135// This will be used until an alternative is found. this is the first
136// step for mapping IPMI
137int find_openbmc_path(uint8_t num, dbus_interface_t *interface) {
138 int rc;
139
140 // When the sensor map does not contain the sensor requested,
141 // fall back to the legacy DBus lookup (deprecated)
142 const auto& sensor_it = sensors.find(num);
143 if (sensor_it == sensors.end())
144 {
145 return legacy_dbus_openbmc_path("SENSOR", num, interface);
146 }
147
148 const auto& info = sensor_it->second;
149
Patrick Williams8451edf2017-06-13 09:01:06 -0500150 char* busname = nullptr;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700151 rc = get_bus_for_path(info.sensorPath.c_str(), &busname);
152 if (rc < 0) {
153 fprintf(stderr, "Failed to get %s busname: %s\n",
154 info.sensorPath.c_str(),
155 busname);
156 goto final;
157 }
158
159 interface->sensortype = info.sensorType;
160 strcpy(interface->bus, busname);
161 strcpy(interface->path, info.sensorPath.c_str());
162 // Take the interface name from the beginning of the DbusInterfaceMap. This
163 // works for the Value interface but may not suffice for more complex
164 // sensors.
165 // tracked https://github.com/openbmc/phosphor-host-ipmid/issues/103
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500166 strcpy(interface->interface, info.propertyInterfaces.begin()->first.c_str());
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700167 interface->sensornumber = num;
168
169final:
170 free(busname);
171 return rc;
172}
173
Tomd700e762016-09-20 18:24:13 +0530174
175/////////////////////////////////////////////////////////////////////
176//
177// Routines used by ipmi commands wanting to interact on the dbus
178//
179/////////////////////////////////////////////////////////////////////
180int set_sensor_dbus_state_s(uint8_t number, const char *method, const char *value) {
181
182
183 dbus_interface_t a;
184 int r;
185 sd_bus_error error = SD_BUS_ERROR_NULL;
186 sd_bus_message *m=NULL;
187
188 fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of %s\n",
189 number, method, value);
190
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700191 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530192
193 if (r < 0) {
194 fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
195 return 0;
196 }
197
198 r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
199 if (r < 0) {
200 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
201 goto final;
202 }
203
204 r = sd_bus_message_append(m, "v", "s", value);
205 if (r < 0) {
206 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
207 goto final;
208 }
209
210
211 r = sd_bus_call(bus, m, 0, &error, NULL);
212 if (r < 0) {
213 fprintf(stderr, "Failed to call the method: %s", strerror(-r));
214 }
215
216final:
217 sd_bus_error_free(&error);
218 m = sd_bus_message_unref(m);
219
220 return 0;
221}
222int set_sensor_dbus_state_y(uint8_t number, const char *method, const uint8_t value) {
223
224
225 dbus_interface_t a;
226 int r;
227 sd_bus_error error = SD_BUS_ERROR_NULL;
228 sd_bus_message *m=NULL;
229
230 fprintf(ipmidbus, "Attempting to set a dbus Variant Sensor 0x%02x via %s with a value of 0x%02x\n",
231 number, method, value);
232
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700233 r = find_openbmc_path(number, &a);
Tomd700e762016-09-20 18:24:13 +0530234
235 if (r < 0) {
236 fprintf(stderr, "Failed to find Sensor 0x%02x\n", number);
237 return 0;
238 }
239
240 r = sd_bus_message_new_method_call(bus,&m,a.bus,a.path,a.interface,method);
241 if (r < 0) {
242 fprintf(stderr, "Failed to create a method call: %s", strerror(-r));
243 goto final;
244 }
245
246 r = sd_bus_message_append(m, "v", "i", value);
247 if (r < 0) {
248 fprintf(stderr, "Failed to create a input parameter: %s", strerror(-r));
249 goto final;
250 }
251
252
253 r = sd_bus_call(bus, m, 0, &error, NULL);
254 if (r < 0) {
255 fprintf(stderr, "12 Failed to call the method: %s", strerror(-r));
256 }
257
258final:
259 sd_bus_error_free(&error);
260 m = sd_bus_message_unref(m);
261
262 return 0;
263}
264
Chris Austen0012e9b2015-10-22 01:37:46 -0500265uint8_t dbus_to_sensor_type(char *p) {
Chris Austenac4604a2015-10-13 12:43:27 -0500266
Chris Austen0012e9b2015-10-22 01:37:46 -0500267 sensorTypemap_t *s = g_SensorTypeMap;
268 char r=0;
Chris Austen0012e9b2015-10-22 01:37:46 -0500269 while (s->number != 0xFF) {
270 if (!strcmp(s->dbusname,p)) {
Tom Joseph558184e2017-09-01 13:45:05 +0530271 r = s->typecode;
Chris Austen0012e9b2015-10-22 01:37:46 -0500272 break;
Chris Austenac4604a2015-10-13 12:43:27 -0500273 }
Chris Austen0012e9b2015-10-22 01:37:46 -0500274 s++;
Chris Austenac4604a2015-10-13 12:43:27 -0500275 }
276
Chris Austen0012e9b2015-10-22 01:37:46 -0500277 if (s->number == 0xFF)
278 printf("Failed to find Sensor Type %s\n", p);
Chris Austenac4604a2015-10-13 12:43:27 -0500279
Chris Austen0012e9b2015-10-22 01:37:46 -0500280 return r;
Chris Austenac4604a2015-10-13 12:43:27 -0500281}
282
Chris Austen0012e9b2015-10-22 01:37:46 -0500283
Emily Shaffer391f3302017-04-03 10:27:08 -0700284uint8_t get_type_from_interface(dbus_interface_t dbus_if) {
Chris Austen0012e9b2015-10-22 01:37:46 -0500285
Chris Austen0012e9b2015-10-22 01:37:46 -0500286 char *p;
Brad Bishop56003452016-10-05 21:49:19 -0400287 uint8_t type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500288
Chris Austen0012e9b2015-10-22 01:37:46 -0500289 // This is where sensors that do not exist in dbus but do
290 // exist in the host code stop. This should indicate it
291 // is not a supported sensor
Emily Shaffer391f3302017-04-03 10:27:08 -0700292 if (dbus_if.interface[0] == 0) { return 0;}
Chris Austen0012e9b2015-10-22 01:37:46 -0500293
Emily Shaffer71174412017-04-05 15:10:40 -0700294 // Fetch type from interface itself.
295 if (dbus_if.sensortype != 0)
296 {
297 type = dbus_if.sensortype;
Chris Austen0012e9b2015-10-22 01:37:46 -0500298 } else {
299 // Non InventoryItems
Emily Shaffer391f3302017-04-03 10:27:08 -0700300 p = strrchr (dbus_if.path, '/');
Brad Bishop56003452016-10-05 21:49:19 -0400301 type = dbus_to_sensor_type(p+1);
Chris Austen0012e9b2015-10-22 01:37:46 -0500302 }
303
Brad Bishop56003452016-10-05 21:49:19 -0400304 return type;
Chris Austen0012e9b2015-10-22 01:37:46 -0500305 }
306
Emily Shaffer391f3302017-04-03 10:27:08 -0700307// Replaces find_sensor
308uint8_t find_type_for_sensor_number(uint8_t num) {
309 int r;
310 dbus_interface_t dbus_if;
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700311 r = find_openbmc_path(num, &dbus_if);
Emily Shaffer391f3302017-04-03 10:27:08 -0700312 if (r < 0) {
313 fprintf(stderr, "Could not find sensor %d\n", num);
314 return r;
315 }
316 return get_type_from_interface(dbus_if);
317}
318
Chris Austen10ccc0f2015-12-10 18:27:04 -0600319
320
321
322
Chris Austen0012e9b2015-10-22 01:37:46 -0500323ipmi_ret_t ipmi_sen_get_sensor_type(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
324 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500325 ipmi_data_len_t data_len, ipmi_context_t context)
326{
327 sensor_data_t *reqptr = (sensor_data_t*)request;
328 ipmi_ret_t rc = IPMI_CC_OK;
329
330 printf("IPMI GET_SENSOR_TYPE [0x%02X]\n",reqptr->sennum);
331
332 // TODO Not sure what the System-event-sensor is suppose to return
333 // need to ask Hostboot team
334 unsigned char buf[] = {0x00,0x6F};
335
Emily Shaffer391f3302017-04-03 10:27:08 -0700336 buf[0] = find_type_for_sensor_number(reqptr->sennum);
Chris Austen0012e9b2015-10-22 01:37:46 -0500337
338 // HACK UNTIL Dbus gets updated or we find a better way
339 if (buf[0] == 0) {
Chris Austen800ba712015-12-03 15:31:00 -0600340 rc = IPMI_CC_SENSOR_INVALID;
Chris Austen0012e9b2015-10-22 01:37:46 -0500341 }
342
Chris Austenac4604a2015-10-13 12:43:27 -0500343
344 *data_len = sizeof(buf);
345 memcpy(response, &buf, *data_len);
346
Chris Austenac4604a2015-10-13 12:43:27 -0500347 return rc;
348}
349
Emily Shaffercc941e12017-06-14 13:06:26 -0700350const std::set<std::string> analogSensorInterfaces =
351{
352 "xyz.openbmc_project.Sensor.Value",
Patrick Venturee9a64052017-08-18 19:17:27 -0700353 "xyz.openbmc_project.Control.FanPwm",
Emily Shaffercc941e12017-06-14 13:06:26 -0700354};
355
356bool isAnalogSensor(const std::string& interface)
357{
358 return (analogSensorInterfaces.count(interface));
359}
360
Tom Josephbe703f72017-03-09 12:34:35 +0530361ipmi_ret_t setSensorReading(void *request)
362{
Tom Joseph816e92b2017-09-06 19:23:00 +0530363 ipmi::sensor::SetSensorReadingReq cmdData =
364 *(static_cast<ipmi::sensor::SetSensorReadingReq *>(request));
Tom Josephbe703f72017-03-09 12:34:35 +0530365
366 // Check if the Sensor Number is present
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500367 const auto iter = sensors.find(cmdData.number);
Tom Josephbe703f72017-03-09 12:34:35 +0530368 if (iter == sensors.end())
369 {
370 return IPMI_CC_SENSOR_INVALID;
371 }
372
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500373 try
374 {
375 return iter->second.updateFunc(cmdData, iter->second);
376 }
377 catch (InternalFailure& e)
378 {
379 log<level::ERR>("Set sensor failed",
380 entry("SENSOR_NUM=%d", cmdData.number));
381 commit<InternalFailure>();
382 }
Tom Joseph82024322017-09-28 20:07:29 +0530383 catch (const std::runtime_error& e)
384 {
385 log<level::ERR>(e.what());
386 }
Dhruvaraj Subhashchandran18e99992017-08-09 09:10:47 -0500387
388 return IPMI_CC_UNSPECIFIED_ERROR;
Tom Josephbe703f72017-03-09 12:34:35 +0530389}
Chris Austenac4604a2015-10-13 12:43:27 -0500390
Chris Austen0012e9b2015-10-22 01:37:46 -0500391ipmi_ret_t ipmi_sen_set_sensor(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
392 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500393 ipmi_data_len_t data_len, ipmi_context_t context)
394{
Chris Austenac4604a2015-10-13 12:43:27 -0500395 sensor_data_t *reqptr = (sensor_data_t*)request;
Chris Austenac4604a2015-10-13 12:43:27 -0500396
Chris Austen0012e9b2015-10-22 01:37:46 -0500397 printf("IPMI SET_SENSOR [0x%02x]\n",reqptr->sennum);
Chris Austenac4604a2015-10-13 12:43:27 -0500398
Tom Josephbe703f72017-03-09 12:34:35 +0530399 /*
400 * This would support the Set Sensor Reading command for the presence
401 * and functional state of Processor, Core & DIMM. For the remaining
402 * sensors the existing support is invoked.
403 */
404 auto ipmiRC = setSensorReading(request);
405
406 if(ipmiRC == IPMI_CC_SENSOR_INVALID)
407 {
408 updateSensorRecordFromSSRAESC(reqptr);
409 ipmiRC = IPMI_CC_OK;
410 }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500411
Chris Austenac4604a2015-10-13 12:43:27 -0500412 *data_len=0;
Tom Josephbe703f72017-03-09 12:34:35 +0530413 return ipmiRC;
Chris Austenac4604a2015-10-13 12:43:27 -0500414}
415
Chris Austen10ccc0f2015-12-10 18:27:04 -0600416
417ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
418 ipmi_request_t request, ipmi_response_t response,
419 ipmi_data_len_t data_len, ipmi_context_t context)
420{
421 sensor_data_t *reqptr = (sensor_data_t*)request;
422 ipmi_ret_t rc = IPMI_CC_SENSOR_INVALID;
Tom Joseph40c35b12017-09-07 02:04:42 +0530423 uint8_t type = 0;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600424 sensorreadingresp_t *resp = (sensorreadingresp_t*) response;
425 int r;
426 dbus_interface_t a;
427 sd_bus *bus = ipmid_get_sd_bus_connection();
428 sd_bus_message *reply = NULL;
Adriana Kobylak93125982016-03-01 12:48:10 -0600429 int reading = 0;
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600430 char* assertion = NULL;
Tom Josephc6162fb2018-01-25 01:55:20 +0530431 ipmi::sensor::GetSensorResponse getResponse {};
432 static constexpr auto scanningEnabledBit = 6;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600433
Chris Austen10ccc0f2015-12-10 18:27:04 -0600434 printf("IPMI GET_SENSOR_READING [0x%02x]\n",reqptr->sennum);
435
Emily Shaffer2ae09b92017-04-05 15:09:41 -0700436 r = find_openbmc_path(reqptr->sennum, &a);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600437
Tom Joseph40c35b12017-09-07 02:04:42 +0530438 if (r < 0)
439 {
Nan Li36deb762016-05-12 10:23:41 +0800440 fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
Nan Li36deb762016-05-12 10:23:41 +0800441 }
Tom Joseph40c35b12017-09-07 02:04:42 +0530442 else
443 {
444 type = get_type_from_interface(a);
445 if(type == 0) {
446 fprintf(stderr, "Failed to find Sensor 0x%02x\n", reqptr->sennum);
447 return IPMI_CC_SENSOR_INVALID;
448 }
Nan Li36deb762016-05-12 10:23:41 +0800449
Tom Joseph40c35b12017-09-07 02:04:42 +0530450 fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", a.bus, a.path,
451 a.interface);
Brad Bishop56003452016-10-05 21:49:19 -0400452 }
Chris Austen10ccc0f2015-12-10 18:27:04 -0600453
Chris Austen10ccc0f2015-12-10 18:27:04 -0600454 *data_len=0;
455
456 switch(type) {
Chris Austen10ccc0f2015-12-10 18:27:04 -0600457 case 0xC2:
Dhruvaraj Subhashchandrand12ae752017-10-04 00:33:27 -0500458 case 0xC8:
Adriana Kobylak93125982016-03-01 12:48:10 -0600459 r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value", NULL, &reply, "i");
Chris Austen10ccc0f2015-12-10 18:27:04 -0600460 if (r < 0) {
461 fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r));
462 fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n",
463 a.bus, a.path, a.interface);
464 break;
465 }
466
Adriana Kobylak93125982016-03-01 12:48:10 -0600467 r = sd_bus_message_read(reply, "i", &reading);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600468 if (r < 0) {
Adriana Kobylak93125982016-03-01 12:48:10 -0600469 fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r));
Chris Austen10ccc0f2015-12-10 18:27:04 -0600470 break;
471 }
472
473 printf("Contents of a 0x%02x is 0x%02x\n", type, reading);
474
475 rc = IPMI_CC_OK;
476 *data_len=sizeof(sensorreadingresp_t);
477
Adriana Kobylak93125982016-03-01 12:48:10 -0600478 resp->value = (uint8_t)reading;
Chris Austen10ccc0f2015-12-10 18:27:04 -0600479 resp->operation = 0;
480 resp->indication[0] = 0;
481 resp->indication[1] = 0;
482 break;
483
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600484 //TODO openbmc/openbmc#2154 Move this sensor to right place.
485 case 0xCA:
486 r = sd_bus_get_property(bus,a.bus, a.path, a.interface, "value", NULL, &reply, "s");
487 if (r < 0) {
488 fprintf(stderr, "Failed to call sd_bus_get_property:%d, %s\n", r, strerror(-r));
489 fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n",
490 a.bus, a.path, a.interface);
491 break;
492 }
493
494 r = sd_bus_message_read(reply, "s", &assertion);
495 if (r < 0) {
496 fprintf(stderr, "Failed to read sensor: %s\n", strerror(-r));
497 break;
498 }
499
500 rc = IPMI_CC_OK;
501 *data_len=sizeof(sensorreadingresp_t);
502
503 resp->value = 0;
504 resp->operation = 0;
505 if (strcmp(assertion,"Enabled") == 0)
506 {
507 resp->indication[0] = 0x02;
508 }
509 else
510 {
511 resp->indication[0] = 0x1;
512 }
513 resp->indication[1] = 0;
Dhruvaraj Subhashchandran6244f932017-11-23 01:08:46 -0600514 break;
515
Chris Austen10ccc0f2015-12-10 18:27:04 -0600516 default:
Tom Joseph14c15462017-09-07 02:16:51 +0530517 {
518 const auto iter = sensors.find(reqptr->sennum);
519 if (iter == sensors.end())
520 {
521 return IPMI_CC_SENSOR_INVALID;
522 }
Tom Joseph13b87a32018-02-16 09:37:43 +0530523 if (ipmi::sensor::Mutability::Read !=
524 (iter->second.mutability & ipmi::sensor::Mutability::Read))
525 {
526 return IPMI_CC_SENSOR_INVALID;
527 }
Tom Joseph14c15462017-09-07 02:16:51 +0530528
529 try
530 {
Tom Josephc6162fb2018-01-25 01:55:20 +0530531 getResponse = iter->second.getFunc(iter->second);
Tom Joseph14c15462017-09-07 02:16:51 +0530532 *data_len = getResponse.size();
533 memcpy(resp, getResponse.data(), *data_len);
Tom Josephc6162fb2018-01-25 01:55:20 +0530534 resp->operation = 1 << scanningEnabledBit;
Tom Joseph14c15462017-09-07 02:16:51 +0530535 return IPMI_CC_OK;
536 }
537 catch (InternalFailure& e)
538 {
Tom Josephc6162fb2018-01-25 01:55:20 +0530539 *data_len = getResponse.size();
540 memcpy(resp, getResponse.data(), *data_len);
541 return IPMI_CC_OK;
Tom Joseph14c15462017-09-07 02:16:51 +0530542 }
Tom Joseph82024322017-09-28 20:07:29 +0530543 catch (const std::runtime_error& e)
544 {
Tom Josephc6162fb2018-01-25 01:55:20 +0530545 *data_len = getResponse.size();
546 memcpy(resp, getResponse.data(), *data_len);
547 return IPMI_CC_OK;
Tom Joseph82024322017-09-28 20:07:29 +0530548 }
Tom Joseph14c15462017-09-07 02:16:51 +0530549 }
Chris Austen10ccc0f2015-12-10 18:27:04 -0600550 }
551
vishwa1eaea4f2016-02-26 11:57:40 -0600552 reply = sd_bus_message_unref(reply);
Chris Austen10ccc0f2015-12-10 18:27:04 -0600553
554 return rc;
555}
556
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530557void getSensorThresholds(uint8_t sensorNum,
558 get_sdr::GetSensorThresholdsResponse* response)
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600559{
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530560 constexpr auto warningThreshIntf =
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600561 "xyz.openbmc_project.Sensor.Threshold.Warning";
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530562 constexpr auto criticalThreshIntf =
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600563 "xyz.openbmc_project.Sensor.Threshold.Critical";
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600564
565 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
566
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530567 const auto iter = sensors.find(sensorNum);
568 const auto info = iter->second;
569
570 auto service = ipmi::getService(bus, info.sensorInterface, info.sensorPath);
571
572 auto warnThresholds = ipmi::getAllDbusProperties(bus,
573 service,
574 info.sensorPath,
575 warningThreshIntf);
576
577 double warnLow = warnThresholds["WarningLow"].get<int64_t>();
578 double warnHigh = warnThresholds["WarningHigh"].get<int64_t>();
579
580 if (warnLow != 0)
581 {
582 warnLow *= pow(10, info.scale - info.exponentR);
583 response->lowerNonCritical = static_cast<uint8_t>((
584 warnLow - info.scaledOffset) / info.coefficientM);
585 response->validMask |= static_cast<uint8_t>(
586 ipmi::sensor::ThresholdMask::NON_CRITICAL_LOW_MASK);
587 }
588
589 if (warnHigh != 0)
590 {
591 warnHigh *= pow(10, info.scale - info.exponentR);
592 response->upperNonCritical = static_cast<uint8_t>((
593 warnHigh - info.scaledOffset) / info.coefficientM);
594 response->validMask |= static_cast<uint8_t>(
595 ipmi::sensor::ThresholdMask::NON_CRITICAL_HIGH_MASK);
596 }
597
598 auto critThresholds = ipmi::getAllDbusProperties(bus,
599 service,
600 info.sensorPath,
601 criticalThreshIntf);
602 double critLow = critThresholds["CriticalLow"].get<int64_t>();
603 double critHigh = critThresholds["CriticalHigh"].get<int64_t>();
604
605 if (critLow != 0)
606 {
607 critLow *= pow(10, info.scale - info.exponentR);
608 response->lowerCritical = static_cast<uint8_t>((
609 critLow - info.scaledOffset) / info.coefficientM);
610 response->validMask |= static_cast<uint8_t>(
611 ipmi::sensor::ThresholdMask::CRITICAL_LOW_MASK);
612 }
613
614 if (critHigh != 0)
615 {
616 critHigh *= pow(10, info.scale - info.exponentR);
617 response->upperCritical = static_cast<uint8_t>((
618 critHigh - info.scaledOffset)/ info.coefficientM);
619 response->validMask |= static_cast<uint8_t>(
620 ipmi::sensor::ThresholdMask::CRITICAL_HIGH_MASK);
621 }
622}
623
624ipmi_ret_t ipmi_sen_get_sensor_thresholds(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
625 ipmi_request_t request, ipmi_response_t response,
626 ipmi_data_len_t data_len, ipmi_context_t context)
627{
628 constexpr auto valueInterface = "xyz.openbmc_project.Sensor.Value";
629
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600630 if (*data_len != sizeof(uint8_t))
631 {
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530632 *data_len = 0;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600633 return IPMI_CC_REQ_DATA_LEN_INVALID;
634 }
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600635
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530636 auto sensorNum = *(reinterpret_cast<const uint8_t *>(request));
637 *data_len = 0;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600638
639 const auto iter = sensors.find(sensorNum);
640 if (iter == sensors.end())
641 {
642 return IPMI_CC_SENSOR_INVALID;
643 }
644
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530645 const auto info = iter->second;
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600646
647 //Proceed only if the sensor value interface is implemented.
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530648 if (info.propertyInterfaces.find(valueInterface) ==
649 info.propertyInterfaces.end())
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600650 {
651 //return with valid mask as 0
652 return IPMI_CC_OK;
653 }
654
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530655 auto responseData =
656 reinterpret_cast<get_sdr::GetSensorThresholdsResponse*>(response);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600657
658 try
659 {
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530660 getSensorThresholds(sensorNum, responseData);
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600661 }
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530662 catch (std::exception& e)
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600663 {
Tom Joseph0ac0dd22018-02-16 09:14:45 +0530664 //Mask if the property is not present
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -0600665 responseData->validMask = 0;
666 }
667
668 *data_len = sizeof(get_sdr::GetSensorThresholdsResponse);
669 return IPMI_CC_OK;
670}
671
Chris Austen0012e9b2015-10-22 01:37:46 -0500672ipmi_ret_t ipmi_sen_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
673 ipmi_request_t request, ipmi_response_t response,
Chris Austenac4604a2015-10-13 12:43:27 -0500674 ipmi_data_len_t data_len, ipmi_context_t context)
675{
Nan Li70aa8d92016-08-29 00:11:10 +0800676 ipmi_ret_t rc = IPMI_CC_INVALID;
Chris Austenac4604a2015-10-13 12:43:27 -0500677
678 printf("IPMI S/E Wildcard Netfn:[0x%X], Cmd:[0x%X]\n",netfn,cmd);
679 *data_len = 0;
680
681 return rc;
682}
683
Emily Shafferd06e0e72017-04-05 09:08:57 -0700684ipmi_ret_t ipmi_sen_get_sdr_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
685 ipmi_request_t request,
686 ipmi_response_t response,
687 ipmi_data_len_t data_len,
688 ipmi_context_t context)
689{
690 auto resp = static_cast<get_sdr_info::GetSdrInfoResp*>(response);
691 if (request == nullptr ||
692 get_sdr_info::request::get_count(request) == false)
693 {
694 // Get Sensor Count
Ratan Guptae0cc8552018-01-22 14:23:04 +0530695 resp->count = sensors.size() + frus.size();
Emily Shafferd06e0e72017-04-05 09:08:57 -0700696 }
697 else
698 {
699 resp->count = 1;
700 }
701
702 // Multiple LUNs not supported.
703 namespace response = get_sdr_info::response;
704 response::set_lun_present(0, &(resp->luns_and_dynamic_population));
705 response::set_lun_not_present(1, &(resp->luns_and_dynamic_population));
706 response::set_lun_not_present(2, &(resp->luns_and_dynamic_population));
707 response::set_lun_not_present(3, &(resp->luns_and_dynamic_population));
708 response::set_static_population(&(resp->luns_and_dynamic_population));
709
710 *data_len = SDR_INFO_RESP_SIZE;
711
712 return IPMI_CC_OK;
713}
714
Emily Shaffera344afc2017-04-13 15:09:39 -0700715ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
716 ipmi_request_t request,
717 ipmi_response_t response,
718 ipmi_data_len_t data_len,
719 ipmi_context_t context)
720{
721 // A constant reservation ID is okay until we implement add/remove SDR.
722 const uint16_t reservation_id = 1;
723 *(uint16_t*)response = reservation_id;
Emily Shaffer5a5a6282017-08-15 11:17:17 -0700724 *data_len = sizeof(uint16_t);
Emily Shaffera344afc2017-04-13 15:09:39 -0700725
726 printf("Created new IPMI SDR reservation ID %d\n", *(uint16_t*)response);
727 return IPMI_CC_OK;
728}
Chris Austenac4604a2015-10-13 12:43:27 -0500729
Tom Josephdc212b22018-02-16 09:59:57 +0530730void setUnitFieldsForObject(const ipmi::sensor::Info *info,
Emily Shaffercc941e12017-06-14 13:06:26 -0700731 get_sdr::SensorDataFullRecordBody *body)
732{
Tom Josephdc212b22018-02-16 09:59:57 +0530733 namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
734 try
Emily Shaffercc941e12017-06-14 13:06:26 -0700735 {
Tom Josephdc212b22018-02-16 09:59:57 +0530736 auto unit = server::Value::convertUnitFromString(info->unit);
737 // Unit strings defined in
738 // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
739 switch (unit)
Emily Shaffercc941e12017-06-14 13:06:26 -0700740 {
Tom Josephdc212b22018-02-16 09:59:57 +0530741 case server::Value::Unit::DegreesC:
742 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
743 break;
744 case server::Value::Unit::RPMS:
745 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions
746 get_sdr::body::set_rate_unit(0b100, body); // per minute
747 break;
748 case server::Value::Unit::Volts:
749 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
750 break;
751 case server::Value::Unit::Meters:
752 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
753 break;
754 case server::Value::Unit::Amperes:
755 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
756 break;
757 case server::Value::Unit::Joules:
758 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
759 break;
760 case server::Value::Unit::Watts:
761 body->sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
762 break;
763 default:
764 // Cannot be hit.
765 fprintf(stderr, "Unknown value unit type: = %s\n",
766 info->unit.c_str());
Emily Shaffercc941e12017-06-14 13:06:26 -0700767 }
768 }
Tom Josephdc212b22018-02-16 09:59:57 +0530769 catch (sdbusplus::exception::InvalidEnumString e)
Emily Shaffercc941e12017-06-14 13:06:26 -0700770 {
Tom Josephdc212b22018-02-16 09:59:57 +0530771 log<level::WARNING>("Warning: no unit provided for sensor!");
Emily Shaffercc941e12017-06-14 13:06:26 -0700772 }
Emily Shaffercc941e12017-06-14 13:06:26 -0700773}
774
Emily Shafferbbef71c2017-05-08 16:36:17 -0700775ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body,
776 const ipmi::sensor::Info *info,
777 ipmi_data_len_t data_len)
778{
779 /* Functional sensor case */
Emily Shaffercc941e12017-06-14 13:06:26 -0700780 if (isAnalogSensor(info->propertyInterfaces.begin()->first))
Emily Shafferbbef71c2017-05-08 16:36:17 -0700781 {
Emily Shafferbbef71c2017-05-08 16:36:17 -0700782
783 body->sensor_units_1 = 0; // unsigned, no rate, no modifier, not a %
784
785 /* Unit info */
Tom Josephdc212b22018-02-16 09:59:57 +0530786 setUnitFieldsForObject(info, body);
Emily Shaffer10f49592017-05-10 12:01:10 -0700787
788 get_sdr::body::set_b(info->coefficientB, body);
789 get_sdr::body::set_m(info->coefficientM, body);
790 get_sdr::body::set_b_exp(info->exponentB, body);
Tom Josephdc212b22018-02-16 09:59:57 +0530791 get_sdr::body::set_r_exp(info->exponentR, body);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700792
Emily Shafferbbef71c2017-05-08 16:36:17 -0700793 get_sdr::body::set_id_type(0b00, body); // 00 = unicode
Emily Shafferbbef71c2017-05-08 16:36:17 -0700794 }
795
Tom Joseph96423912018-01-25 00:14:34 +0530796 /* ID string */
797 auto id_string = info->sensorNameFunc(*info);
798
799 if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
800 {
801 get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH, body);
802 }
803 else
804 {
805 get_sdr::body::set_id_strlen(id_string.length(), body);
806 }
807 strncpy(body->id_string, id_string.c_str(),
808 get_sdr::body::get_id_strlen(body));
809
Emily Shafferbbef71c2017-05-08 16:36:17 -0700810 return IPMI_CC_OK;
811};
812
Ratan Guptae0cc8552018-01-22 14:23:04 +0530813ipmi_ret_t ipmi_fru_get_sdr(ipmi_request_t request, ipmi_response_t response,
814 ipmi_data_len_t data_len)
815{
816 auto req = reinterpret_cast<get_sdr::GetSdrReq*>(request);
817 auto resp = reinterpret_cast<get_sdr::GetSdrResp*>(response);
818 get_sdr::SensorDataFruRecord record {};
819 auto dataLength = 0;
820
821 auto fru = frus.begin();
822 uint8_t fruID {};
823 auto recordID = get_sdr::request::get_record_id(req);
824
825 fruID = recordID - FRU_RECORD_ID_START;
826 fru = frus.find(fruID);
827 if (fru == frus.end())
828 {
829 return IPMI_CC_SENSOR_INVALID;
830 }
831
832 /* Header */
833 get_sdr::header::set_record_id(recordID, &(record.header));
834 record.header.sdr_version = SDR_VERSION; // Based on IPMI Spec v2.0 rev 1.1
835 record.header.record_type = get_sdr::SENSOR_DATA_FRU_RECORD;
836 record.header.record_length = sizeof(record.key) + sizeof(record.body);
837
838 /* Key */
839 record.key.fruID = fruID;
840 record.key.accessLun |= IPMI_LOGICAL_FRU;
841 record.key.deviceAddress = BMCSlaveAddress;
842
843 /* Body */
844 record.body.entityID = fru->second[0].entityID;
845 record.body.entityInstance = fru->second[0].entityInstance;
846 record.body.deviceType = fruInventoryDevice;
847 record.body.deviceTypeModifier = IPMIFruInventory;
848
849 /* Device ID string */
850 auto deviceID = fru->second[0].path.substr(
851 fru->second[0].path.find_last_of('/') + 1,
852 fru->second[0].path.length());
853
854
855 if (deviceID.length() > get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH)
856 {
857 get_sdr::body::set_device_id_strlen(
858 get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH,
859 &(record.body));
860 }
861 else
862 {
863 get_sdr::body::set_device_id_strlen(deviceID.length(),
864 &(record.body));
865 }
866
867 strncpy(record.body.deviceID, deviceID.c_str(),
868 get_sdr::body::get_device_id_strlen(&(record.body)));
869
870 if (++fru == frus.end())
871 {
872 get_sdr::response::set_next_record_id(END_OF_RECORD, resp); // last record
873 }
874 else
875 {
876 get_sdr::response::set_next_record_id(
877 (FRU_RECORD_ID_START + fru->first), resp);
878 }
879
880 if (req->bytes_to_read > (sizeof(*resp) - req->offset))
881 {
882 dataLength = (sizeof(*resp) - req->offset);
883 }
884 else
885 {
886 dataLength = req->bytes_to_read;
887 }
888
889 if (dataLength <= 0)
890 {
891 return IPMI_CC_REQ_DATA_LEN_INVALID;
892 }
893
894 memcpy(resp->record_data,
895 reinterpret_cast<uint8_t*>(&record) + req->offset,
896 (dataLength));
897
898 *data_len = dataLength;
899 *data_len += 2; // additional 2 bytes for next record ID
900
901 return IPMI_CC_OK;
902}
903
Emily Shafferbbef71c2017-05-08 16:36:17 -0700904ipmi_ret_t ipmi_sen_get_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
905 ipmi_request_t request, ipmi_response_t response,
906 ipmi_data_len_t data_len, ipmi_context_t context)
907{
908 ipmi_ret_t ret = IPMI_CC_OK;
909 get_sdr::GetSdrReq *req = (get_sdr::GetSdrReq*)request;
910 get_sdr::GetSdrResp *resp = (get_sdr::GetSdrResp*)response;
911 get_sdr::SensorDataFullRecord record = {0};
912 if (req != NULL)
913 {
914 // Note: we use an iterator so we can provide the next ID at the end of
915 // the call.
916 auto sensor = sensors.begin();
Ratan Guptae0cc8552018-01-22 14:23:04 +0530917 auto recordID = get_sdr::request::get_record_id(req);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700918
919 // At the beginning of a scan, the host side will send us id=0.
Ratan Guptae0cc8552018-01-22 14:23:04 +0530920 if (recordID != 0)
Emily Shafferbbef71c2017-05-08 16:36:17 -0700921 {
Ratan Guptae0cc8552018-01-22 14:23:04 +0530922 // recordID greater then 255,it means it is a FRU record.
923 // Currently we are supporting two record types either FULL record
924 // or FRU record.
925 if (recordID >= FRU_RECORD_ID_START)
926 {
927 return ipmi_fru_get_sdr(request, response, data_len);
928 }
929 else
930 {
931 sensor = sensors.find(recordID);
932 if (sensor == sensors.end())
933 {
934 return IPMI_CC_SENSOR_INVALID;
935 }
Emily Shafferbbef71c2017-05-08 16:36:17 -0700936 }
937 }
938
939 uint8_t sensor_id = sensor->first;
940
941 /* Header */
942 get_sdr::header::set_record_id(sensor_id, &(record.header));
943 record.header.sdr_version = 0x51; // Based on IPMI Spec v2.0 rev 1.1
944 record.header.record_type = get_sdr::SENSOR_DATA_FULL_RECORD;
945 record.header.record_length = sizeof(get_sdr::SensorDataFullRecord);
946
947 /* Key */
Tom Joseph96423912018-01-25 00:14:34 +0530948 get_sdr::key::set_owner_id_bmc(&(record.key));
Emily Shafferbbef71c2017-05-08 16:36:17 -0700949 record.key.sensor_number = sensor_id;
950
951 /* Body */
Tom Joseph96423912018-01-25 00:14:34 +0530952 record.body.entity_id = sensor->second.entityType;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700953 record.body.sensor_type = sensor->second.sensorType;
954 record.body.event_reading_type = sensor->second.sensorReadingType;
Tom Joseph96423912018-01-25 00:14:34 +0530955 record.body.entity_instance = sensor->second.instance;
Emily Shafferbbef71c2017-05-08 16:36:17 -0700956
957 // Set the type-specific details given the DBus interface
958 ret = populate_record_from_dbus(&(record.body), &(sensor->second),
959 data_len);
960
961 if (++sensor == sensors.end())
962 {
Ratan Guptae0cc8552018-01-22 14:23:04 +0530963 // we have reached till end of sensor, so assign the next record id
964 // to 256(Max Sensor ID = 255) + FRU ID(may start with 0).
965 auto next_record_id = (frus.size()) ?
966 frus.begin()->first + FRU_RECORD_ID_START :
967 END_OF_RECORD;
968
969 get_sdr::response::set_next_record_id(next_record_id, resp);
Emily Shafferbbef71c2017-05-08 16:36:17 -0700970 }
971 else
972 {
973 get_sdr::response::set_next_record_id(sensor->first, resp);
974 }
975
976 *data_len = sizeof(get_sdr::GetSdrResp) - req->offset;
977 memcpy(resp->record_data, (char*)&record + req->offset,
978 sizeof(get_sdr::SensorDataFullRecord) - req->offset);
979 }
980
981 return ret;
982}
983
984
Chris Austenac4604a2015-10-13 12:43:27 -0500985void register_netfn_sen_functions()
986{
Tom05732372016-09-06 17:21:23 +0530987 // <Wildcard Command>
Emily Shaffera344afc2017-04-13 15:09:39 -0700988 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
989 NETFUN_SENSOR, IPMI_CMD_WILDCARD);
990 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_WILDCARD,
991 nullptr, ipmi_sen_wildcard,
Tom05732372016-09-06 17:21:23 +0530992 PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -0500993
Tom05732372016-09-06 17:21:23 +0530994 // <Get Sensor Type>
Emily Shaffera344afc2017-04-13 15:09:39 -0700995 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
996 NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE);
997 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_TYPE,
998 nullptr, ipmi_sen_get_sensor_type,
Tom05732372016-09-06 17:21:23 +0530999 PRIVILEGE_USER);
Chris Austenac4604a2015-10-13 12:43:27 -05001000
Tom05732372016-09-06 17:21:23 +05301001 // <Set Sensor Reading and Event Status>
Emily Shaffera344afc2017-04-13 15:09:39 -07001002 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
1003 NETFUN_SENSOR, IPMI_CMD_SET_SENSOR);
1004 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_SET_SENSOR,
1005 nullptr, ipmi_sen_set_sensor,
Tom05732372016-09-06 17:21:23 +05301006 PRIVILEGE_OPERATOR);
Chris Austen8a45e7c2015-10-15 00:31:46 -05001007
Tom05732372016-09-06 17:21:23 +05301008 // <Get Sensor Reading>
Emily Shaffera344afc2017-04-13 15:09:39 -07001009 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",
1010 NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING);
1011 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_READING,
1012 nullptr, ipmi_sen_get_sensor_reading,
1013 PRIVILEGE_USER);
1014
Tom Joseph5ca50952018-02-22 00:33:38 +05301015 // <Reserve Device SDR Repository>
1016 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_RESERVE_DEVICE_SDR_REPO,
Emily Shaffera344afc2017-04-13 15:09:39 -07001017 nullptr, ipmi_sen_reserve_sdr,
1018 PRIVILEGE_USER);
Chris Austen10ccc0f2015-12-10 18:27:04 -06001019
Tom Joseph5ca50952018-02-22 00:33:38 +05301020 // <Get Device SDR Info>
1021 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR_INFO,
Emily Shaffera344afc2017-04-13 15:09:39 -07001022 nullptr, ipmi_sen_get_sdr_info,
1023 PRIVILEGE_USER);
Emily Shafferbbef71c2017-05-08 16:36:17 -07001024
Tom Joseph5ca50952018-02-22 00:33:38 +05301025 // <Get Device SDR>
1026 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR,
Emily Shafferbbef71c2017-05-08 16:36:17 -07001027 nullptr, ipmi_sen_get_sdr,
1028 PRIVILEGE_USER);
1029
Dhruvaraj Subhashchandran5c0beec2018-01-23 04:47:06 -06001030 // <Get Sensor Thresholds>
1031 ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_SENSOR_THRESHOLDS,
1032 nullptr, ipmi_sen_get_sensor_thresholds,
1033 PRIVILEGE_USER);
1034
Chris Austenac4604a2015-10-13 12:43:27 -05001035 return;
1036}